// Pin definition
const int outputPin = 12; // Change to the desired pin
// Time intervals (in milliseconds)
const unsigned long onTime = 5000; // Time in ON state (5 seconds)
const unsigned long offTime = 3000; // Time in OFF state (3 seconds)
// Variables to track the timing
unsigned long previousMillis = 0;
bool outputState = true; // Initially the output is ON
void setup() {
pinMode(outputPin, OUTPUT); // Set the pin as an output
digitalWrite(outputPin, HIGH); // Start in ON state
}
void loop() {
unsigned long currentMillis = millis();
if (outputState) {
// If output is ON, check if it's time to turn OFF
if (currentMillis - previousMillis >= onTime) {
previousMillis = currentMillis; // Reset the timer
outputState = false; // Change state to OFF
digitalWrite(outputPin, LOW); // Turn OFF the output
}
} else {
// If output is OFF, check if it's time to turn ON
if (currentMillis - previousMillis >= offTime) {
previousMillis = currentMillis; // Reset the timer
outputState = true; // Change state to ON
digitalWrite(outputPin, HIGH); // Turn ON the output
}
}
}