Utility Bar

Building an Arduino Temperature Monitor with DHT22 and 0.96" OLED Display

Arduino Temperature Monitor Using Arduino Nano & SSD1306 OLED Display Project

Ethan Zaitchik |

Table of Contents

    This project shows how to build a simple Arduino temperature and humidity monitor using a DHT22 sensor and a 0.96 inch SSD1306 OLED display.

    The Arduino reads temperature and humidity data from the DHT22 and displays the values in real time on the OLED screen. The same setup also works with a DHT11 sensor if you already have one. For pros and cons of these sensors, see the DHT11 vs DHT22 sensor guide. If you want to compare more options like BME280 and DS18B20 to find the best sensor for your next build, check the Arduino digital temperature sensor comparison guide.

    Parts List

    Software Requirements

    • Arduino IDE (installed or web version)
    • Adafruit SSD1306 library
    • Adafruit DHT sensor library

    Step 1: Install Libraries

    1. Open the Arduino IDE.
    2. Go to Sketch > Include Library > Manage Libraries.
    3. Search for Adafruit SSD1306 and install it.
    4. Search for DHT sensor library by Adafruit and install it.

    Step 2: Wiring

    Connect the DHT22 sensor and SSD1306 OLED display to the Arduino using the pinout table below. If you need a general reference for I2C, SPI, and UART pinouts on common development boards like Arduino, ESP32, and others, see the Arduino sensor protocols reference guide.

    Component Pin Arduino Connection
    DHT22 VCC 5V
    DHT22 GND GND
    DHT22 DATA D2
    SSD1306 OLED VCC 3.3V
    SSD1306 OLED GND GND
    SSD1306 OLED SCL A5 or SCL
    SSD1306 OLED SDA A4 or SDA

    Wiring Diagram

    Arduino temperature monitor with DHT22 and 0.96" SSD1306 OLED wiring diagram

    Step 3: Code

    Upload the following code to your Arduino to start monitoring the temperature and humidity:

    /*
     * Ethan Zaitchik
     * Temprature & Humidity Arduino Project using DHT22 Sensor and 0.96 OLED Display
     * Full guide: https://zaitronics.com.au/blogs/main/building-an-arduino-temperature-monitor-with-dht22-and-0-96-oled-display
     */
     
    #include <Arduino.h>
    #include <U8g2lib.h>
    #include "DHT.h"
    
    #define DHTPIN 2        // Digital pin connected to the DHT sensor
    #define DHTTYPE DHT22   // Using a DHT22 sensor
    DHT dht(DHTPIN, DHTTYPE);
    
    #ifdef U8X8_HAVE_HW_SPI
    #include <SPI.h>
    #endif
    #ifdef U8X8_HAVE_HW_I2C
    #include <Wire.h>
    #endif
    
    // SSD1306 128x64 OLED using hardware I2C
    U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(
      U8G2_R0,
      U8X8_PIN_NONE
    );
    
    void draw(void) {
      // Read humidity and temperature from the DHT sensor
      float h = dht.readHumidity();
      float t = dht.readTemperature();
    
      // Draw title text
      u8g2.setFont(u8g2_font_helvB10_tf);
      u8g2.setCursor(0, 16);
      u8g2.print("Temp & Humidity");
    
      // Draw temperature value
      u8g2.setFont(u8g2_font_helvB18_tf);
      u8g2.setCursor(0, 42);
      u8g2.print("T= ");
      u8g2.print(t);
      u8g2.print(" C");
    
      // Draw humidity value
      u8g2.setCursor(0, 64);
      u8g2.print("H= ");
      u8g2.print(h);
      u8g2.print(" %");
    }
    
    void setup(void) {
      // Initialise the DHT sensor
      dht.begin();
    
      // Initialise the OLED display
      u8g2.begin();
    }
    
    void loop(void) {
      // DHT sensors should not be read too frequently
      delay(2000);
    
      // Update the display using the page buffer method
      u8g2.firstPage();
      do {
        draw();
      } while (u8g2.nextPage());
    
      delay(1000);
    }
    

    Results

    Arduino temperature monitor output on OLED

    After completing the wiring and uploading the code, the Arduino temperature monitor will display live temperature and humidity readings on the SSD1306 OLED display. The values update automatically, giving a clear and readable output in real time.

    Note If the display remains blank or the readings look incorrect, double check all wiring connections to the DHT22 sensor and OLED display. Most issues are caused by incorrect power or I2C connections.

    Troubleshooting and Tips

    If your display remains blank or readings are incorrect, try the following checks:

    • Wiring – Double check all power, ground, and data pin connections. Loose jumpers or incorrect power pins are a common cause of no output.
    • Sensors not reading – DHT sensors can return NaN if not read properly. Make sure your wiring and code match the sensor type. If you see frequent failed reads, try increasing the delay between measurements. :contentReference[oaicite:1]{index=1}
    • Power – The DHT22 and DHT11 both run from 3.3V to 5V, but powering the DHT22 at 5V often gives more reliable results. Inconsistent USB power can also cause read errors. :contentReference[oaicite:2]{index=2}
    • Pull-up resistor – Some breakout modules include a built in pull-up resistor on the data line. If you have issues with readings, adding a 4.7 kΩ to 10 kΩ pull-up resistor between data and VCC can help.

    Voltage and Power Notes

    • OLED Display – Many 0.96" SSD1306 displays are 3.3 V logic. Make sure you power the module at its rated voltage and use the correct I2C logic levels if connecting to 5V boards.
    • DHT22 / DHT11 – Both sensors work between 3 V and 5.5 V. If powering at the lower end, ensure your board and sensors share a common ground and stable supply.

    Sensor Alternatives

    If you want more advanced sensing capabilities or more stable measurements, consider these alternatives:

    • BME280 - Measures temperature, humidity, and barometric pressure with higher precision. Communicates over I2C or SPI.
    • DS18B20 - Temperature only, waterproof options available, communicates via 1-Wire allowing multiple sensors on one pin.

    1 comment

    Easy to follow, wiring was clear, the end results on the .96" OLED were very visible and the sketch was flawless

    Claude,

    Leave a comment

    // Table of contents