Arduino Weather Station guide

Configurare noua (How To)

Situatie

The DHT11 and DHT22 measure temperature and humidity. DHT22 offers higher accuracy and a wider range.

Pin Description
VCC +5V
DATA Data output (connect to D2)
NC Not connected
GND Ground

BMP180 / BME280

Measures pressure and temperature using the I2C interface.

Pin Description
VIN +3.3V or +5V
GND Ground
SCL I2C Clock (A5)
SDA I2C Data (A4)

LCD (16×2 I2C)

Displays data using the I2C interface — only two wires are required (SDA, SCL).
The most common I2C addresses are 0x27 or 0x3F.

Wiring Diagram

Component Arduino Pin Notes
DHT11 Data D2 Use 10kΩ pull-up resistor (optional)
BMP180 SDA A4 I2C Data
BMP180 SCL A5 I2C Clock
LCD SDA A4 Shared with BMP180
LCD SCL A5 Shared with BMP180
Power (+) 5V Common power line
Ground (–) GND Common ground

On Arduino Mega, use SDA = 20 and SCL = 21 instead.

Arduino Code Example


#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

// Define sensors
#define DHTPIN 2
#define DHTTYPE DHT11   // or DHT22

DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP085 bmp;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change address if needed (0x3F or 0x27)

void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.backlight();
  dht.begin();

  if (!bmp.begin()) {
    Serial.println("BMP180 not found!");
    lcd.print("BMP Error!");
    while (1);
  }

  lcd.clear();
  lcd.print("Weather Station");
  delay(2000);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float p = bmp.readPressure() / 100.0; // hPa

  if (isnan(h) || isnan(t)) {
    Serial.println("DHT read error!");
    return;
  }

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print(t);
  lcd.print((char)223);
  lcd.print("C H:");
  lcd.print(h);
  lcd.print("%");

  lcd.setCursor(0, 1);
  lcd.print("P:");
  lcd.print(p);
  lcd.print(" hPa");

  Serial.print("Temp: "); Serial.print(t);
  Serial.print(" °C  Hum: "); Serial.print(h);
  Serial.print("%  Pressure: "); Serial.print(p);
  Serial.println(" hPa");

  delay(2000);
}

Explanation: This program reads data from the DHT and BMP sensors, then prints it to both the Serial Monitor and the LCD screen.

How It Works

  1. The sensors measure temperature, humidity, and pressure.
  2. Arduino reads and formats this data.
  3. The LCD displays readings in real time.
  4. Every few seconds, the data updates automatically.

Troubleshooting

Problem Possible Cause Solution
LCD shows random text Wrong I2C address Try 0x3F instead of 0x27
“BMP180 not found!” Wiring issue Check SDA/SCL and power
DHT readings show NaN Missing library or bad sensor Install DHT library, recheck wiring
LCD blank Contrast too low or backlight off Adjust contrast screw or enable backlight

Install these from Arduino IDE → Sketch → Include Library → Manage Libraries:

  • DHT sensor library by Adafruit
  • Adafruit Unified Sensor
  • Adafruit BMP085 Library or Adafruit BME280
  • LiquidCrystal_I2C

Optional: IoT Integration

Add an ESP8266 or ESP32 to send data to cloud platforms such as:

  • ThingSpeak
  • Blynk
  • Adafruit IO

Use libraries like ESP8266WiFi.h and HTTPClient.h to upload readings as HTTP requests.

Expansion Ideas

  • Add a rain sensor or anemometer (wind speed)
  • Store data on an SD card
  • Add a real-time clock (RTC) for timestamped data
  • Display graphs on a web dashboard.

Solutie

Tip solutie

Permanent

Voteaza

(7 din 9 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?