2 Temp&Humi Sensors on the same Arduino

Hey guys,

I am trying to use 2 Temperature & Humidity Sensor Modules (http://www.seeedstudio.com/wiki/Grove-_Temperature_and_Humidity_Sensor) with the same Arduino. As the code for using only one sensor is quite complicated for my skill level, I would really need some help.

Thank you so much,
zws

[code]#define DHT11_PIN 0 // ADC0

byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++){

while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
delayMicroseconds(30);

if(PINC & _BV(DHT11_PIN)) 
  result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN)));  // wait '1' finish

}
return result;
}

void setup()
{
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);

Serial.begin(9600);

Serial.println(“Ready”);
}

void loop()
{
byte dht11_dat[5];
byte dht11_in;
byte i;
// start condition
// 1. pull-down i/o pin from 18ms
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC |= _BV(DHT11_PIN);
delayMicroseconds(40);

DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);

dht11_in = PINC & _BV(DHT11_PIN);

if(dht11_in){
Serial.println(“dht11 start condition 1 not met”);
return;
}
delayMicroseconds(80);

dht11_in = PINC & _BV(DHT11_PIN);

if(!dht11_in){
Serial.println(“dht11 start condition 2 not met”);
return;
}
delayMicroseconds(80);
// now ready for data reception
for (i=0; i<5; i++)
dht11_dat[i] = read_dht11_dat();

DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);

byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println(“DHT11 checksum error”);
}

Serial.print(“Current humdity = “);
Serial.print(dht11_dat[0], DEC);
Serial.print(”.”);
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print(“temperature = “);
Serial.print(dht11_dat[2], DEC);
Serial.print(”.”);
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");

delay(2000);
}[/code]

arduino.cc/playground/Main/DHT11Lib

Use this library.

In this line

int chk = DHT11.read(DHT11PIN);

you read values from the sensor you define in DHT11PIN.
If your reading is finished you can start another with a new pin.

Thank you for the tip, Rony!

Unfortunately it doesn’t work. I tried it with only one sensor. I installed the library, I copied the sketch, I changed the #define DHT11PIN 2 to 0 (as I use that pin), it gives me no errors while verifying.

But once I run it on Arduino, it gives me “Read sensor: Time out error” which by the definition on the link it says “-2 : if a timeout occured, communication failed.”

Did you use the library yourself with the Temp&Humi Sensor module from Seeedstudio?

By the way, I tried to use the library from adafruit for the DHT11 and I had problems with that as well (you can check: http://www.ladyada.net/learn/sensors/dht.html for the tutorial from adafruit)

Pin 0 is RX from serial interface. Pin 1 is TX.
You cannot use this pins for your sensor if you use the serial interface.

Yes i use this lib (and also i tested ladyada lib) with this sensor and it works very well.

Hey Rony,

Thank you so so much!

I was stuck on getting some response while using the analogue inputs :smiley:

I just tested 2 and while they are next to each other, they output totally different results. I also let them settle for about 15 minutes before copying the results you see below.

Read sensor 1: OK
Humidity1 (%): 37.00
Temperature1 (oC): 22.00
Read sensor 2: OK
Humidity2 (%): 33.000
Temperature2 (oC): 21.000

Humidity is off by 4% and Temperature by 1oC. :frowning:

It says there on the wiki page that:

(see http://www.seeedstudio.com/wiki/Grove-_Temperature_and_Humidity_Sensor)


but reality hit me pretty hard :cry:

If you want a sensor with better tolerance you must cash more then $5 or $15.
For this price the results are very good :wink:

You can calibrate your sensor in your software