Advertisement
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.

Photos

Arduino Sketch

//Arduino Self-Timer
//T.K.Hareendran
//www.electroschematics.com
#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);
   pinMode(relayPin,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 */
      lcd.clear();
      lcd.print("TIMER=");
      //Start timer
      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;
   lcd.noDisplay();
   delay(250);
   for(int duration = 0; duration < 100; duration ++){
      digitalWrite(buzzerPin, HIGH);
      delayMicroseconds(500);
      digitalWrite(buzzerPin, LOW);
      delayMicroseconds(500);
   } 
   lcd.display();
   delay(250);
}

void timer() {
   for(int timer = runFor;timer > 0; --timer){
   if(timer >= 10) {
      lcd.setCursor(6,0); 
   } else {   
      lcd.setCursor(6,0);
      lcd.print("0");
      lcd.setCursor(7,0);
   }
   lcd.print(timer);
   lcd.print(" SECOND!");
   delay(1000);
   }
   lcd.setCursor(0,0);
   lcd.clear();
   lcd.print(" TIMER ALERT!");  
}

15 Comments

Join the conversation!

Error! Please fill all fields.
  • 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.
    Thankyou…

    veeramanikandan.

  • 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);
      delay(CYCLE_TIME_ON);
      // Turn timed output off
      digitalWrite(OUTPUT_PIN, LOW);
      delay(CYCLE_TIME_OFF);
      }
      // Hold forever
      while(1);
      }

  • 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.

      Thanks

  • 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.

  • Popescu Marian

    Also be aware that that LCDs may use other pins, for example mine uses pins 7, 6, 5, 4, 3 and 2 so you have to change the relayPin to 8 or another pin that is not used by the LCD.

Looking for the latest from TI?