Are you fascinated by the world of electronics and eager to start a hands-on project? This guide will help you create a sleek, functional temperature monitor using an Arduino Nano, a DHT22 sensor, and a vibrant OLED display. Whether you're a seasoned tinkerer or a curious beginner, this project is perfect for diving into the exciting realm of Arduino. By the end of this guide, you'll have a working device that accurately displays temperature and humidity, making it a practical addition to your home or a stepping stone for more complex projects.
Parts List:
- Arduino Nano (or most other Arduinos)
- USB cable for Arduino
- 0.96" OLED Display SSD1306
- DHT22 temperature and humidity sensor
- Jumper wires
Software Requirements:
- Arduino IDE (Either online or installed works)
- "Adafruit SSD1306" library by Adafruit
- "DHT sensor library" by Adafruit
Step 1: Install Libraries
- Open the Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries.
- In the Library Manager, search for "Adafruit SSD1306".
- Click on the result and click Install All.
- Search for "DHT sensor library" by Adafruit.
- Click on the result and click Install All.
Step 2: Wiring
Refer to the wiring diagram below and use the following wiring key to connect your components.
Wiring Key:
DHT22 Sensor- VCC to 5V
- GND to GND
- DATA to D2 (or any digital pin)
SSD1306 OLED Display
- VCC to 3.3V
- GND to GND
- SCL to A5 (or SCL)
- SDA to A4 (or SDA)
Wiring Diagram:
Step 3: Code
Upload the following code to your Arduino to start monitoring the temperature and humidity:
/* * Temprature & Humidity Arduino Project using DHT22 Sensor and 0.96 OLED Display * * https://zaitronics.com.au/blogs/main/building-an-arduino-temperature-monitor-with-dht22-and-0-96-oled-display * * by Ethan - Zaitronics */ #include <Arduino.h> #include <U8g2lib.h> #include "DHT.h" #define DHTPIN 2 // which pin we're connected to #define DHTTYPE DHT22 // DHT 22 (AM2302) DHT dht(DHTPIN, DHTTYPE); #ifdef U8X8_HAVE_HW_SPI #include <SPI.h> #endif #ifdef U8X8_HAVE_HW_I2C #include <Wire.h> #endif U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); void draw(void) { // // graphic commands to redraw the complete screen should be placed here float h = dht.readHumidity(); // Read temperature as Celsius float t = dht.readTemperature(); // Read temperature as Fahrenheit float f = dht.readTemperature(true); u8g2.setFont(u8g2_font_helvB10_tf); u8g2.setCursor(0, 16); u8g2.print("Temp & Humidity"); u8g2.setFont(u8g2_font_helvB18_tf); u8g2.setCursor(0, 42); u8g2.print("T= "); u8g2.print(t); u8g2.print(" °C"); u8g2.setCursor(0, 64); u8g2.print("H= "); u8g2.print(h); u8g2.print(" %"); } void setup(void) { dht.begin(); u8g2.begin(); } void loop(void) { // Wait a few seconds between measurements. delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius float t = dht.readTemperature(); u8g2.firstPage(); do { draw(); } while ( u8g2.nextPage() ); delay(1000); }
Results:
Once you have completed the wiring and uploaded the code, your Arduino temperature monitor will start displaying the temperature and humidity readings on the OLED display. This project is a great way to get started with Arduino and sensor integration.
Note: Ensure that the DHT22 sensor and OLED display are connected properly to avoid issues with the readings and display output. If you encounter any problems, double-check the wiring and comment below if you need any more help
1 comment
Easy to follow, wiring was clear, the end results on the .96" OLED were very visible and the sketch was flawless