Trigger relay with Temperature threshold from analoginput?

Hi,

I have been dabbing with some LM35 temperature sensors and I found a website and code to print the ambient in Celsius:

I would like to trigger a relay when temp exceeds say > 25 Degrees C, any ideas??

Jon.

Code:

float temp;
int tempPin = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.println(temp);
delay(1000);
}

Very simple. Make an if statement. If your code works as you say it does, something like this would suffice:

if(temp > 25){

}

The code to control the relay goes in the middle. I'm guessing you would have to give a digitalRead(pin, HIGH) to wherever the relay is?

Cool, thanks Angelo, with your help I compiled this:

====CODE:====

float temp;
int tempPin = 4;

void setup()
{
Serial.begin(9600);
pinMode(7, OUTPUT);
}

void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.println(temp);
if (temp > 25) {digitalWrite(7, HIGH);
}
else {
digitalWrite(7, LOW);
}
delay(1000);
}

======/CODE/=======

IF the temperature exceeds 25 Degrees C it will +5v (HIGH) Digital Pin 7, triggering a relay. When the temperature is below that it will apply 0V.