const int redBlub=8;
const int ntc=A0;
void setup() {
Serial.begin(9600);
pinMode(redBlub, OUTPUT);
}
void loop() {
//Read the values from pin A0 where Temperature Sensor is connected
int analogValue=analogRead(ntc);
//Called user defined Function
int temp= checkTemp(analogValue);
Serial.print("Temperature is ");
Serial.print(temp);
Serial.println("^C");
//Called user defined Function
onOffBulb(temp);
delay(5000);
}
//In this function we convert the values to temperature
//that are come from sensor
int checkTemp(double analogValue){
int resistance=(1000.0/((1023.0/analogValue)-1.0));
int temp=(1.0/((log(resistance/10000.0)/3950.0)+(1.0/298.15)))-273.15;
return temp;
}
//In this function, On Off bulb wrt to temperature
void onOffBulb(double temp){
if(temp>500){
digitalWrite(redBlub,HIGH);
}
else{
digitalWrite(redBlub,LOW);
}
}