DHT11/22 - the 2-sensors is not working

Hi, I am using the idDHT11 Interrupt Driven Library as I need to monitor two sensors.

I know the DHT11 are inaccurate but they are good enough and I can use an offset to match them up before putting them to work. But for now, the example program is not working and I can't see why.

If I use the single_sensor.ino and set the Pin assignment to 2
#1 Hum=43% and Temp=72.2
Swapping in the other sensor by changing the Pin assignment to 3
#2 Hum=38% and Temp=74.6

When I use the "2_sensors_example.ino" for the same raw data it is NOT reading the correct Temperature for sensor #2 as I am getting...
#1 Hum=43% and Temp=72.2
#2 Hum=38% and Temp=72.2

It is reading the correct Humidity for each sensor but using the Temp from #1 in the Console.

I have checked the .h and the .cpp files and it all looks OK, but I am not a well versed C-programmer. :slight_smile:

I am not locked into any libraries or example sketches so I am open to suggestions for anything that allows me to use two sensor-results in the same time frame, give or take 20-seconds or so. It is not critical.

Thanks

you could try my DHT library - Arduino/libraries/DHTstable at master · RobTillaart/Arduino · GitHub -

test sketches here - Arduino/libraries/DHTlib/examples at master · RobTillaart/Arduino · GitHub -

Thanks Rob,
But it will not compile. I checked online and it was suggested that a conflict with other dht libraries, so deleted all other occurrences of dht-anything and still will not compile.


Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"
dht11_test.ino: In function 'void loop()':
dht11_test:39: error: 'DHTLIB_ERROR_CONNECT' was not declared in this scope
dht11_test:42: error: 'DHTLIB_ERROR_ACK_L' was not declared in this scope
dht11_test:45: error: 'DHTLIB_ERROR_ACK_H' was not declared in this scope
'DHTLIB_ERROR_CONNECT' was not declared in this scope


the latest versions of the test sketches test for more errors than the stable version provides. I need to fix that.

for now just delete those 3 case from switch in the test sketch.
(line 39-48 I guess)

give this one a try

//
//    FILE: dht11_test.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.01
// PURPOSE: DHT library test sketch for DHT11 && Arduino
//     URL:
//
// Released to the public domain
//

#include <dht.h>

dht DHT;

#define DHT11_PIN 5

void setup()
{
  Serial.begin(115200);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}

void loop()
{
  // READ DATA
  Serial.print("DHT11, \t");
  int chk = DHT.read11(DHT11_PIN);
  switch (chk)
  {
    case DHTLIB_OK:  
		Serial.print("OK,\t"); 
		break;
    case DHTLIB_ERROR_CHECKSUM: 
		Serial.print("Checksum error,\t"); 
		break;
    case DHTLIB_ERROR_TIMEOUT: 
		Serial.print("Time out error,\t"); 
		break;
    default: 
		Serial.print("Unknown error,\t"); 
		break;
  }
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.println(DHT.temperature, 1);

  delay(2000);
}
//
// END OF FILE
//

Thanks, but that is not using the Interrupt Driven one. I have been using two Analog pins and a basic DHT library after seeing some other examples and have the two temp sensors working fine.

What's the advantage of using the Interrupt version?

The reading of a DHT sensor takes ~5000 micros to read 41 pulses.
That is more than 0.1 millisec per pulse, most of that time waiting for the next pulse.

Using the interrupt version makes more efficient use of those 5000 micros as it can do other things "in parallel"

Thanks Rob,

I am back to using your Interrupt version, although speed is not an issue as this is intended to turn on the swamp cooler when humidity and temp outside is suitable. Then once running, it will control pump and fan speed on/off to hold a preset temperature inside.

I have seen some mentions of controlling air conditioners since starting this project so will check them out, but for now the 2 x DHT11 are working fine with your Library. I added some percentage fudge factors to balance up the inaccuracies between the two DHT11 as they seem steady values but wrong with the real temp. One is off by 2-deg F, the other by 3. :slight_smile:

Thanks very much.