To test the sketch, we'll use an Arduino. You can use any micrcontroller that can do microsecond timing, but since its a little tricky to code it up, we suggest verifying the wiring and sensor work with an Arduino to start.

You should have the Arduino IDE software running at this time. Next it’s necessary to install our DHT library, which can be done though the Arduino Library Manager:

Sketch→Include Library→Manage Libraries…

Enter “dht” in the search field and look through the list for “DHT sensor library by Adafruit.” Click the “Install” button, or “Update” from an earlier version.

IMPORTANT: As of version 1.3.0 of the DHT library you will also need to install the Adafruit Unified Sensor library, which is also available in the Arduino Library Manager:

Now load up the Examples→DHT→DHTtester sketch

If you're using a DHT11 sensor, comment out the line that sets the type:
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
and uncomment the line that says:
#define DHTTYPE DHT11   // DHT 11
This will make the data appear correctly for the correct sensor. Upload the sketch!
You should see the temperature and humidity. You can see changes by breathing onto the sensor (like you would to fog up a window) which should increase the humidity.

You can add as many DHT sensors as you line on individual pins, just add new lines such as

DHT dht2 = DHT(pin, type);

below the declaration for the initial dht object, and you can reference the new dht2 whenever you like.

This guide was first published on Jul 29, 2012. It was last updated on Apr 18, 2024.

This page (Using a DHTxx Sensor with Arduino) was last updated on Mar 08, 2024.

Text editor powered by tinymce.