Site icon Circuit Ideas for You

Arduino 2-Step Programmable Timer Circuit with Independent Output Delay Adjustment

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:

ComponentQuantity
Arduino Uno Board1
IC 78091
Transistor BC5471
Resistor 10k 1/4 watt1
SPDT 12V Relay1
Diode 1N40071
Connector to Arduino1

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:

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.

References:

How to generate two signals with time delay?

Exit mobile version