const int relayPin = 8; // Define the pin to which the relay module is connected
const unsigned long onDuration = 5000; // Duration in milliseconds (5 seconds in this example)
void setup() {
pinMode(relayPin, OUTPUT); // Set the relay pin as an output
}
void loop() {
// Your condition here
bool conditionIsTrue = true; // Replace this with your actual condition
if (conditionIsTrue) {
digitalWrite(relayPin, HIGH); // Turn the relay ON
delay(onDuration); // Wait for the specified duration
digitalWrite(relayPin, LOW); // Turn the relay OFF
}
// Your other loop code here
}