Temperature and Humidity Sensor
by mohamedkareem in Circuits > Arduino
31 Views, 0 Favorites, 0 Comments
Temperature and Humidity Sensor
Building an temperature and humidity sensore
Downloads
Supplies
1- Breadboard. https://a.co/d/5JgXTQz
2- Jumper wires. https://a.co/d/1GdRblX
3- Dht11 sensor. https://a.co/d/iQ7q5OJ
4- Ardunio uno. https://a.co/d/44aqo58
5- Lcd. https://a.co/d/7TuVVJF
6- 10k Potentiometer. https://a.co/d/55CEDLb
Circuit Digram
This is the circuit diagram
The Code
The code .
take this code and paste it in ardunio ide
#include <DHT.h>
#include <LiquidCrystal.h>
// Set DHT pin
#define DHTPIN 2
// Initialize LCD with the interface pins (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// Define DHT sensor type
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Setup LCD's number of columns and rows
lcd.begin(16, 2);
dht.begin();
// Print a message to LCD
lcd.print("Temp: Humidity:");
}
void loop() {
delay(2000); // changed this to 2 seconds between readings
// Read humidity
float h = dht.readHumidity();
// Read temperature in Fahrenheit
float f = dht.readTemperature(true);
// Check if any reading failed
if (isnan(h) || isnan(f)) {
lcd.setCursor(0, 1); // Move cursor to the second row
lcd.print(" Sensor Error ");
return; // Skip the rest of the loop if there's an error
}
// Display temperature and humidity on the LCD
lcd.setCursor(0, 1);
lcd.print("T: ");
lcd.print(f, 1); // Display temperature with 1 decimal place
lcd.print("F ");
lcd.print("H: ");
lcd.print(h, 1); // Display humidity with 1 decimal place
lcd.print("%");
}
Install the Libraries
Don't forget to install the two libraries for the lcd and dht11
After this run the code and you had finished your project