WolfieWeb Advanced Arduino

DIY Arduino Weather Station: DHT22 + OLED Wiring & Code

Build a beginner-friendly Arduino Uno temperature and humidity station using a DHT22 sensor and 0.96-inch SSD1306 I2C OLED. Follow the wiring diagram, upload the complete sketch, and troubleshoot your readings step by step. This is a local indoor climate monitor, not a full outdoor weather station.

What You Are Building

This DIY Arduino weather station measures local temperature and relative humidity. It does not measure wind speed, rainfall, or atmospheric pressure without additional sensors. This project teaches sensor wiring, I2C display wiring, library installation, serial debugging, and clean breadboard habits. Take your time with the wiring. Most failures come from one loose ground wire, the OLED using a different I2C address, or the DHT22 data pin being placed in the wrong row.

Parts Needed

PartPurposeParts shopping link
Arduino UnoMain controller that reads the sensor and drives the OLED display.Arduino Uno on Amazon
DHT22 / AM2302 SensorMeasures temperature and humidity with better accuracy than a DHT11.DHT22 sensor on Amazon
0.96 inch I2C OLED DisplayShows live readings without needing a laptop connected.SSD1306 OLED display
BreadboardMakes the sensor and display wiring clean and removable.Breadboard options
10k ResistorOptional pull-up resistor between DHT22 VCC and DATA if your sensor module does not include one.Resistor kit
Jumper WiresConnects the Arduino, breadboard, sensor, and display.Jumper wires

Detailed Wiring Guide

Wire the OLED first, then wire the DHT22. That keeps the build easier to test. After the OLED lights up, add the sensor and confirm the readings in the Serial Monitor.

Pin Mapping Table

Component PinArduino PinWire Color SuggestionNotes
OLED VCC5VRedSome SSD1306 breakout boards accept 5V, while others require 3.3V. Check the board specifications before connecting power.
OLED GNDGNDBlackDisplay ground must share Arduino ground.
OLED SDAA4BlueI2C data line on Arduino Uno.
OLED SCLA5YellowI2C clock line on Arduino Uno.
DHT22 VCC5VRedUse 5V for simple Uno builds.
DHT22 DATAD2GreenThe code uses digital pin 2.
DHT22 GNDGNDBlackDo not skip the ground wire.
10k resistorBetween VCC and DATAPurple/YellowOptional for many breakout modules, required for many bare sensors.

Arduino IDE Install Instructions

1. Install the required libraries

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries.
  3. Search for DHT sensor library by Adafruit and install it.
  4. Install Adafruit Unified Sensor if the IDE asks for it.
  5. Search for Adafruit SSD1306 and install it.
  6. Search for Adafruit GFX Library and install it.

2. Select the board and port

  1. Connect the Arduino Uno with a USB cable.
  2. Go to Tools > Board and select Arduino Uno.
  3. Go to Tools > Port and choose the COM port that appears when the Arduino is plugged in.
  4. Upload the code below.
  5. Open Tools > Serial Monitor and set the speed to 9600 baud.

Build Steps

  1. Place the Arduino Uno beside the breadboard so the wires do not stretch across the table.
  2. Connect the breadboard ground rail to Arduino GND.
  3. Connect the breadboard positive rail to Arduino 5V.
  4. Plug the OLED display into the breadboard or connect it directly with jumper wires.
  5. Wire OLED VCC to the voltage supported by your particular module, GND to GND, SDA to A4, and SCL to A5.
  6. Plug the DHT22 into the breadboard with the front grille facing you.
  7. Wire DHT22 VCC to 5V, DATA to Arduino D2, and GND to GND.
  8. If you are using a bare DHT22 sensor, place a 10k resistor between VCC and DATA.
  9. Upload the code and watch the OLED display. The first reading may take a couple seconds.
  10. Open the Serial Monitor at 9600 baud and confirm that temperature and humidity are printing repeatedly.

Good build habit: Test one section at a time. If the OLED does not work, fix that first before adding the DHT22. If the sensor does not work, verify the Serial Monitor before blaming the display.

Full Arduino Code

This sketch reads the DHT22, prints Celsius, Fahrenheit, and humidity to the Serial Monitor, then displays Fahrenheit and humidity on the OLED.

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define OLED_ADDRESS 0x3C

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  Serial.begin(9600);
  dht.begin();

  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS)) {
    Serial.println(F("OLED display not found. Check wiring or I2C address."));
    while (true);
  }

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("WolfieWeb Weather");
  display.println("Starting sensor...");
  display.display();
  delay(2000);
}

void loop() {
  float humidity = dht.readHumidity();
  float tempC = dht.readTemperature();
  float tempF = dht.readTemperature(true);

  if (isnan(humidity) || isnan(tempC) || isnan(tempF)) {
    Serial.println(F("Failed to read from DHT22. Check VCC, DATA, GND, and pull-up resistor."));
    display.clearDisplay();
    display.setTextSize(1);
    display.setCursor(0, 0);
    display.println("Sensor Error");
    display.println("Check DHT22 wiring");
    display.display();
    delay(2000);
    return;
  }

  Serial.print(F("Humidity: "));
  Serial.print(humidity);
  Serial.print(F("%  Temp: "));
  Serial.print(tempC);
  Serial.print(F("C / "));
  Serial.print(tempF);
  Serial.println(F("F"));

  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.println("WolfieWeb Weather");
  display.drawLine(0, 12, 127, 12, SSD1306_WHITE);

  display.setTextSize(2);
  display.setCursor(0, 20);
  display.print(tempF, 1);
  display.println(" F");

  display.setTextSize(2);
  display.setCursor(0, 44);
  display.print(humidity, 1);
  display.println(" %");

  display.display();
  delay(2000);
}

Serial Monitor Testing

Troubleshooting

OLED screen is blank

Check VCC, GND, SDA, and SCL. On Arduino Uno, SDA is A4 and SCL is A5. Some OLED modules use I2C address 0x3D instead of 0x3C. Change OLED_ADDRESS in the code if needed.

DHT22 reads NaN or failed

The sensor data pin may be in the wrong row, the sensor may need a pull-up resistor, or the pin order may not match your module. Confirm DATA goes to D2 and that the ground is shared.

Temperature looks wrong

Make sure you are reading Fahrenheit or Celsius intentionally. The code prints both to Serial Monitor but displays Fahrenheit on the OLED.

Readings update slowly

That is normal. DHT22 sensors are not meant to update extremely fast. A 2-second delay is safe and stable.

Upload fails

Select the correct board and port. Try a known-good USB data cable. Some cheap cables only charge and cannot upload sketches.

Display flickers

Keep wires short and seated firmly. Loose breadboard connections can make the display reset or flicker.

Related Build Videos

Use these popup videos as support: a full DHT22/OLED weather display build, an SSD1306 OLED display setup, and a DHT22 sensor wiring/coding walkthrough.

Arduino Weather Station FAQ

Can I build this with an Arduino Uno?

Yes. The wiring and sketch on this page use an Arduino Uno, with the DHT22 data line on D2 and the I2C OLED on A4 (SDA) and A5 (SCL).

Why is my SSD1306 OLED screen blank?

Check power compatibility, ground, SDA/SCL wiring, and the I2C address. The example uses 0x3C, but some modules use 0x3D.

Does the DHT22 measure outdoor weather?

The DHT22 measures temperature and relative humidity at its location. A complete outdoor station needs extra sensors and suitable weather protection.

Does this project need Wi-Fi?

No. The Arduino reads the sensor and updates the OLED locally. Wi-Fi or cloud logging would be a separate upgrade.

What You Learned

  • You wired a DHT22 sensor to an Arduino digital pin.
  • You connected an SSD1306 OLED display using I2C.
  • You installed Arduino libraries the right way.
  • You used the Serial Monitor as a real debugging tool.
  • You built a standalone display project that can run without your laptop after upload.

Keep Building with WolfieWeb

Ready to try another hands-on electronics project? These related tutorials include wiring and step-by-step instructions.

Arduino GPS Tracker →

Read NEO-6M GPS coordinates and log a route to MicroSD.

ESP32 Smart Home Hub →

Use sensors, MQTT messaging, and automation rules in a connected project.

Explore the Arduino Lab →

Browse more Arduino and electronics tutorials.

Share This Arduino Weather Station Build

Use the buttons below to share this tutorial or copy the link for later.

Ready for the next build?

Save this weather station tutorial, then head back to WolfieWeb or the Arduino tutorial hub for more projects.

🤖↑