What am I missing in my temperature code?

So, I started on my first little project without a tutorial. Or actually, with one, but one that I have adapted to do a little more.

I used the standard oomlout tutorial that came with my Arduino kit, but expanded it to not only show the temperature in the serial monitor, but also by using 6 LED's (2 blue, 2 green, 2 red) that should go on when specific values are met or surpassed.

Should be pretty easy, I thought. But all the LED's turn on. I got the temperature reading in the serial monitor displaying a value of a bit under 22 degrees, which should mean the two blue LED's and 1 green LED should light up.

Seeing the LED's actually light up and the temp. reading is correct, my hardware should be good.

Below is the code I made/adapted. Any help and explanation why it isn't working would be highly appreciated. I'm learning pretty fast (the last time I did any programming is over 10 years ago but I'm picking it up quite well) so I'll be only asking this once :)

Thanks in advance!

/*   Borrowed most of the code form the ARDX experimenters kit tutorials by oomlout
 *   editted for making a visual temperature reading with 6 LEDS
 */

//TMP36 Pin Variables
int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade 
                        //(500 mV offset) to make negative temperatures an option
int blue1 = 7;          //LED for cold
int blue2 = 6;          //LED for less cold
int green1 = 5;         //LED for medium cold
int green2 = 4;         //LED for medium warm
int red1 = 3;           //LED for warm
int red2 = 2;           //LED for really warm

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the copmuter
                       //to view the result open the serial monitor 
                       //last button beneath the file bar (looks like a box with an antenae)
  pinMode(blue1, OUTPUT);  //setting all the pins as output
  pinMode(blue2, OUTPUT);  
  pinMode(green1, OUTPUT);
  pinMode(green2, OUTPUT);
  pinMode(red1, OUTPUT);
  pinMode(red2, OUTPUT);
}

void loop()                     // run over and over again
{
 float temperature = getVoltage(temperaturePin);  //getting the voltage reading from the temperature sensor
 float temperature1 = (temperature - .5) * 100;          //converting from 10 mv per degree wit 500 mV offset
                                                  //to degrees ((volatge - 500mV) times 100)
 if (temperature1 >= 10.00)                  //using the code below to create the visual thermometer
   digitalWrite(blue1, HIGH);
 if (temperature1 >= 15.00)
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
 if (temperature1 >= 20.00)
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
   digitalWrite(green1, HIGH);
 if (temperature1 >= 25.00)
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
   digitalWrite(green1, HIGH);
   digitalWrite(green2, HIGH);
 if (temperature1 >= 27.00)
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
   digitalWrite(green1, HIGH);
   digitalWrite(green2, HIGH);
   digitalWrite(red1, HIGH);
 if (temperature1 >= 30.00)
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
   digitalWrite(green1, HIGH);
   digitalWrite(green2, HIGH);
   digitalWrite(red1, HIGH);
   digitalWrite(red2, HIGH);
   Serial.println(temperature1);                     //printing the result
 delay(1000);                                     //waiting a second
}

/*
 * getVoltage() - returns the voltage on the analog input defined by
 * pin
 */
float getVoltage(int pin){
 return (analogRead(pin) * .004882814); //converting from a 0 to 1024 digital range
                                        // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}

Are you a python programmer by any chance?

 if (temperature1 >= 10.00)                  //using the code below to create the visual thermometer
 {
   digitalWrite(blue1, HIGH);
 }
 if (temperature1 >= 15.00)
 {
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
 }
 if (temperature1 >= 20.00)
 {
   digitalWrite(blue1, HIGH);
   digitalWrite(blue2, HIGH);
   digitalWrite(green1, HIGH);
 }

You need curly braces around the code that is to be conditionally executed.

Without them, only the first line after the if statement is conditionally executed. The rest are unconditionally executed, indentation notwithstanding.

I knew it had to be something STUPID. Thanks :)

No I'm not a python programming, I did some Pascal in school and with that I forgot the most stupid things as well so I'm used to it.

I asked about the python programming because in python, indenting IS how you define a block of code. Your python code MUST be properly indented, or it will throw all kinds of errors that seem to make no sense.

Sounds real inconvenient to me... I jsut use indents to keep it all nice and tidy, to see where a certain statement begins and ends.

All works great now, it also turns the pins low when the temp. drops below a value so I'm a happy newb :)

Just a side note. That strict INDENTING aspect of PYTHON is why it never caught on with me. It's just not intuitive after working with C.

mmh, >=10 is 10,11, and 20 or 100 also.

Your if condition overlaps.

You have to divide events better, to get it work.
Maybe <> or case.

Greetings ChrisS

Hi ChrisS,

Well, actualy it already works, what you are saying is exactly what it is intended to do.

The LED’s are inserted into my breadboard like this:

[g][g][r][r]
b being blue, g being green and r being red.
So let’s say the room temperature is 25 degrees and the second green LED is set to 23 and the first red to 27, it would light up:
[g][g]
Like a normal, old school mercury or alcohol thermometer.
Lighting just 1 LED is boring, and we all know it :wink:

Hah, youre right...

ahm, well... then you should have a look to Rainbowduino... but programming an get things done is hardly with Rainbowduino... (i think...).

Go on... first steps are done... great job!

Greetings ChrisS