Open cksajil opened 3 months ago
const int relayPin = 3; // Pin connected to the relay module
void setup() {
pinMode(rainSensorPin, INPUT);
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Ensure the relay is initially off
}
void loop() {
int sensorValue = digitalRead(rainSensorPin);
if (sensorValue == LOW) { // Rain detected
digitalWrite(relayPin, HIGH); // Turn on relay (and thus the Raspberry Pi)
} else {
// Add delay functionality so that the Pi turns off itself based on inference values after some time
digitalWrite(relayPin, LOW); // Turn off relay (and thus the Raspberry Pi)
}
delay(1000); // Check every second
}