• Skip to main content
  • Skip to primary sidebar

Homemade Circuit Projects

Get free circuit help 24/7

Circuits for Beginners | Basic Circuits | LED Driver | Hobby Circuits | Transistor Circuits

New-Projects | Privacy Policy | About us | Contact | Disclaimer | Copyright | Videos

You are here: Home / Arduino Engineering Projects / Arduino 2-Step Programmable Timer Circuit

Arduino 2-Step Programmable Timer Circuit

Last Updated on June 9, 2020 by Swagatam 23 Comments

ask questions through comments

In this article we learn how to make a simple 2-step Arduino programmable timer circuit, which can be used to switch an electrical load ON/OFF with independently adjustable ON and OFF timings.

For example if you want a light to remain ON for 24 hours and OFF for 2 hours, you can simply do this through a quick modification in the program code. In the same way you can customize the output timings to any other desired set of time intervals by changing the code appropriately.

You just have to compile and upload the following code to your Arduino board and start the timer function as per your specific application needs.

Program Code

void setup(){
pinMode(13, OUTPUT);
}
void loop(){

digitalWrite(13, HIGH);
delay(86400000);
digitalWrite(13, LOW);
delay(3600000);
}

In the above example code the lines delay(86400000); and delay(3600000); determine the output ON and OFF delay time intervals respectively, in milliseconds. Here, the figure 86400000 milliseconds corresponds to 24 hours, while 3600000 exhibits 1 hour delay.

You can customize these two values as per your personal preference to get the required output delays.

Once setup and powered, the Arduino will continue switching between the two step ON/OFF timing sequence. as long as power remains applied to the system.

Circuit Diagram

The complete circuit diagram along with the Arduino connections can be witnessed in the following diagram:

Arduino One-Shot Timer Circuit

If you don't want the timer to loop through the two step timer, instead want the timer to be a one-shot type, which will switch OFF permanently after the set delay, you can apply the following code:



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
  }
}

If you want a discretely designed version of an identical programmable timer circuit, you can opt for this circuit

Parts Required 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
get free help for circuit diagrams

You'll also like:

  • 1.  Simple Delay Timer Circuits Explained
  • 2.  Password Security Lock Circuit Using 4×4 Keypad and Arduino
  • 3.  Microcontroller Basics Explored
  • 4.  Make this Simple Weather Station Project for Homes and Offices
  • 5.  Ultraviolet (UV) Sanitizer Circuit for Disinfecting Home Materials
  • 6.  Arduino Pure Sine Wave Inverter Circuit with Full Program Code

About Swagatam

I am an electronic engineer (dipIETE ), hobbyist, inventor, schematic/PCB designer, manufacturer. I am also the founder of the website: https://www.homemade-circuits.com/, where I love sharing my innovative circuit ideas and tutorials.
If you have any circuit related query, you may interact through comments, I'll be most happy to help!

Subscribe for the Latest Posts


 

Reader Interactions

Comments

    Have Questions? Please post your comments below for quick replies! Comments should be related to the above artcile Cancel reply

    Your email address will not be published. Required fields are marked *

  1. Todd Maurer says

    January 20, 2022 at 7:31 pm

    Swagatam,
    Thanks for posting this. I’d like to add a momentary button to start the timer cycle, how would this be done?

    Thanks,
    Todd

    Reply
    • Swagatam says

      January 20, 2022 at 8:20 pm

      Hello Todd, I am not an Arduino expert, so it may be difficult for me to solve this query.

      Reply
  2. Bjarne Sønderskov Nielsen says

    January 19, 2022 at 5:23 pm

    Thank You for most speedy reply- can I use a potentiometer for adjusting welding time- pause isn¨t’nt so crusial- welding in “spots” isnt always easy to control during the welding proces- maybe i can as experimetnally use a switch for differenting capasitors and a potmeter ,replacing R 2 – to a potentiometer some above the resistance for the fittet resistor- slope value- hoW many ohms for a middelvalue- about 5 sec??

    Reply
    • Swagatam says

      January 19, 2022 at 6:08 pm

      You are welcome! Yes R2 can be replaced with a pot, for example a 500K pot, and C2 with a 220uF capacitor. Mke sure to put another fixed resistor such as 10K in series with the pot R2.

      The circuit will function in the following manner: When power is switched ON, initially the relay will be OFF, and the LED will be OFF. After some delay the relay will switch ON, and then after some more delay the LED will switch ON and reset the relay to OFF, and the cycle will repeat.

      Reply
  3. Bjarne Sønderskov Nielsen says

    January 19, 2022 at 7:50 am

    I’m loving your site with nonsensfree smaal circuit , we all are able to complete. Maybe You can help me too-
    I’m repairing my Welder , a nameless nearly 50 years old co2- welder, app. 250A. By mistake an bad luck i burned the motor for weldingmateriale- core,0,8 or 1mm thiknes- I have chosen to rebuild this velder, when a welder in same quality is pretty expencive- here in DK app 1000 us dollar, and i need a sort of a timer for
    sequence velding, where is is velding for 5 sec and then pause for 5 sec- both period must be adjusteable from maybe 2-10 sec for the welding and maybe same for pause- it must drive a relay, which wil be the contact to the other circuit- and both periodes must be controlled with a potentiometer-hole controlling system is driven by 24 v DC- and of cource- as simpel as possible anit will be built on a trial bord vith velding -dots.
    yours cincerrely Bjarne S. Nielsen

    Reply
    • Swagatam says

      January 19, 2022 at 4:48 pm

      Thank you for liking this site! You can build and try the following transistorized two step timer circuit for your specific application:

      R2 and C2 on both the stages can be adjusted for getting any desired timing for the relay ON/OFF sequencing

      two step transistorized timer circuit fully adjustable

      Reply
  4. Денис says

    January 1, 2022 at 10:01 pm

    Добрый день. Можете помочь со скетчем таймера на ардуино или атини?
    Таймер должен включать и выключать нагрузку на определенное время два раза в день.

    Reply
  5. Jix says

    October 6, 2021 at 6:46 pm

    Can I use arduino nano instead of arduino nano?

    Reply
    • Swagatam says

      October 6, 2021 at 8:01 pm

      Yes you can use it…

      Reply
  6. Wilson says

    March 22, 2021 at 11:45 am

    Hello, sorry if this may seem off topick, am trying to make a inverter using arduino uno, am not good in cording so i generated a code from an android app, the inverter seem to be working ok, the only problem i have is how to give it feedback so the output voltage can be stable.
    below is the generated code

    #include

    #define HO1 12
    #define LO1 11
    #define HO2 10
    #define LO2 9
    int f_sin=50;
    int f_pwm=10000;
    float sin_buffer[200];
    float sampling_tot,pwm_period,sin_period,us=1000000;
    int count=0,flag=0,Ampli=1000;

    void setup() {
    Serial.begin(9600);
    pinMode(HO1,OUTPUT);
    pinMode(LO1,OUTPUT);
    pwm_period=(us*1)/f_pwm;
    sin_period=(us*1)/f_sin;
    sampling_tot=(sin_period/pwm_period)/2.0;
    Serial.println(pwm_period);
    Serial.println(sin_period);
    Serial.println(sampling_tot);
    for(int deg=0;deg(sampling_tot) && flag==1 ){
    flag=0;
    count=1;
    TCCR1A=0b10110000;
    }
    if(count>(sampling_tot) && flag==0 ){
    flag=1;
    count=1;
    TCCR1A=0b11100000;
    }
    count++;
    if(flag==0){
    Timer1.pwm(HO2,sin_buffer[count]* Ampli);
    Timer1.pwm(LO2,sin_buffer[count]* Ampli);
    digitalWrite(HO1,HIGH);
    digitalWrite(LO1,LOW);
    }
    if(flag==1){
    Timer1.pwm(HO2,sin_buffer[count]* Ampli);
    Timer1.pwm(LO2,sin_buffer[count]* Ampli);
    digitalWrite(HO1,LOW);
    digitalWrite(LO1,HIGH);
    }
    }

    Reply
    • Swagatam says

      March 22, 2021 at 8:13 pm

      Hello, if the inverter is working that means the code should be fine too…sorry, just like you I am too not good with coding stuff, so won’t be able to help you much in this regard.

      Reply
  7. Sunshine says

    February 7, 2021 at 11:03 pm

    Good day sir…happy Sunday…please I want be familiarize with arduino system..please help..how do I give a command it or program it? Thanks Engr.

    Reply
    • Swagatam says

      February 8, 2021 at 8:00 am

      Hello Sunshine, You can read the following article to get some basic tips regarding Arduino programming:

      Learning Basic Arduino Programming – Tutorial for the Newcomers

      Reply
  8. Sanjiv Kumar Mohbansi says

    August 22, 2020 at 1:15 pm

    Dear Sir;
    I am in need of Arduino controlled reverse and forward relay controlled project details.
    Following are the steps:-
    1. After power ON, only after pushing ON push button (PB1), after 15 seconds, both relay1 (Motor1) and relay2 (Motor2) will start automatically simultaneously and stopped simultaneously, by pushing OFF push button (PB2) .
    2. Relay3 (Motor3) will remain stopped, unless and until we press direction change push button (PB3).
    3. When we will press PB3, relay2 stops and relay3 will ON after a timing gap of 15 seconds. Both relay2 and relay3 are interlocked. And stopped through PB2.
    4. Along with PB3, there is also provision for a proximity switch (PB3 OR proximity switch) to change direction as per step number 3.
    5. All three relay1, relay2 and relay3 will start with PB1 and stopped with PB2.
    6. Relay1 is controlled with PB1 and PB2 only.
    Thanks in advance for your kind guidance and support.
    Sanjiv Mohbansi
    sbmohbansi@gmail.com

    Reply
    • Swagatam says

      August 22, 2020 at 5:35 pm

      Dear Sanjiv, I am not good with Arduino coding, so won’t be able to help you with this project.

      Reply
      • Sanjiv says

        August 26, 2020 at 6:14 pm

        Thank you Sir for your kind reply!!
        Else as per your view, is there any option without using Arduino??
        Awaiting your suggestion.
        Thanks in advance!!

        Reply
        • Swagatam says

          August 27, 2020 at 3:04 pm

          Yes it is possible using a simple flip flop circuit

          Reply
  9. Dan says

    June 10, 2020 at 5:37 am

    Please Sir can you elaborate on how to load a bootloader to ATMEGA 328?
    Thank you

    Reply
    • Swagatam says

      June 10, 2020 at 10:38 am

      Sorry Dan, I have no idea about it.

      Reply
  10. Dan says

    June 8, 2020 at 4:25 am

    Thank you very much Sir for your quick responds. its exactly what I need.

    Reply
    • Swagatam says

      June 8, 2020 at 7:35 am

      You are welcome Dan!

      Reply
      • Dan says

        June 9, 2020 at 4:28 pm

        wow Thanks a lot Swagatam the code (sketch) is working very well.

        Reply
        • Swagatam says

          June 9, 2020 at 5:37 pm

          Glad it’s working Dan, hope you succeed with the project.

          Reply

Primary Sidebar



Categories

  • 3-Phase Power (15)
  • 324 IC Circuits (19)
  • 4017 IC Circuits (52)
  • 4060 IC Circuits (25)
  • 555 IC Circuits (98)
  • 741 IC Circuits (19)
  • Amplifiers (59)
  • Arduino Engineering Projects (83)
  • Audio Projects (94)
  • Battery Chargers (83)
  • Car and Motorcycle (94)
  • Datasheets (46)
  • Decorative Lighting (Diwali, Christmas) (32)
  • DIY LED Projects (89)
  • Electronic Components (97)
  • Electronic Devices and Circuit Theory (35)
  • Electronics Tutorial (109)
  • Fish Aquarium (5)
  • Free Energy (34)
  • Fun Projects (12)
  • GSM Projects (9)
  • Health Related (19)
  • Heater Controllers (28)
  • Home Electrical Circuits (100)
  • How to Articles (20)
  • Incubator Related (6)
  • Industrial Electronics (28)
  • Infrared (IR) (40)
  • Inverter Circuits (98)
  • Laser Projects (12)
  • LM317/LM338 (21)
  • LM3915 IC (25)
  • Meters and Testers (64)
  • Mini Projects (156)
  • Motor Controller (66)
  • MPPT (7)
  • Oscillator Circuits (24)
  • PIR (Passive Infrared) (8)
  • Power Electronics (33)
  • Power Supply Circuits (74)
  • Radio Circuits (9)
  • Remote Control (47)
  • Security and Alarm (61)
  • Sensors and Detectors (118)
  • SG3525 IC (5)
  • Simple Circuits (74)
  • SMPS (29)
  • Solar Controllers (60)
  • Timer and Delay Relay (53)
  • TL494 IC (5)
  • Transformerless Power Supply (8)
  • Transmitter Circuits (40)
  • Ultrasonic Projects (14)
  • Water Level Controller (45)


Circuit Calculators

  • AWG to Millimeter Converter
  • Battery Back up Time Calculator
  • Capacitance Reactance Calculator
  • IC 555 Astable Calculator
  • IC 555 Monostable Calculator
  • Inductance Calculator
  • LC Resonance Calculator
  • LM317, LM338, LM396 Calculator
  • Ohm’s Law Calculator
  • Phase Angle Phase Shift Calculator
  • Power Factor (PF) Calculator
  • Reactance Calculator
  • Small Signal Transistor(BJT) and Diode Quick Datasheet
  • Transistor Astable Calculator
  • Transistor base Resistor Calculator
  • Voltage Divider Calculator
  • Wire Current Calculator
  • Zener Diode Calculator


You can also Chat with me here:

Facebook
Twitter
YouTube
Instagram
My Facebook-Page
Quora



© 2022 · Swagatam Innovations

We use cookies on our website to give you the best experience.
Cookie settingsAccept All
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Please visit the Privacy Policy Page for more info.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT