DHT11 Temp/Humidity sensor
Gary Wilkerson
Posts: 3
Has anyone interfaced to this sensor? I'm having problems reading the 40 bit stream. Any examples would be appreciated.
Gary
Gary
Comments
Details are sketchy. Found a datasheet of sorts and a page with arduina code.
It's "9600", but I don't know if their convention is 'True' or 'Inverted'.
Are you using a BS2 of some sort?
http://www.emesystems.com/BS2index.htm
Sorry for the delay responding; I had to make an unexpected trip to Chicago. It is big with the Arduina crowd, I was attracted to the price. I am using a BS2. I think the problem I'm having is parsing the string.
I'll take a look at the emesystems link.
Thanks!
Gary
I hope you are ok, i have the same problem with the DHT11 sensor, i try to connect to the basic stamp 2, but i can't... i would like to know if you solve the problem or not??? i'm continue trying with the sensor if i have good news... i'll notify you.
Greetings
Best regards..
#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(19200);
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 = 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);
}
this is the datasheet for this sensor..http://www.robotshop.com/PDF/dht11.pdf
thanks
Each bit is preceded by a 50us low time with the following
high time determining the data_bit's value, a "0" is 26-28us and
a "1" is 70us.
I doubt that any Stamp is fast enough to
decide 0-or-1 (or 0-or-not0) on the fly.
You have to establish a VAR array, take in those times/transitions
and then interpret the results (later.)
A bit transmission always begins with the 50us (!!) low time - that's the
time you/it has to stash in RAM the PULSIN val result and get ready for
the next incoming data_bit/pulse_time.
I may be wrong, but a BS2sx or BS2px will be required for the speed
and the scratchpad RAM.
(It's very SX'able and Propeller easy.)
Post Edit -- If you don't take in the 8 error check bits at the end, then you cut your RAM requirements from 40bytes to 32. [It's a byte for the pulsin_time taken by each data_bit (40 or 32.)]
I think you're right. I didn't consider the speed of the processor and it being unable to respond to/ detect the states.
Need to look further, thanks for the help.
Gary