DIY Project: Build a Smart Monitor - Temperature and Humidity Monitor with OLED Display
- Gulshan Sharma
- Jan 13
- 3 min read
Introduction
Monitoring temperature and humidity is essential in many environments, such as greenhouses, server rooms, and homes. This DIY project will guide you in creating a smart temperature and humidity monitor using a DHT22 sensor, an Arduino Nano, and an OLED display. This project is beginner-friendly and focuses on hands-on learning while incorporating key electronics concepts.
Materials Required for Smart Monitor
Hardware Components:
Arduino Nano (or any compatible microcontroller) ×1
DHT22 (AM2302) Temperature and Humidity Sensor ×1
0.96-inch OLED Display (128x64, SSD1306 driver) ×1
Breadboard ×1
Jumper wires ×10-15
USB cable (for programming Arduino) ×1
5V power supply or battery pack ×1
Software:
Arduino IDE (downloadable from Arduino)
Libraries:
Adafruit_SSD1306 (for the OLED display)
DHT sensor library (for the DHT22)
Circuit Diagram
Here is the basic wiring diagram:

Step 1: Setting Up Hardware
Connect the DHT22 Sensor:
Place the sensor on the breadboard.
Connect its VCC pin to the 5V pin of the Arduino Nano.
Connect the GND pin to the Arduino's GND.
Connect the DATA pin of the DHT22 to digital pin D2 on the Arduino Nano.
Connect the OLED Display:
Connect the OLED’s VCC pin to the 3.3V or 5V pin of the Arduino Nano (check your display specs).
Connect GND to the common ground.
Connect the SDA pin of the OLED to A4 on the Arduino Nano.
Connect the SCL pin of the OLED to A5 on the Arduino Nano.
Step 2: Setting Up Software
Install Arduino IDE:
Download and install the Arduino IDE if not already installed.
Install Libraries:
Open the Arduino IDE.
Navigate to Sketch > Include Library > Manage Libraries.
Search for "Adafruit SSD1306" and install it.
Search for "DHT Sensor Library" by Adafruit and install it.
Step 3: Coding
Here’s the complete code for this project:
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <DHT.h>
// Pin definitions
#define DHTPIN 2 // Pin where DHT22 is connected
#define DHTTYPE DHT22
// OLED display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize Serial Monitor
Serial.begin(9600);
Serial.println("DHT22 and OLED Display Test");
// Initialize DHT sensor
dht.begin();
// Initialize OLED display
if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear and display a startup message
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Starting...");
display.display();
delay(2000);
}
void loop() {
// Read temperature and humidity
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if reading was successful
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Display readings on Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("°C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println("%");
// Display readings on OLED
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Temp & Humidity Monitor");
display.setCursor(0, 16);
display.print("Temp: ");
display.print(temperature);
display.println(" C");
display.setCursor(0, 32);
display.print("Humidity: ");
display.print(humidity);
display.println(" %");
display.display();
delay(2000); // Update every 2 seconds
}
Step 4: Upload the Code
Connect the Arduino Nano to your computer via USB.
Open the Arduino IDE and select the correct COM port.
Copy the code above into the IDE.
Click Upload to program the Arduino.
Step 5: Test the Project
Once the upload is complete, the OLED display should show the temperature and humidity readings.
Check the readings by placing the sensor in different environments (e.g., blowing warm air on it or placing it in a cool area).
Enhancements
Add a buzzer to alert when the temperature or humidity crosses a threshold.
Connect the project to Wi-Fi using an ESP8266 module to monitor readings remotely.
Replace the breadboard with a PCB for a more robust design.
Conclusion
This project is an excellent introduction to using sensors and displays with microcontrollers. It offers a practical application of coding, circuit design, and sensor integration. Once completed, you’ll have a functional temperature and humidity monitor that can be further enhanced or customized for your specific needs.
Happy Building! 😊
Looking for Electronics R&D Support, BOM Procurement, PCB, Turnkey, etc., please reach out to sales@xelec.in
Комментарии