DHT11 Humidity and Temperature sensor tutorial using Arduino
Overview
In this video tutorial, we will learn how to interfacing dht11 sensor with Arduino. Also, the real-time humidity and temperature value show on Lcd display.You can watch the following video below:-
Components Required
The required components list for this project given below:-- Arduino Uno
- DHT11 Humidity Sensor Module
- 16*2 Lcd Display
- 10k Potentiometer
- 220-ohm Resistor
- Breadboard
- Some Jumper Wire
Pinout
Circuit Schematic
The circuit diagram of the dht11, Lcd display and Arduino interfacing below:-
Source Code
The source code is given below:-
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define DHTPIN 10 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT11 // DHT 11
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
// Initialize device.
dht.begin();
Serial.println("DHTxx Unified Sensor Example");
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
dht.humidity().getSensor(&sensor);
delayMS = sensor.min_delay / 1000;
lcd.setCursor(0, 0);
lcd.print("Calibrating");
for(int i = 0; i <10; i++){
if (i==4)
{
lcd.setCursor(0, 1);
lcd.print(".");
}
else lcd.print(".");
delay(500);
}
lcd.setCursor(5, 1);
lcd.print("done");
delay(1000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("SENSOR ACTIVE");
delay(1500);
}
void loop() {
// Delay between measurements.
delay(delayMS);
lcd.clear();
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println("Error reading temperature!");
}
else {
lcd.setCursor(0, 0);
lcd.print("Temp : ");
Serial.print("Temperature: ");
Serial.print(event.temperature);
lcd.print(event.temperature);
Serial.println(" *C");
lcd.write(0xdf); // for dgree sign
lcd.print("C ");
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println("Error reading humidity!");
}
else {
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
Serial.print("Humidity: ");
Serial.print(event.relative_humidity);
lcd.print(event.relative_humidity);
lcd.print("%");
Serial.println("%");
}
}
You can download the library from here:-
No comments