arduino timer diagram

Arduino Self Timer

“Arduino Self-Timer” project presented here is a low-component count 60 seconds countdown timer. It can be powered from a 9V compact battery or suitable Arduino AC mains adaptor. Working of the circuit is simple!

Schematic of the Arduino Timer Circuit

arduino timer diagram

When you Press the RESET Button on the Arduino board, the timer will countdown from 60 seconds, as programmed. Once the timer countdown reaches 0 seconds, the PIEZO-BUZZER (BZ1) will bang on and the LCD display will blink “TIMER ALERT!”. An optional RELAY driver output is available at pin 4 of the Arduino board. If you wish to add an electromagnetic relay to switch off/switch on any external electric load, just use this output to drive the electro-magnetic relay with the help of a suitable transistor-based relay driver circuit. Note that the timer program is resetted every time you press the RESET Button and the timer countdown begins again.


Arduino Sketch

//Arduino Self-Timer
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
int runTimer = 1; 
int runFor = 60; // time in seconds
int buzzerPin = 13;
int relayPin=4;
int data = 0;

void setup() {
   pinMode(buzzerPin, OUTPUT);
   lcd.begin(16, 2);

void loop() {
   if(runTimer == 1){ 
      digitalWrite(relayPin,LOW); // relay is OFF during countdown
      /* *change to HIGH if you want the relay to be ON while countdowning */
      //Start timer
   } else {
      digitalWrite(relayPin,HIGH); // relay is ON when time expired
      /* *change to LOW if you want the relay to be OFF when the time expired */
   runTimer = 0;
   for(int duration = 0; duration < 100; duration ++){
      digitalWrite(buzzerPin, HIGH);
      digitalWrite(buzzerPin, LOW);

void timer() {
   for(int timer = runFor;timer > 0; --timer){
   if(timer >= 10) {
   } else {   
   lcd.print(" SECOND!");
   lcd.print(" TIMER ALERT!");  


Join the conversation!

Error! Please fill all fields.
  • wasanthapicgmail-com

    hi !!!
    your code is working thanks for the help
    can you show me how to put 2 buttons that will run 2 relays
    when button 1 is pressed relay 01 is on for 500ms and off for 1000ms goes on a loop
    when button 2 is pressed relay 02 is on for 1000ms and off for 500ms goes on a loop if buttons are not bushed relay 01 and 02 are off
    hopping to hear from you soon sir

    • T.K.Hareendran

      Don’t get me wrong; As I’m busy with many projects, I don’t have enough spare time (the schedule is ever growing) to provide free customized codes. I’m ready to clear your doubts (if any) connected with this published article. For the rest, better try it out yourself!

  • Veeramanikandanmanoharan

    Dear Sir,
    Can you help me in writing a C program to generate a two 50khz signal?
    Duty cycle of 50% and there should be a deadtime of 1 millsec between that two signals.


  • wasanthapicgmail-com

    Dear sir my name is wasantha and I am from Srilanka.

    Can you show me how to make this timer loop over without stopping.
    like relay ON for 20 second and OFF for 30 second and goes on without stopping
    Thank you.

    • T.K.Hareendran

      I think you’re looking for a cyclic timer, ie. want an operation to repeat periodically.

      Here’s a sample code for your reference. Tweak it for the specific purpose:

      const int OUTPUT_PIN = 13; // Pin to control the load
      const int NUMBER_OF_CYCLES = 10; // Total number of cycles
      const int CYCLE_TIME_ON = 500; // On time per cycle in milliseconds
      const int CYCLE_TIME_OFF = 200; // Off time per cycle in milliseconds

      void setup()
      pinMode(OUTPUT_PIN, OUTPUT);
      digitalWrite(OUTPUT_PIN, LOW);

      // Run the timer
      void loop()
      int cycles = NUMBER_OF_CYCLES;
      while(cycles– > 0)
      // Turned timed output on
      digitalWrite(OUTPUT_PIN, HIGH);
      // Turn timed output off
      digitalWrite(OUTPUT_PIN, LOW);
      // Hold forever

  • Frank

    Me refiero a modificar la programación para establecer un intervalo de tiempo o varios intervalos de tiempo usando pulsadores.

  • Frank

    Hola, ¿como podria programar el tiempo?

  • Daniel

    hi there.

    can any one help I like your project I have changed it a bit so that it turns 6 relays on every 5 seconds any on help me I want it to display witch relays are on as it goes through them thanks

  • Shyam

    Mr. Hareendran, my lcd powers up and is functional but I’m not getting any display response. “TIMER=” or “TIMER ALERT” isn’t appearing. I’m using this as a small mechanism in a larger project. Could you please help solve this problem?

  • joey P

    also, can you recommend a good place to get an LCD like the one shown?

  • joey P

    Can you change the switch that sets it off to something other than the button on the board? For example a switch on one of the pins…

    • Medzik

      Hello I would also like to reset timer through some input switch. I not very good in programming, so it will be really help-full if somebody give me a start clue.


  • T.K.Hareendran

    The original sketch was slightly modified at Electroschematics!I am thankful to Mr.Popescu Marian for his keen interest in my little design.

Looking for the latest from TI?