πΉ Step 1: Components Needed
- Arduino Uno (or Nano) β 1x
- DHT11 Temperature & Humidity Sensor β 1x
- 16×2 LCD with I2C module β 1x
- Jumper wires β some
- Breadboard β optional
πΉ Step 2: Wiring Diagram (Connections)
DHT11 β Arduino
- VCC β 5V
- GND β GND
- Data β D2
I2C LCD β Arduino
- VCC β 5V
- GND β GND
- SDA β A4
- SCL β A5
πΉ Step 3: Arduino Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 2 // DHT11 data pin connected to D2
#define DHTTYPE DHT11 // Using DHT11 sensor
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD at I2C address 0x27
void setup() {
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on backlight
dht.begin(); // Start DHT11 sensor
lcd.setCursor(0,0);
lcd.print("Temp & Humidity");
delay(2000);
lcd.clear();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
// Check if any reading failed
if (isnan(h) || isnan(t)) {
lcd.setCursor(0,0);
lcd.print("Sensor Error!");
return;
}
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Hum: ");
lcd.print(h);
lcd.print(" %");
delay(2000); // Update every 2 seconds
}
πΉ Step 4: How It Works
- The DHT11 sensor reads temperature and humidity.
- Data is sent to the Arduino UNO.
- Arduino sends values to the LCD via I2C.
- The display refreshes every 2 seconds, showing Temp (Β°C) and Humidity (%).
πΉ Step 5: Next Upgrades (Optional)
- Add a buzzer if temperature exceeds a limit.
- Add an SD card module to log data.
- Send readings to a mobile app or cloud via ESP8266 WiFi module.