Forum >DHT11, hydrometer leds don't go off. Help! :P
General

DHT11, hydrometer leds don't go off. Help! :P

userHead renssmal 2012-05-30 12:20:41 6665 Views3 Replies
Hello

For my fist arduino project I want to make an hydrometer. When the humidity is between the 0 and 40 % the first bleu led must go on and when the humidity is between the 50 and 60 % the second led must go on and the other led must go out and ect.

I bought the following components
- Arduino atmega 168
- DHT11 temperature & humidity sensor
- 4 bleu leds
- jump wire

I found the following code on the DFRobot wiki and paste my "if part" behind it. But my problem is when I upload the code the blue led keeps burning also when the huminity is lower than 50 % or higher than 60% . What goes wrong?

the code


#define dht11_pin 14 //Analog port 0 on Arduino Uno
//#define dht11_pin 54 //Analog port 0 on Arduino Mega2560
int led0040 = 2;
int led4050 = 3;
int led5060 = 4;
int led60100 = 5;
int ledgroen = 12;
int ledrood = 11;
int ledoranje = 10;

byte read_dht11_dat()
{
byte i = 0;
byte result=0;
for(i=0; i< 8; i++)
{
while (!digitalRead(dht11_pin));
delayMicroseconds(30);
if (digitalRead(dht11_pin) != 0 )
bitSet(result, 7-i);
while (digitalRead(dht11_pin));
}
return result;
}


void setup()
{
pinMode(dht11_pin, OUTPUT);
pinMode(led0040, OUTPUT);
pinMode(led4050, OUTPUT);
pinMode(led5060, OUTPUT);
pinMode(led60100, OUTPUT);
pinMode(ledoranje, OUTPUT);
pinMode(ledrood, OUTPUT);
pinMode(ledgroen, OUTPUT);
digitalWrite(dht11_pin, HIGH);
Serial.begin(9600);
Serial.println("Ready");
}

void loop()
{
byte dht11_dat[5];
byte dht11_in;
byte i;// start condition

digitalWrite(dht11_pin, LOW);
delay(18);
digitalWrite(dht11_pin, HIGH);
delayMicroseconds(1);
pinMode(dht11_pin, INPUT);
delayMicroseconds(40);

if (digitalRead(dht11_pin))
{
Serial.println("dht11 start condition 1 not met"); // wait for DHT response signal: LOW
delay(1000);
return;
}
delayMicroseconds(80);
if (!digitalRead(dht11_pin))
{
Serial.println("dht11 start condition 2 not met"); //wair for second response signal:HIGH
return;
}

delayMicroseconds(80);// now ready for data reception
for (i=0; i<5; i++)
{ dht11_dat = read_dht11_dat();} //recieved 40 bits data. Details are described in datasheet

pinMode(dht11_pin, OUTPUT);
digitalWrite(dht11_pin, HIGH);
byte dht11_check_sum = dht11_dat[0]+dht11_dat[2];// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
Serial.print("de luchtvochtigheid is = ");
Serial.print(dht11_dat[0], DEC);
Serial.print("% ");
Serial.print("temperatuur = ");
Serial.print(dht11_dat[2], DEC);
Serial.println("C ");
Serial.print(led5060);
delay(2000); //fresh time

int val = analogRead(dht11_dat[0]);
if (val > 50 && val < 60)
{
digitalWrite(led5060, HIGH);
}
if (!val > 50 && val < 60);
{
digitalWrite(led5060, LOW);
}
if (val > 60 && val < 100)
{
digitalWrite(led60100, HIGH);
}
if (val < 60 );
{
digitalWrite(led60100, LOW);
}
}

Sorry for the grammer mistakes, english is not my mother language
2012-06-02 06:23:54 Thanks synekvl for your advice!  ;D ;D My project is now working!

When I was monitoring the "val" value I saw indeed that the Arduino was reading the wrong value's.

I changed my code " int val = analogRead(dht11_dat[0]); " in  " int val = dht11_dat[0]; " and the program worked!



userHeadPic renssmal
2012-06-01 19:16:02 Thanks Vladimir for your input!  8) userHeadPic Hector
2012-06-01 09:02:32 Hi, let me allow a few comments:

1. DHT11 is digital sensor, so  you read both the temperature and humidity in digital way and store the values in array dht11_dat[] - especially humidity is in dht11_dat[0]

2. which LED will be On or Off depends on "int val"

3. you fill "val" (according to me) in wrong way using instruction  int val = analogRead(dht11_dat[0]); .... The analogRead is foreseen for reading of analog value (voltage) on relevant arduino pin. In your code you read the voltage on pin which number depends on "dht11_dat[0]" value .... so if  dht11_dat[0] is 30, arduino tries to read analog value from pin no. 30 ...

4. according to me let's int val = dht11_dat[0]; and it should go ... or let transfer byte value in dht11_dat[0] to decimal format ....


That's my observations

Cheers
Vladimir
userHeadPic synekvl