Introduction
The DHT-11 is a digital-output relative humidity and temperature sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin.
In this tutorial you will learn how to use this sensor with Arduino uno. The room temperature & humidity will be printed to serial monitor. |
About the DHT-11 sensor
The DHT11 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed).
Connections are simple, the first pin on the left to 3-5V power, the second pin to your data input pin and the right most pin to ground.
Connections are simple, the first pin on the left to 3-5V power, the second pin to your data input pin and the right most pin to ground.
What you will need - Hardware
For this tutorial you will need:
|
The Circuit
The connections are pretty easy, see the image above with breadboard circuit schematic.
The code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | /* How to use the DHT-11 sensor with Arduino uno Temperature and humidity sensor More info: http://www.ardumotive.com/how-to-use-dht-11-sensor-en.html Dev: Michalis Vasilakis // Date: 2/7/2015 // www.ardumotive.com */ //Libraries #include <dht.h> dht DHT; //Constants #define DHT11_PIN 2 // DHT 22 (AM2302) - what pin we're connected to //Variables float hum; //Stores humidity value float temp; //Stores temperature value void setup() { Serial.begin(9600); } void loop() { int chk = DHT.read11(DHT11_PIN); //Read data and store it to variables hum and temp hum = DHT.humidity; temp= DHT.temperature; //Print temp and humidity values to serial monitor Serial.print("Humidity: "); Serial.print(hum); Serial.print(" %, Temp: "); Serial.print(temp); Serial.println(" Celsius"); delay(2000); //Delay 2 sec. } |
Download the code from here and open it with Arduino IDE. Inside you will also find and the DHT.h library.
|
|
Open the serial monitor from tools menu of Arduino IDE.
The result:
The result:
Well done!
You have successfully completed one more Arduino "How to" tutorial and you learned how to use the DHT-11 sensor.
I hope you liked this, let me know in the comments.
I hope you liked this, let me know in the comments.