const int motionSensor = 2; // Motion sensor pin const int relayPin = 3; // Digital pin connected to the relay module const int pumpOnTime = 1000; // Pump on time in milliseconds (1 second) unsigned long pumpStartTime = 0; // Variable to store the pump start time bool pumpIsRunning = false; // Flag to indicate if the pump is running void setup() { pinMode(motionSensor, INPUT); pinMode(relayPin, OUTPUT); } void loop() { int motionDetected = digitalRead(motionSensor); if (motionDetected == HIGH && !pumpIsRunning) { // Motion detected and pump is not already running pumpStartTime = millis(); digitalWrite(relayPin, HIGH); // Turn on the relay pumpIsRunning = true; } if (pumpIsRunning && millis() - pumpStartTime >= pumpOnTime) { digitalWrite(relayPin, LOW); // Turn off the relay pumpIsRunning = false; // Reset the pump running flag } }