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
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




Logged

