HOW TO USE: DHT11

Are you a starter with Dasduino? Or a newbie when it comes to electronics? You fancy a specific module, but you don’t know how to use it? Don’t worry, we have our How To Use series!
How to Use is a series of blog tutorials by soldered where you will find everything you need to begin working with your favorite modules. Tutorials include technical characteristics, operating principles, instructions on how to connect the module with Dasduino and basic coding. Everything else is up to you and your imagination.
BASIC FEATURES
DHT11 is probably one of the first sensors you will meet. It is included in Dasduino set for beginners. It reads temperature and humidity and allows us to handle that information with ease.
Characteristics:
Temperature measuring range: 0° – 50° C
Humidity measuring range (in air): 20% – 90%
Temperature measuring deviation: +/- 2 °C
Humiditiy measuring deviation: +/- 5%
Voltage: 3V – 5V
Current: 100uA(standby), 2.5mA(measuring)
WORKING PRINCIPLE
Inside the module itself, there are, obviously, 2 sensor types:
* temperature sensor: small termistor(type of temperature sensor) soldered on board.
* humidity sensor: small pcb soldered to the basic one. It has open (uncovered) copper lines which are close to each other. The more humidity in the air, the more humidity is on the lines themselves and there is less resistance between them (or in case of water – just shows up – that is the reason why sensor starts to read values on 20%; only then it can read resistance).
In addition to the two components mentioned, there is another integrated circuit that analyzes the inputs of these two sensors and communicates with Croduino. (if you are really curious about what’s inside, you can open the blue case :))
Regarding communication, there is a library which will make using much easier. Namely, it has already summarized all the procedures needed to establish communication.
In this tutorial we will use:
HOW TO CONNECT MODULE WITH DASDUINO
DHT11 Dasduino
pin1 +5V
pin2 A0
pin3 –
pin4 gnd
It is suggested to add a pull-up resistor of 10kOhm.
CODE
At this link can find and download Arduino library which simplifies using of the DHT11. You’ll be able to find code which writes values of temperature and humidity inside Serial monitor under examples of that library. If you need some help regarding the installation of the library, check out our tutorial about it. After you’ve downloaded and installed the library, you can use the code below.
#include "DHT.h"
#define DHTPIN A0 // to which pin the DHT11 is connected
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void
setup
() {
Serial.begin(9600);
Serial.println(
"DHT11 test!"
);
dht.begin();
}
void
loop
() {
//wait for a few seconds between each measurement
delay
(2000);
// reads humidity in the h variable and the temperature in the t variable
float
h = dht.readHumidity();
float
t = dht.readTemperature();
if
(isnan(h) || isnan(t)) {
Serial.println(
"Unsuccessful reading of the sensor! "
);
return
;
}
Serial.print(
"Humidity: "
);
Serial.print(h);
Serial.print(
" %\t"
);
Serial.print(
"Temperature: "
);
Serial.print(t);
Serial.println(
" *C "
);
}