If/else statement with functions.

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);  
}

digitalWrite(redLed=HIGH); Didn't the compiler complain?

mirr0r:
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.

if (tempC<=18) {
digitalWrite(blueLed=HIGH);

Welcome to the Forum and I have added one karma for using code tags. Some advice for getting best results from the members here, you need to answer these questions in your first post:

Did the code compile?
If not what were the error messages?
What were you expecting to happen when you ran the code?
What did happen?

It helps to have tested the basics, if you look in the Examples section of the IDE program there is a lot of helpful info on using the things like inputs and outputs.

Syntax for digitalWrite() is

digitaWrite(pin, state);

Good job using code tags on your first post.

In the future, if you have compile errors, post the entire error message (in code tags).

The Arduino reference is a valuable resource.

Ah, such simple fix.

I will make sure to include the compiler error message when I post next time. Sorry!