I immediately had the same question, but ended up figuring it out. I also added a fourth LED and the addition of a buzzer so that when the fourth LED lights up the buzzer goes off. The kids really get a kick out of this because the buzzer adds and extra element of excitement. I told them if they are really love struck then the buzzer will go off. I was surprised how easy it was to set up the buzzer. I set it up on pin 6 in this variation:
//Addition of 4th LED and a buzzer to go off with 4th LED
*/
// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 78;
void setup(){
// open a serial connection to display values
Serial.begin(9600);
// set the LED pins as outputs
// the for() loop saves some extra coding
for(int pinNumber = 2; pinNumber<6; pinNumber++){
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop(){
// read the value on AnalogIn pin 0
// and store it in a variable
int sensorVal = analogRead(sensorPin);
//define alarm pitch
// send the 10-bit sensor value out the serial port
Serial.print("sensor Value: ");
Serial.print(sensorVal);
// convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
// Send the voltage level out the Serial port
Serial.print(", Volts: ");
Serial.print(voltage);
// convert the voltage to temperature in degrees C
// the sensor changes 10 mV per degree
// the datasheet says there's a 500 mV offset
// ((volatge - 500mV) times 100)
Serial.print(", degrees C: ");
float temperature = (voltage - .5) * 100;
Serial.print(temperature);
float degF = (temperature*9/5+32);
Serial.print(", degrees F: ");
Serial.println(degF);
// if the current temperature is lower than the baseline
// turn off all LEDs
if(degF < baselineTemp){
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} // if the temperature rises 2-4 degrees, turn an LED on
else if(degF >= baselineTemp +2 && degF < baselineTemp+4){
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} // if the temperature rises 4-6 degrees, turn a second LED on
else if(degF >= baselineTemp+4 && degF < baselineTemp+6){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} // if the temperature rises more than 6 degrees, turn all LEDs on
else if(degF >= baselineTemp+6 && degF < baselineTemp+8){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
} // if the temperature rises more than 6 degrees, turn all LEDs on and sends tone to speaker
else if(degF >= baselineTemp+8){
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
tone(6,2000,50);
}
delay(10);
}