Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Wemos D1 mini weather station

Creating a weather station using the Wemos D1 Mini is a great project. The Wemos
D1 Mini is based on the ESP8266 WiFi module, making it suitable for connecting your
weather station to the internet for remote monitoring. Here's a basic example using
the Wemos D1 Mini, DHT22 for temperature and humidity, and BMP180 for pressure
sensors:

Components needed:

Wemos D1 Mini board


DHT22 (or DHT11) temperature and humidity sensor
BMP180 (or BMP280) pressure sensor
Breadboard and jumper wires
Libraries required:

DHT sensor library (for DHT22 sensor)


Adafruit BMP085 Unified Library (for BMP180 sensor)
Adafruit Unified Sensor Library
Make sure you've installed these libraries via the Arduino Library Manager before
using the code.

Here's an example code for a weather station using the Wemos D1 Mini:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <DHT.h>
#include <ESP8266WiFi.h>

// Replace with your WiFi credentials


const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

#define DHT_PIN D2 // Define the pin for the DHT sensor (change as needed)
#define DHT_TYPE DHT22 // Use DHT22 sensor; change to DHT11 if using that

DHT dht(DHT_PIN, DHT_TYPE);


Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

void setup() {
Serial.begin(9600);
delay(1000);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {


delay(1000);
Serial.println("Connecting to WiFi...");
}

Serial.println("Connected to WiFi");
dht.begin();
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1);
}
}

void loop() {
sensors_event_t event;
bmp.getEvent(&event);

float temperature = dht.readTemperature();


float humidity = dht.readHumidity();
float pressure = event.pressure / 100.0F; // Convert pressure to hPa

Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");

Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");

delay(2000); // Delay for 2 seconds before taking another reading


}

his code is similar to the previous example, but it also connects to your WiFi network
using the ESP8266WiFi library, allowing you to upload data to an online service or
display it on a web page. Don't forget to replace "your_SSID" and "your_PASSWORD"
with your actual WiFi credentials.

You can enhance this project further by adding a web server to display weather data,
using a cloud service for data storage, or integrating other sensors like a rain gauge or
wind speed sensor for a more comprehensive weather station.

You might also like