Rohan Barnwal
Published © GPL3+

Tabletop Weather Station Using Arduino, DHT11 Sensor & OLED

Build a sleek Arduino-powered Tabletop Weather Station and turn your DIY into a pro-grade IoT device with JUSTWAY!

BeginnerFull instructions provided1 hour2
Tabletop Weather Station Using Arduino, DHT11 Sensor & OLED

Things used in this project

Hardware components

Adafruit Monochrome 1.3" 128x64 OLED graphic display
×1
UNO R4 WiFi
Arduino UNO R4 WiFi
×1
Gravity: DHT11 Temperature Humidity Sensor For Arduino
DFRobot Gravity: DHT11 Temperature Humidity Sensor For Arduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Connections

Code

Code

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

// ==== OLED SETTINGS ====
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// ==== DHT SETTINGS ====
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("Initializing DHT11 + SSD1306 OLED...");

  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
    Serial.println("❌ SSD1306 not found! Check wiring or I2C address.");
    while (1);
  }

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(20, 25);
  display.println("Initializing...");
  display.display();

  dht.begin();
  delay(2000);
}

void loop() {
  delay(2000);

  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("⚠️ Failed to read from DHT11 sensor!");
    display.clearDisplay();
    display.setTextSize(1);
    display.setCursor(25, 25);
    display.println("Sensor Error!");
    display.display();
    return;
  }

  int tempInt = (int)temperature;
  int humInt  = (int)humidity;

  Serial.print("Temperature: ");
  Serial.print(tempInt);
  Serial.print(" °C | Humidity: ");
  Serial.print(humInt);
  Serial.println(" %");

  display.clearDisplay();

  display.setTextSize(1);
  display.setCursor(35, 0);
  display.println("DHT11 DATA");

  display.setTextSize(1);
  display.setCursor(0, 20);
  display.print("Temp: ");
  display.print(tempInt);
  display.println(" C");

  display.setCursor(0, 40);
  display.print("Hum : ");
  display.print(humInt);
  display.println(" %");

  display.display();
}

Credits

Rohan Barnwal
39 projects • 35 followers
Rohan Barnwal - maker, hacker, tech enthusiast. I explore new tech & find innovative solutions. See my projects on hackster.io!

Comments