
Arduino Project: Smart Home Temperature and Humidity Monitor
This project involves building a smart home system that monitors temperature and humidity levels using an Arduino and a DHT11 sensor. The data will be displayed on an LCD, and thresholds will trigger visual and audible alerts. This project is perfect for learning how sensors, displays, and basic control systems work.
1. Introduction
Monitoring indoor environmental conditions is important for comfort and health. This project demonstrates how to build a temperature and humidity monitoring system that can be used in a smart home. When the temperature or humidity crosses predefined limits, an LED and a buzzer will activate, alerting the user. The readings will be continuously displayed on an LCD screen.
Real-world applications:
- Smart home automation
- Agricultural monitoring
- Industrial environmental control
- Personal health monitoring
2. Learning Objectives
By the end of this project, you will:
- Understand how to interface a DHT11 sensor with Arduino.
- Learn to use an I2C-based 16×2 LCD for displaying sensor data.
- Implement conditional logic for threshold-based alerts.
- Gain experience in integrating multiple components with Arduino.
3. Tools and Components
Here’s what you’ll need:
Hardware
- Arduino Uno (or compatible board)
- DHT11 temperature and humidity sensor
- I2C 16×2 LCD display
- Breadboard
- 10kΩ potentiometer (for contrast control on the LCD)
- LED (any color)
- Buzzer
- Jumper wires
- USB cable
Software
- Arduino IDE (latest version)
- DHT sensor library (
DHT.h) - LiquidCrystal_I2C library
4. Background/Definitions
Arduino
An open-source electronics platform based on easy-to-use hardware and software. It’s widely used for creating interactive projects.
DHT11 Sensor
A basic, low-cost digital sensor that provides temperature and humidity readings. It uses a capacitive humidity sensor and a thermistor to measure environmental conditions and outputs data via a digital pin.
I2C Protocol
Inter-Integrated Circuit (I2C) is a serial communication protocol used to connect low-speed devices like microcontrollers, sensors, and displays.
LiquidCrystal_I2C Library
This library simplifies the process of controlling an LCD with an I2C backpack, reducing the number of pins needed from 6 to 2.
5. Step-by-Step Guide
Step 1: Circuit Diagram and Connections
Wiring Instructions:
- DHT11 Sensor
- VCC → 5V
- GND → GND
- Data → Pin 2
- I2C 16×2 LCD
- VCC → 5V
- GND → GND
- SDA → A4
- SCL → A5
- LED
- Anode (+) → Pin 9
- Cathode (-) → GND (via a 220Ω resistor)
- Buzzer
- Positive terminal → Pin 10
- Negative terminal → GND
Step 2: Source Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Define DHT sensor type and pin
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address 0x27 for a 16x2 display
const int ledPin = 9;
const int buzzerPin = 10;
void setup() {
// Initialize LCD
lcd.init();
lcd.backlight();
lcd.print("Initializing...");
// Initialize DHT sensor
dht.begin();
// Configure pins
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
delay(2000);
lcd.clear();
}
void loop() {
// Read temperature and humidity
float temp = dht.readTemperature();
float hum = dht.readHumidity();
// Check if reading failed
if (isnan(temp) || isnan(hum)) {
lcd.setCursor(0, 0);
lcd.print("Error reading");
lcd.setCursor(0, 1);
lcd.print("sensor data!");
return;
}
// Display data on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Hum: ");
lcd.print(hum);
lcd.print(" %");
// Check thresholds
if (temp > 30 || hum > 70) {
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}
// Wait for 2 seconds before the next reading
delay(2000);
}
Step 3: Explanation of Code
- Library Imports: Include the
Wire.handLiquidCrystal_I2C.hlibraries for I2C communication andDHT.hfor reading temperature and humidity. - Initialization: The
setup()function initializes the LCD and DHT sensor and configures the LED and buzzer pins. - Main Loop: The
loop()function reads the temperature and humidity values, displays them on the LCD, and triggers alerts if thresholds are exceeded.
6. Testing and Debugging Tips
- Sensor Initialization Failure: Ensure the DHT sensor is properly connected to the 5V and GND pins.
- LCD Not Displaying: Check the I2C address (it might be 0x3F instead of 0x27). Use an I2C scanner sketch to find the correct address.
- No Buzzer or LED Response: Verify the pins are correctly connected and not damaged.
7. Extensions and Improvements
- Data Logging: Store temperature and humidity data on an SD card for later analysis.
- Wi-Fi Connectivity: Use an ESP8266 or ESP32 to send data to a cloud platform for remote monitoring.
- Mobile Notifications: Integrate with a platform like Blynk to receive alerts on your smartphone.
- Multiple Sensors: Add additional sensors (e.g., light, air quality) to create a more comprehensive environmental monitoring system.
Conclusion
This project introduced you to building a simple yet practical smart home device using an Arduino, a temperature and humidity sensor, and an LCD display. You learned how to read sensor data, display it, and implement alerts when conditions exceed predefined limits. With this foundation, you can expand the project to include more advanced features like data logging and remote monitoring.