Hello there! I'm currently working on a project which read temperature and humidity from a DHT11 sensor, and if the temperature is less than the set value then the relay is turned on which starts the heater.
I want to display the temperature and humidity on 16x2 LCD. But, when I run the following code it shows the garbage value...I guess the problem is in the code because while the program is in the if/else condition it can't read the value(that's what I am guessing). But the serial monitor works perfectly fine. Please help!
NOTE: Relay pin connected to pin7 and here set temperature is 50C.
#include "dht.h"
#define dht_apin A0
#include <LiquidCrystal.h>
LiquidCrystal LCD(10, 9, 5, 4, 3, 2);
dht DHT;
int in1 = 7;
void setup(){
Serial.begin(9600);
pinMode(in1, OUTPUT);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor
LCD.begin(16,2); //Tell Arduino to start your 16 column 2 row LCD
}
void loop(){
DHT.read11(dht_apin);
LCD.setCursor(0,0); //Set LCD cursor to upper left corner, column 0, row 0
LCD.print("Humid = "); //Print Message on First Row
LCD.print(DHT.humidity);
LCD.print("%"); //Print Message on First Row
LCD.setCursor(0,1); //Go to 1st column(column 0) and 2nd row(row 1)
LCD.print("Temp = "); //Print Message on First Row
LCD.print(DHT.temperature);
LCD.print("C"); //Print Message on First Row
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
if( DHT.temperature<50){
digitalWrite(in1, HIGH);
}
else{
digitalWrite(in1, LOW);
}
}