int lm35_pin = A1; /* LM35 O/P pin */
int fan =3;
void setup()
{
Serial.begin(9600);
pinMode(fan,OUTPUT);
pinMode(lm35_pin ,INPUT);
}
void loop()
{
int temp_adc_val;
float temp_val;
temp_adc_val = analogRead(lm35_pin); /* Read Temperature */
temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent voltage */
temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print(" Degree Celsius\n");
delay(1000);
if(temp_val > 50)
{
digitalWrite(fan, HIGH);
}
else
{
digitalWrite(fan, LOW);
}
}