hi guys,
I'm trying to read 40bits from DHT11(Humidity and temperature sensor).
It uses 1 wire communication.
I need to pull LOW for 18ms, and then pull HIGH to request data from it.
It then send 40bits immediately, 28us represents"0" and 70us represents"1".
Here is the datasheet- www.robotshop.com/PDF/dht11.pdf
I've been trying to get data for several days with pulseIn() and I couldn't get it.
By using the code below,
#include <SoftwareSerial.h>
int response;
int data[40];
void setup(){
pinMode(11,OUTPUT);
digitalWrite(11,HIGH);
Serial.begin(9600);
}
void loop(){
delay(1000);
pinMode(12,OUTPUT);
digitalWrite(12,HIGH);
digitalWrite(12,LOW);
delay(18);
digitalWrite(12,HIGH);
pinMode(12,INPUT);
response = pulseIn(12,HIGH);
Serial.println(response);
Serial.println();
for (int i=0; i<40;i++){
data[i] = pulseIn(12,HIGH);
}
for (int i=0; i<40;i++){
Serial.println(data[i]);
}
delay(10000);
}
I gets
23
64
23
23
23
24
24
23
24
69
14
23
24
23
23
70
48
69
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
In contrast, by using a more stupid method,
#include <SoftwareSerial.h>
int response;
int data[40];
void setup(){
pinMode(11,OUTPUT);
digitalWrite(11,HIGH);
Serial.begin(9600);
}
void loop(){
delay(1000);
pinMode(12,OUTPUT);
digitalWrite(12,HIGH);
digitalWrite(12,LOW);
delay(18);
digitalWrite(12,HIGH);
pinMode(12,INPUT);
response = pulseIn(12,HIGH);
Serial.println(response);
Serial.println();
response = pulseIn(12,HIGH);
Serial.println(response);
response = pulseIn(12,HIGH);
Serial.println(response);
*40 times!!!!!
}
delay(10000);
}
guess what? I got only 8 none zero numbers!
Could anybody help with this problem? This is killing me~
Thanks!