Novice Question about code for my quick read thermometer.

Hi, I’ve just recently started learning to use the Arduino Uno and am working on building a quick read thermometer using 4 LEDs to indicate temperatures are within a certain range. I’m having problems with an error saying that " ‘sensor’ was not declared in this scope. The part that’s highlighted in the sketch is bold and colored red below. I’m unsure how to resolve this issue.

#define HOT 2 // red LED
#define WARM 5 // yellow LED
#define COOL 8 // green LED
#define COLD 11// blue LED
#define del 1000// delay time

float voltage = 0;
float celsius = 0;
float hotTemp = 26;
float warmTemp= 24;
float coolTemp= 22;
float coldTemp= 20;

void setup()
{
pinMode(HOT, OUTPUT); // red LED
pinMode(WARM, OUTPUT); // yellow LED
pinMode(COOL, OUTPUT); // green LED
pinMode(COLD, OUTPUT); // blue LED

digitalWrite(HOT, HIGH);
digitalWrite(WARM, HIGH);
digitalWrite(COOL, HIGH);
digitalWrite(COLD, HIGH);
delay(del);
digitalWrite(HOT, LOW);
delay(del);
digitalWrite(WARM, LOW);
delay(del);
digitalWrite(COOL, LOW);
delay(del);
digitalWrite(COLD, LOW);
delay(del);
}
void loop()
{
// read the temperature sensor and convert the result to degrees Celsius
sensor = analogRead(0);
voltage = (sensor*5000)/1024; // convert raw sensor value to millivolts
voltage = voltage-500; // remove voltage offset
celsius = voltage/10; // convert millivolts to Celsius
}

// act on temperature range.
if ( celsius < coldTemp )
{
digitalWrite(COLD, HIGH);
delay(del);
digitalWrite(COLD, LOW);
}
else if ( celsius > coldTemp && celsius <= coolTemp)
{
digitalWrite(COOL, HIGH);
delay(del)
digitalWrite(COOL, LOW);
}
else if ( celsius > coolTemp && celsius <= warmTemp )
{
digitalWrite(WARM, HIGH);
delay(del);
digitalWrite(WARM, LOW);
}
else
{
//celcius is greater than hot temp
digitalWrite(HOT, HIGH);
delay(del);
digitalWrite(HOT, LOW);
}
}

You haven't declared sensor to be a variable anywhere.

See at the top where you have

float voltage = 0;

That declared a variable named voltage with the type float and an initial value of 0. That "creates" the variable if you will. But nowhere have you done that for sensor.

You either need to put it up there with the others if you want it to be at global scope, or declare it in loop if you want it to be local to loop.