// Define the relay pin connected to the solenoid valve
const int relayPin = 2;
// Setup function runs once when you press reset or power the board
void setup() {
// Initialize the relay pin as an output
pinMode(relayPin, OUTPUT);
// Initially turn off the solenoid valve (relay in OFF state)
digitalWrite(relayPin, LOW);
}
// Main loop function runs continuously after setup()
void loop() {
// Example logic to open the water flow for 10 seconds every minute
openWaterFlow(10000); // Open water flow for 10 seconds
delay(50000); // Wait for the rest of the minute (50 seconds)
}
// Function to open the water flow
void openWaterFlow(unsigned long duration) {
// Turn on the relay to open the solenoid valve
digitalWrite(relayPin, HIGH);
// Keep the valve open for the specified duration
delay(duration);
// Turn off the relay to close the solenoid valve
digitalWrite(relayPin, LOW);
}