ElectroMartBDElectroMartBD

Mini Weather Station with DHT11 and OLED

Bangladesh weather changes fast — hot, humid, then rainy. This small project shows live temperature and humidity on a crisp 0.96" OLED screen, perfect for your desk or a school science fair.

What You Need:

1. Wiring

  • DHT11 VCC → 5V, GND → GND, DATA → D2
  • OLED VCC → 5V, GND → GND, SDA → A4, SCL → A5

2. The Code

Install DHT sensor library, Adafruit SSD1306 and Adafruit GFX from the Library Manager.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);
DHT dht(2, DHT11);   // change to DHT22 if you use one

void setup() {
  dht.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(SSD1306_WHITE);
}

void loop() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  display.clearDisplay();
  display.setTextSize(1); display.setCursor(0, 0);
  display.print("Weather Station");
  display.setTextSize(2); display.setCursor(0, 20);
  if (isnan(t) || isnan(h)) { display.print("Error"); }
  else {
    display.print(t, 1); display.print(" C");
    display.setCursor(0, 44); display.print(h, 0); display.print(" %");
  }
  display.display();
  delay(2000);
}

3. Tips

  • The DHT11 can only be read about once per second — keep the 2 second delay.
  • Keep the sensor away from the Arduino's voltage regulator, which gets warm and affects readings.

Need help? Stuck on wiring or code? Message us on WhatsApp at +880 1577-098376 and we will help you with your project.