Haveyoueverheartoflayout?Indentation?
pres ctrl+T and see how that looks ![]()
Next, how did you connect those LEDs? I see nothing wrong (at least not with that) in the code.
After some rework:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte BlueLedPin = 8;
const byte RedLedPin = 9;
const byte SensorPin = A0;
void setup(){
lcd.begin(16, 2);
pinMode(BlueLedPin, OUTPUT);
//digitalWrite(Blue, LOW); //the default
pinMode(RedLedPin, OUTPUT);
//digitalWrite(Red, LOW); //the default
//pinMode(sensorPin, INPUT); //only applies to the digital mode
Serial.begin(9600);
}
void loop(){
unsigned int reading = analogRead(sensorPin);
float temperatureC = (5.0 * reading * 100.0) / 1024;
Serial.print(temperatureC);
if (temperatureC >= 20) {
digitalWrite(RedLedPin, HIGH);
digitalWrite(BlueLedPin, LOW);
}
else{
digitalWrite(BlueLedPin, HIGH);
digitalWrite(RedLedPin, LOW);
}
lcd.setCursor(0, 0);
lcd.print("TEMP: ");
lcd.print(temperatureC);
lcd.print(" C");
delay(500);
}
Also note, a float does NOT simply mean a decimal point and is pretty hard for a Uno to do.