Hi, i have this code working with dht11 + lcd but i need to introduce a comparators something like if humidity is lower than 40% then turn a led and with temperature the same thing like if higher than 23 C then turn another led
Code working with no comparators DHT11 + LCD
#define dht_dpin 14
#define LIGHT_SENSOR_PIN 1
#include <LiquidCrystal.h>
LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
byte bGlobalErr;
byte dht_dat[4];
int light_intensity = 0;
unsigned int flip = 0;
void setup(){
pinMode(13, OUTPUT);
lcd.begin(16, 2);
lcd.print(“Heeeeeello!”);
InitDHT();
delay(300);
delay(700);
}
void loop(){
if ( flip & 1 )
{
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
flip++;
light_intensity=analogRead(LIGHT_SENSOR_PIN);
ReadDHT();
switch (bGlobalErr) {
case 0:
lcd.setCursor(0, 0);
lcd.print("temp = ");
lcd.setCursor(7, 0);
lcd.print( dht_dat[2], DEC);
lcd.setCursor(0, 1);
if ((flip % 15) > 7 )
{
lcd.print("humidity = ");
lcd.setCursor(11, 1);
lcd.print( dht_dat[0], DEC);
} else {
lcd.print("Light = ");
lcd.setCursor(8, 1);
lcd.print( light_intensity, DEC);
}
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
delay(800);
}
void InitDHT(){
pinMode(dht_dpin,OUTPUT);
digitalWrite(dht_dpin,HIGH);
}
void ReadDHT(){
bGlobalErr=0;
byte dht_in;
byte i;
digitalWrite(dht_dpin,LOW);
delay(18);
delayMicroseconds(600);
digitalWrite(dht_dpin,HIGH);
delayMicroseconds(40);
pinMode(dht_dpin,INPUT);
delayMicroseconds(40);
dht_in=digitalRead(dht_dpin);
if(dht_in) {
bGlobalErr=1;
return;
}
delayMicroseconds(80);
dht_in=digitalRead(dht_dpin);
if(!dht_in) {
bGlobalErr=2;
return;
}
delayMicroseconds(70);
for (i=0; i<5; i++)
dht_dat = read_dht_dat();
- pinMode(dht_dpin,OUTPUT);*
- digitalWrite(dht_dpin,HIGH);*
- byte dht_check_sum =*
- dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];*
- if(dht_dat[4]!= dht_check_sum)*
- {bGlobalErr=3; }*
};
byte read_dht_dat(){ - byte i = 0;*
- byte result=0;*
- for(i=0; i< 8; i++) {*
- while(digitalRead(dht_dpin)==LOW) ; *
- delayMicroseconds(30);*
- if (digitalRead(dht_dpin)==HIGH)*
- result |=(1<<(7-i)); *
- while (digitalRead(dht_dpin)==HIGH) ;*
- }*
- return result;*
}