Go Down

Topic: Not sure if i understand the code right (Read 823 times) previous topic - next topic

11Trevor11

Jul 16, 2014, 03:57 pm Last Edit: Jul 16, 2014, 04:06 pm by 11Trevor11 Reason: 1
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.


Peter_n

When I see that code, I would like to change it immediately  ;)

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.
http://arduino.cc/en/Serial/Println

steinie44

Code: [Select]
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
Code: [Select]
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.

Go Up