
Arduino-Based Smart Temperature and Humidity Monitor
1. Introduction
This project focuses on building a smart temperature and humidity monitoring system using an Arduino, a DHT11 sensor, and an OLED display. It can be used in various applications, such as home automation, greenhouse monitoring, and weather stations.
2. Learning Objectives
By completing this project, you will:
- Learn how to interface a DHT11 sensor with an Arduino.
- Understand how to display data on an OLED screen using I2C communication.
- Use the Adafruit_GFX and Adafruit_SSD1306 libraries to format text on the display.
- Process real-time sensor data and output meaningful information.
3. Components and Tools Required
To build this project, you will need the following components:
- Arduino Uno or Nano – Microcontroller board to process the data.
- DHT11 Sensor – Measures temperature and humidity.
- OLED Display (SSD1306, 0.96″) – Displays temperature and humidity readings.
- 10KΩ Resistor – Used as a pull-up resistor for the DHT11 sensor.
- Breadboard – Helps in prototyping the circuit.
- Jumper Wires – Connect various components.
- USB Cable – Used to upload the code to the Arduino.
4. Background and Key Concepts
DHT11 Sensor
The DHT11 is a digital sensor that measures temperature and humidity. It contains a capacitive humidity sensor and a thermistor to sense the surrounding environment. The sensor communicates with the Arduino using a single-wire data protocol.
Specifications:
- Temperature Range: 0°C to 50°C
- Humidity Range: 20% to 90% RH
- Accuracy: ±1°C for temperature, ±5% RH for humidity
- Operating Voltage: 3.3V – 5V
OLED Display (SSD1306, 0.96″)
OLED (Organic Light Emitting Diode) displays provide high contrast without requiring a backlight, making them energy efficient. The SSD1306 driver enables communication with the Arduino via I2C (SDA & SCL pins).
5. Circuit Connections
Wiring the DHT11 Sensor
- VCC → Connect to 5V on Arduino.
- GND → Connect to GND on Arduino.
- DATA → Connect to Digital Pin 2 on Arduino (use a 10KΩ pull-up resistor to 5V).
Wiring the OLED Display
- VCC → Connect to 5V on Arduino.
- GND → Connect to GND on Arduino.
- SDA → Connect to A4 on Arduino.
- SCL → Connect to A5 on Arduino.
6. Arduino Code for Temperature & Humidity Monitoring
Upload the following code to your Arduino board:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
// OLED display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// DHT11 settings
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
}
void loop() {
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (isnan(temp) || isnan(hum)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(10, 10);
display.print("Temp: ");
display.print(temp);
display.print("C");
display.setCursor(10, 40);
display.print("Hum: ");
display.print(hum);
display.print("%");
display.display();
delay(2000);
}
7. Code Explanation
Libraries Used
Adafruit_GFX.handAdafruit_SSD1306.hfor controlling the OLED display.DHT.hfor reading temperature and humidity from the DHT11 sensor.
Setup Function (setup())
- Initializes the Serial Monitor, DHT11 sensor, and OLED display.
- Checks if the OLED display is properly initialized.
Loop Function (loop())
- Reads temperature and humidity data from the DHT11 sensor.
- Displays the values on the OLED screen.
- Updates the display every 2 seconds.
8. Testing and Debugging
Common Issues and Solutions
1. The DHT11 sensor is not working
- Ensure that the data pin is correctly connected to pin D2 on the Arduino.
- Verify that a 10KΩ pull-up resistor is connected to the DATA pin.
2. OLED Display is not showing data
- Check if the I2C address (0x3C) matches your display module.
- Ensure SDA is connected to A4 and SCL is connected to A5.
3. Slow sensor readings
- The DHT11 has a 2-second delay between readings, which is normal.
9. Project Enhancements
Here are some ideas to expand this project:
- Wi-Fi Connectivity: Use an ESP8266 or ESP32 to send data to a cloud platform like Thingspeak or Firebase.
- Data Logging: Store temperature and humidity data on an SD card for future analysis.
- Alert System: Add a buzzer or LED that activates when temperature/humidity exceeds a set limit.
10. Summary
This project successfully monitors temperature and humidity using an Arduino, DHT11 sensor, and OLED display. It provides real-time feedback and can be further expanded with IoT capabilities, data logging, or alert systems.