#include <LiquidCrystal_I2C.h>
const int relayPin = 7;
const int relayPin2 = 6;
void setup() {
// Start serial communication
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
pinMode(relayPin2, OUTPUT);
}
void loop() {
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature in C: ");
Serial.print(celsius);
Serial.print(" ");
if(celsius > 30 & celsius < 50){
digitalWrite(relayPin, HIGH);
digitalWrite(relayPin2, LOW);
Serial.println("Relay1 ON"); // Print to serial monitor
}
else if(celsius>50){
digitalWrite(relayPin, LOW);
digitalWrite(relayPin2, HIGH);
Serial.println("Relay2 ON");
}
else{
digitalWrite(relayPin, LOW);
digitalWrite(relayPin2, LOW);
Serial.println("Both Relays OFF");
}
// Wait for a second before the next reading
delay(1000);
}