const float beta=3950;
int reading;
float v;
float temp;
int yellow=12;int green=8;int red=2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(yellow, OUTPUT);pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
reading=analogRead(A4);
v=reading*(5.0/1024.0);
temp=1/(log(1/(1023./reading-1))/beta+1.0/298.15)-273.15;
Serial.print("The temperature is");
Serial.print(temp);
Serial.println("°C");
if(temp>30) {
Serial.println("The temperature is high");
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
while (temp>30){
digitalWrite(red, HIGH);
delay(150);
digitalWrite(red, LOW);
delay(150);
reading=analogRead(A4)
temp=1/(log(1/(1023./reading-1))/beta+1.0/298.15)-273.15
}
}
else if(temp>=25){
Serial.println("The temperature is optimum");
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
while (temp>=25 && temp<30){
digitalWrite(green, HIGH);
delay(120);
digitalWrite(green, LOW);
delay(120);
reading=analogRead(A4)
}
;
}
else{
Serial.println("The temperature is low");
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
}
delay(1000);
}