Digital Thermometer and Hygrometer with LCD
Digital Thermometer and Hygrometer with LCD
DHT11SENSOR
Components Needed:
- Arduino Uno (or any compatible board)
- LCD Display (16x2) - using
<Adafruit_LiquidCrystal.h>library - DHT11 Temperature and Humidity Sensor
- 10kΩ potentiometer (for adjusting LCD contrast)
- Breadboard and jumper wires
Wiring Diagram:
LCD Display:
- Connect VSS to GND and VDD to 5V
- Connect RS to Arduino pin 12
- Connect RW to GND
- Connect E (Enable) to Arduino pin 11
- Connect D4, D5, D6, D7 to Arduino pins 5, 4, 3, 2, respectively
- Connect the potentiometer:
- One side to GND
- Other side to 5V
- Middle pin to the VO (contrast) pin of the LCD
DHT11 Sensor:
- Connect VCC to 5V
- Connect GND to GND
- Connect the Data pin to Arduino digital pin 7
Explanation:
- DHT11 Sensor: The DHT11 sensor measures both temperature and humidity, and we use the
DHTlibrary to access these values. - The
dht.readTemperature()anddht.readHumidity()functions are used to get temperature and humidity values, respectively. - These values are then displayed on the 16x2 LCD.
- The code includes error handling to check if the sensor read fails (
isnan(humidity) || isnan(temperature)).
Code
#include <Adafruit_LiquidCrystal.h>
#include <DHT.h>
#define DHTPIN 7 // Pin connected to DHT11 data pin
#define DHTTYPE DHT11 // DHT11 sensor type
Adafruit_LiquidCrystal lcd(0);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Temp & Humidity");
dht.begin(); // Initialize DHT sensor
delay(2000); // Wait for the sensor to get ready
}
void loop() {
float humidity = dht.readHumidity(); // Read humidity
float temperature = dht.readTemperature(); // Read temperature in Celsius
// Check if any reads failed
if (isnan(humidity) || isnan(temperature)) {
lcd.setCursor(0, 1);
lcd.print("Sensor Error ");
} else {
// Display temperature on LCD
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C "); // Add padding to clear previous readings
lcd.setCursor(0, 2);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" % "); // Add padding to clear previous readings
}
delay(2000); // Update every 2 seconds
}
Summary
- Gather all the required components.
- Set up the wiring according to the wiring diagram.
- Install the required libraries in the Arduino IDE.
- Upload the code to the Arduino.
- Monitor the LCD to see the temperature and humidity readings.
.jpg)
Comments
Post a Comment