Adafruit DHT - Two sensors

Hi everybody....... need a bit of help with coding.

I have two sensors ( DHT11 and DHT22 ). Looking at the sample code, ( which works fine ), I cannot determine if and how I would modify it for two sensors......

If anyone can provide a sample sketch or solution even if based on DHTLib that would be great!!!

Sample....

#include "DHT.h"
#define DHTPIN 2
// # define DHTPINb 3 ????????????????????????????????
// #define DHTTYPEb DHT11   // DHT 11  ??????????????????????????
#define DHTTYPE DHT22   // DHT 22

DHT dht(DHTPIN, DHTTYPE);
// DHT dhtb(DHTPIN, DHTTYPE); // Isn't TYPE global so you can't set it differently for 2 devices?????????????

Define the pin numbers and call the function with the correct pin number:

DHT11_PIN = pin 4 // define the pin on the fly
int chk = DHT.read11(DHT11_PIN); //Check Read Status
do some more stuff with pin 4 DHT
DHT11_PIN = pin 5 // re-define the pin on the fly
int chk = DHT.read11(DHT11_PIN); //Check Read Status
do some more stuff with pin 5 DHT
or define both and call each one as needed
Not recommended to put long wires on sensors like the DHT series W/O small value pull-ups < 4K7, > 2K2 ohms and even then not for more that a meter or maybe two as the Arduino pullls down the pin and waits 15uS then flips it to an input and waits for the DHT device to “release” the pin (let it go high) the time measured from flip to input to the falling edge of the “pin” determines a 1 or a 0. The whole transaction usually takes
< 50uS which is easy to “smear” or distort with extra capacity on the measurement pin).

Doc

wulfy117:

// DHT dhtb(DHTPIN, DHTTYPE); // Isn't TYPE global so you can't set it differently for 2 devices?????????????

No. “TYPE” is a global. #define creates macros which are text-replacements done before compiling.

dhtb is an object of the DHT type. So you can create multiples if you wish.

DHT dh1(DHTPIN1, DHTTYPE);
DHT dh2(DHTPIN2, DHYTYPE);

assuming that you assign DHTPIN1 and DHTPIN2 values.

Also, you might want to check your keyboard. Looks like the ‘?’ key is getting stuck when you press it.