Not sure if i understand the code right

Really new to Arduino and did this project if found making a temp. sensor that light up one of three LEDs according to the TEMP. In the code it seems as if they should blink but they don't and this is not the first project with the same section of code and they don't blink, maybe I just don't understand what it should be doing. everything else works perfectly. I attached the sketch if that helps.

AWproject_8.ino (1.02 KB)

When I see that code, I would like to change it immediately :wink:

The temperature is measured and according to the temperature, a led is turned on, a second waiting, and the led is turned off.
So the led is actually turned off.
After that the temperate is read again.

Reading the temperature and calculating the degrees in Celsius is so fast, you won't see that the led is turned off.
If the temperature is the same, the same led is turned on again. I might seem that the led just stays on. You can test it with the high speed camera or oscilloscope that the led turnes off for a few milliseconds.

The result of the sketch is that the temperature is tested only once a second.

Next step: Can you write the temperature to the serial monitor ? So that you can see the real temperature on the computer.

void loop()
{
  // read the temperature sensor and conver the result to degrees celsius
  sensor = analogRead(0);

Add a delay 1st thing and the LEDs will blink

void loop()
{
  delay(1000);
  // read the temperature sensor and conver the result to degrees celsius
  sensor = analogRead(0);

This is just a Workaround to blink, the sketch can be improved quite a bit.