The Arduino and sensor maintenance-temperature and humidity DHT11

 

Module DHT11 is used to measure temperature and humidity. The following example shows how to use its capabilities with Arduino.

In the example, we used the following elements:

Connect DHT11 to Arduino:

In order to read the values of temperature and humidity sensor connect the circuit with the Arduino in the following way:

 

Pin DHT11 Pin Arduino
VCC 5 V
DATE 2
GND GND

 

In the case of the sensor without the module, it is necessary to pull up the data line to the supply voltage VCC through a resistor, in this case a 4.7 kOhm (as in the following figure).

 

 

 Connection diagram of DHT11 sensor to Arduino Uno.

 

 

Wiring diagram for sensor DHT11 (the version with the module) with the Arduino Uno.

Program for Arduino

At the beginning of the library you want to add to the environment of the Arduino (Sketch -> Include Library -> Add .ZIP Library...).

In the example, we used the following code:

 

dht11 DHT11; 

#define DHT11PIN 2 //assigning Arduino pin 2 as the reading from the sensor 

void setup() 
{ 
 Serial.begin(115200); //initialize serial monitor 
 Serial.println("DHT11 test Program"); 
 Serial.println(); 
} 

void loop() 
{ 
 int chk = DHT11.read(DHT11PIN); //check status of the sensor, and then a message appears on the serial monitor 

 Serial.print("sensor Status: "); 
 switch (chk) 
 { 
 case DHTLIB_OK: 
 Serial.print("Oct"); 
 break; 
 case DHTLIB_ERROR_CHECKSUM: 
 Serial.println("checksum Error"); 
 break; 
 case DHTLIB_ERROR_TIMEOUT: 
 Serial.println("End time out - no response"); 
 break; 
 default: 
 Serial.println("Unknown error"); 
 break; 
 } 
 Serial.print("Humidity (%): "); //output value humidity 
 Serial.print((float)DHT11.humidity, 2); 
 Serial.print("TT"); 
 Serial.print("Temperature (C): "); //display the temperature 
 Serial.println((float)DHT11.temperature, 2); 

 delay(1000); //delay between consecutive readings is 1 second. 
} 

The result of this program, we can see on the screenshot:

 

A screenshot of the serial monitor.

Botland.store - shop for makers!