int relay = 2; // Relay control pin
int temp = 35; // Temperature sensor analog pin
int sensor1 = 0; // Variable to store the analog reading
int pushButton = 4; // Push button GPIO pin
void setup() {
Serial.begin(9600); // Start serial communication
pinMode(relay, OUTPUT); // Set relay pin as output
pinMode(pushButton, INPUT); // Set push button pin as input
}
void loop() {
sensor1 = analogRead(temp); // Read the analog temperature sensor
int buttonState = digitalRead(pushButton); // Read the push button state
// Print sensor status
Serial.print("status = ");
Serial.println(sensor1);
delay(500); // Delay for half a second
// Turn on the relay if the button is pressed and sensor value is below a threshold
if (buttonState == HIGH && sensor1 > 1100) {
digitalWrite(relay, HIGH); // Turn on the relay
} else if (sensor1 > 1100) {
digitalWrite(relay, LOW); // Turn off the relay if the temperature exceeds the threshold
} else {
digitalWrite(relay, LOW); // Keep the relay off otherwise
}
}