The following article explains methods to create a basic 2-step Arduino programmable timer circuit that can be used to separately alter the ON and OFF timings of an electrical load.
You may easily do this by making a small change to the program code, for instance, if you want a light to stay ON for 24 hours and OFF for 2 hours. Similarly, by altering the code suitably, you may change the output timings to any other desired set of time intervals.
To begin the timer function in accordance with your particular application requirements, simply build and upload the following code to your Arduino board.
Program Code
void setup(){
pinMode(13, OUTPUT);
}
void loop(){
digitalWrite(13, HIGH);
delay(86400000);
digitalWrite(13, LOW);
delay(3600000);
}
The output ON and OFF delay time intervals, in milliseconds, are determined by the lines delay(86400000); and delay(3600000); in the sample code above. In this case, 3600000 shows a one-hour delay, whereas 86400000 milliseconds represents 24 hours.
To obtain the necessary output delays, you can alter these two variables to suit your preferences.
The Arduino will keep on alternating between the two-step ON/OFF timing cycle soon after it has been configured and switched on, as long as the system continues to get power.
Circuit Diagram
The following diagram shows the entire circuit schematic as well as the Arduino links:
Creating an Arduino One-Shot Timer Circuit
The code listed below can be used if you want the timer to be a one-shot kind that will turn off forever after the predetermined delay rather than looping over the two-step timer:
int led = 13; // Pin 13 has an LED connected on most Arduino boards.
unsigned long DELAY_TIME = 10000; // 10 sec
unsigned long delayStart = 0; // the time the delay started
bool delayRunning = false; // true if still waiting for delay to finish
void setup() {
pinMode(led, OUTPUT); // initialize the digital pin as an output.
digitalWrite(led, HIGH); // turn led on
// start delay
delayStart = millis();
delayRunning = true;
}
void loop() {
// check if delay has timed out
if (delayRunning && ((millis() - delayStart) >= DELAY_TIME)) {
delayRunning = false; // finished delay -- single shot, once only
digitalWrite(led, LOW); // turn led off
}
}
You may choose this circuit if you're looking for a discreetly constructed version of the same programmable timer circuit.
Bill of Materials for the Arduino Programmable Timer Circuit
- Arduino UNO Board = 1
- IC 7809 = 1
- BC547 = 1
- 1N4007 Diode = 1
- 10k 1/4 w resistor = 1
- Relay 12V/400 ohm/SPDT/5 amp = 1
- 12V AC to DC Adapter = 1
Leave a Reply