Lesson 22 Humiture Sensor

Share for us

Introduction

The digital temperature and humidity sensor DHT11 is a composite sensor that contains a calibrated digital signal output of temperature and humidity. The technology of a dedicated digital modules collection and the temperature and humidity sensing technology are applied to ensure that the product has high reliability and excellent long-term stability.

The sensor includes a resistive sense of wet component and an NTC temperature measurement device, and is connected with a high-performance 8-bit microcontroller.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * Humiture sensor module

– 1 * LCD1602

– 1 * Potentiometer

– Jumper wires

Experimental Principle

Only three pins are available for use: VCC, GND, and DATA. The communication process begins with the DATA line sending start signals to DHT11, and DHT11 receives the signals and returns an answer signal. Then the host receives the answer signal and begins to receive 40-bit humiture data (8-bit humidity integer + 8-bit humidity decimal + 8-bit temperature integer + 8-bit temperature decimal + 8-bit checksum). For more information, please refer to DHT11 datasheet.

Experimental Procedures

Step 1: Build the circuit

                      Humiture Sensor Module          SunFounder Uno

                                          S ————————————— D4

                                          – —————————————- GND

                                          + —————————————  5V

LCD1602 connection: connect pin RS to digital pin 5; R/W to GND; E to digital pin 6; D4~D7 to digital pin 9 to 12; VSS to GND; VDD to 5V; A to 3.3V; K to GND

Potentiometer connection: Connect the middle pin to VO of LCD1602 and any other pin to GND

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno

Now, you can see the value of the current humidity and temperature displayed on the LCD.

Code

#include <dht.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(5, 6, 9, 10, 11, 12);dht DHT;#define DHT11_PIN 4void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}void loop()
{
// READ DATA
Serial.print(“DHT11, \t”);
//read the value returned from sensor
int chk = DHT.read11(DHT11_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print(“OK,\t”);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print(“Checksum error,\t”);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print(“Time out error,\t”);
break;
default:
Serial.print(“Unknown error,\t”);
break;
}
// DISPLAY DATA
lcd.setCursor(0, 0);
lcd.print(“Tem:”);
lcd.print(DHT.temperature,1); //print the temperature on lcd
lcd.print(” C”);
lcd.setCursor(0, 1);
lcd.print(“Hum:”);
lcd.print(DHT.humidity,1); //print the humidity on lcd
lcd.print(” %”);
delay(200); //wait a while
}