You are here

Multiple DHT humidity sensors on Arduino

Primary tabs

A reader of my book Arduino Projects To Save The World recently asked me about the DHT11 and DHT22 sensors. In particular, how to connect multiple sensors (and how to write the code for it) to an Arduino. I must admit I had never considered it. I have used them plenty of times, but not in parallel. Turns out, Adafruit's DHT library makes it super easy. Just repeate the wiring diagram for each sensor, connecting the data pin to any digital pin available, one pin per sensor. In the example below, I chose pins 2 and 3.

The DHT command creates the object, and we can give any name we want to it. So, in the code DHT dht1(DHT1PIN, DHT1TYPE); 'dht1' is the name I chose, but could easily be 'inside' or 'outside.' And the variables can be similarly named: DHT outsideDHT(outsidePin, outsideType); would be fine.

The following example was tested with Arduino V1.0.5, a DHT11 and a DHT22 running together: