An Arduino microcontroller is used in this project to create a versatile timer.
Unlike a traditional two step timer with separate outputs, this circuit focuses on a single output that cycles through two distinct states, each of which has an adjustable delay to allow for flexibility in controlling different applications.
#include <Arduino.h>
// Define pins
const int outputPin = 9;
const int relayDriverPin = 3; // Adjust for your relay driver
// Define delay values (in milliseconds)
unsigned long delayTime1 = 5000;
unsigned long delayTime2 = 3000;
// Variables to track timer states
unsigned long previousMillis = 0;
int outputState = LOW;
void setup() {
pinMode(outputPin, OUTPUT);
pinMode(relayDriverPin, OUTPUT);
// Initialize relay driver (if necessary)
// ...
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= delayTime1 + delayTime2) {
previousMillis = currentMillis;
outputState = !outputState;
}
digitalWrite(outputPin, outputState);
digitalWrite(relayDriverPin, outputState); // Control relay if used
}
Circuit Working:
Parts List:
Component | Quantity |
---|---|
Arduino Uno Board | 1 |
IC 7809 | 1 |
Transistor BC547 | 1 |
Resistor 10k 1/4 watt | 1 |
SPDT 12V Relay | 1 |
Diode 1N4007 | 1 |
Connector to Arduino | 1 |
The Arduino board configures the output pin and, if needed the relay driver pin.
The loop() method monitors the time since the previous state change.
If the total elapsed time equals or exceeds the sum of both delay times, the output state is reversed (HIGH to LOW or LOW to HIGH).
The output pin and, if applicable the relay driver pin are set based on the current output state.
Description
To generate a sequential two-step output, the code makes use of a single output pin and one timer.
The output state variable rotates between HIGH and LOW.
The overall delay for one cycle is the combination of delayTime1 and delayTime2.
How to adjust the 2-step programmable timer
The start time of each delay period is tracked using two different variables, previousMillis1 and previousMillis2.
The code examines the elapsed time for each delay individually.
When the initial delay (delayTime1) ends, the output state changes to HIGH.
When the second delay (delayTime2) ends, the output state is reset to LOW.
How to Build a Transistor Relay Driver Stage with Arduino:
- The Arduino digital pin 3 is connected to the transistors base via a resistor 10k for current limiting.
- The transistors collector is connected to one terminal of the relay coil and other other terminal of relay coil is connected to positive supply +12V.
- Transistor emitter is connected to ground.
- The Relay Common Terminal is connected to the load
- Relay normally closed (NC) or normally open (NO) contacts is determined when the load is connected or disconnected.
- Connect a diode 1N4007 between the terminals of 12V relay coil
- Connect a regulated IC 7809 to provide a regulated 9V DC to the arduino board.
Conclusion
This Arduino based circuit offers a versatile and efficient way to build a two-step timer with a single output.
By altering the delay timings, you may tailor the on and off times to specific applications.
The extra relay driver increases the circuits ability to control higher power loads.
Leave a Reply