const int relayPin = 7; // Relay control pin
const int potPin = A0; // Potentiometer pin
const unsigned long interval = 3600000; // 1 hour in milliseconds
unsigned long previousMillis = 0;
void setup() {
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Ensure relay is off
}
void loop() {
unsigned long currentMillis = millis();
// Check if 1 hour has passed
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; // Reset the timer
// Read the potentiometer value (0-1023) and map it to 1-30 seconds
int potValue = analogRead(potPin);
int delayTime = map(potValue, 0, 1023, 1000, 30000); // Map to 1000ms (1s) to 30000ms (30s)
digitalWrite(relayPin, HIGH); // Activate the relay
delay(delayTime); // Keep the relay activated for the mapped time
digitalWrite(relayPin, LOW); // Deactivate the relay
}
}