Temperature and Humidity (DHT11 and DHT22) on the Arduino

DHT11

For my arduino weather station I need temperature and humidity sensors. The first sensor I bought was the DHT11 (I got mine from this seller on ebay for £1.41), this is the datasheet.

DHT11 pins
DHT11 pins
Pin
1 VCC
2 DATA
3 Not Used
4 GND

 

 

Connections:

  • VCC to Arduino 5V
  • DATA to Arduino pin 2
  • GND to Arduino GND
  • Connect a 10K resistor between VCC and the data pin, this is acting as a pull up resistor

The connections can be seen in this Fritzing diagram and photo, the resistor is a little unclear, it is between pins 1 and 2.

DHT11 Fritzing DiagramDHT11 Connections

To test the sensor I used the AdaFruit DHT sensor library and the DHTtester example. All you need to do to get this to work is uncomment the sensor you are using eg:

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

Once this sketch is uploaded to the board opening up the Serial Monitor should show something like this:

Serial Monitor

This works but the problem with the DHT11 sensor can be seen in this screenshot, the temperature is fluctuating between 19oC and 22oC, this sensor is just not very accurate, certainly not accurate enough to work in a weather station.

DHT22

I decided to upgrade and try the DHT22, I bought mine from this seller on ebay for £2.22, not a massive price increase! (Datasheet)

DHT11&22
DHT11 and DHT22

DHT22 is slightly bigger than DHT11 as you can see in this photo. The pin layout is exactly the same as the DHT11 and it needs connecting in exactly the same way as for the DHT11. Don’t forget to update the DHTtester sketch to use DHT22!

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

Uploading this sketch produces these results:
DHT22 serial monitor
It is immediately that this sensor is a lot more accurate than the DHT11 and will be suitable for use in a weather station.

Add a Comment

Your email address will not be published. Required fields are marked *