Hello,
I'm having this little home-project that I want to make, but somehow I get some errors in my code.
What I want to do is to read the temperature in the room and print it on an LCD screen. This works fine.
However, if the temperature is below 18 degrees celsius or above 24 degrees celsius, a LED should light up.
This is where it somehow gets tricky and I might have done some errors.
Hoping someone could give me some advice on what's wrong in my code
//TMP36 Pin Variables
int sensorPin = 0;
const int redLed=8;
const int blueLed=9;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode (redLed, OUTPUT);
pinMode (blueLed, OUTPUT);
lcd.begin(16, 2);
}
void loop()
{
int reading = analogRead(sensorPin);
float voltage = reading * 5.0;
voltage /= 1024.0;
float tempC = (voltage - 0.5) * 100 ;
lcd.setCursor(0, 1);
lcd.print(tempC);
lcd.print(" Celsius");
if (tempC<=18) {
digitalWrite(blueLed=HIGH);
}
else {
digitalWrite(blueLed=LOW);
}
if (tempC>=24) {
digitalWrite(redLed=HIGH);
}
else {
digitalWrite(redLed=LOW);
}
delay(1000);
}