Arduino Countdown timer with LCD and buzzer

In this post we are going to construct a countdown timer using Arduino with 16×2 LCD display and buzzer which beeps loudly for 4 seconds once the set time reaches zero. We also provided an optional relay to control external electrical or electronic devices when the set time counts to zero.

We will see:

  • Simple difference between countdown timer and stopwatch.
  • Block diagram of arduino countdown timer.
  • Countdown timer circuit without relay.
  • Countdown timer circuit with a relay.
  • Program code for countdown timer.
  • Tested prototype of the countdown timer.
  • How to operate the countdown timer properly.

What is the difference between countdown timer and stopwatch?

We are answering this question because countdown timer and stopwatch are two different things and yet many people think they are synonymous and unaware of their core differences. They are used in two opposite scenarios and you should choose the correct one for your purpose.

Countdown timer:

A countdown timer is used where the time is predetermined (fixed) and there is a need for completing a task with in the specified time period. The timer display or an analog dial counts backward and shows the remaining time left and the timer eventually reaches zero.   

Traffic Light – Image courtesy: Flickr (CC BY-SA 2.0)

For example: Traffic lights, microwave oven timer, sleep timer on TV / computer etc.

Stopwatch:

A stopwatch is used where you need to measure how long it took for an event to complete. The timer display or an analog dial shows the time passed since the beginning of an event.

Analog Stopwatch-Image courtesy: Flickr (CC BY-SA 2.0)

For example: A running race where we measure how long it took for a participant to reach the finish line, measuring pulse of a patient etc.

By now you should have understood the difference between a stopwatch and a countdown timer.  In this post we are building a countdown timer, if you want to build a stopwatch we have designed a 6-digit 7 segment display stopwatch circuit using IC 555; you can find the details here.

Block diagram of Arduino countdown timer:

Arduino Countdown Timer Block Diagram

An arduino board is utilized here which acts as brain of the project, it tracks the time and actuates a buzzer and an (optional) relay and also it controls the 16 x 2 LCD display where it shows the amount of time left in HH:MM:SS format.

This countdown timer consists of 4 buttons using which you can set, start and stop the timer. A 10k ohm variable resistor controls the contrast of the LCD where you may adjust it to get optimum legibility on the screen.

Countdown timer circuit diagram:

Arduino Countdown Timer Circuit With LCD and Buzzer

You can download high resolution image of the above circuit: Click here

The circuit is self-explanatory; just connect the components as shown in the circuit diagram. For backlighting a 100 ohm current limiting resistor is connected to +Ve of the backlight terminal on the LCD. The 10K variable resistor can be a potentiometer or a preset or a trimmer potentiometer.

The 4 buttons are momentary push buttons where it conducts when you press the button and stops conducting when you release the button.   

You can utilize any arduino board not just limited to arduino nano as shown in the above circuit and you may power the arduino via USB.

If you could not recognize the correct arduino pins on the schematic, please download the high resolution image and you can zoom in to the circuit extensively.

Countdown timer circuit with relay:

Arduino Countdown Timer Circuit With Relay

You can download high resolution image of the above circuit: Click here

The above circuit consist of an additional relay using which you can trigger some useful application when the timer counts to zero, like automatic bathroom light shut-off, automatic water heater shut-off, disconnecting microphone in a speech competition…… you name an application for it.

The relay coil is connected to BC548 NPN transistor which switches the relay ON and OFF. The control signal is provided from pin #8 of arduino, when the timer reaches zero the pin #8 turns low, while the timer is running / counting pin #8 stays high. A diode is connected across the relay coil in reverse bias to arrest the high voltage spike that could arise while switching the relay coil ON and OFF.

Relay pin diagram:

Do not use a relay that operates at 5V which usually comes with a breakout board as illustrated above, this is because the relay, LCD and buzzer consumes current more than arduino’s 5V regulator can provide so we are using a relay that can be powered externally, doing so we can provide adequate current to the mentioned peripherals.

The commonly available relay voltages are 9V and 12V, the whole circuit can powered with 9V if you are using a 9V relay or with 12V if you are using a 12V relay. Don’t power this circuit via USB as it cannot provide power to relay.

Program code for countdown timer (with and without relay):

//--------------(c) Electronics project hub -----------//
#include <LiquidCrystal.h>
#include<EEPROM.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int stsp = A0;
const int inc = A1;
const int dec = A2;
const int set = A3;
const int buzz = 9;
const int relay = 8;
int hrs = 0;
int Min = 0;
int sec = 0;
unsigned int check_val = 50;
int add_chk = 0;
int add_hrs = 1;
int add_min = 2;
bool RUN = true;
bool min_flag = true;
bool hrs_flag = true;
void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("   ELECTRONIC");
  lcd.setCursor(0, 1);
  lcd.print("COUNTDOWN TIMER");
  pinMode(stsp, INPUT_PULLUP);
  pinMode(inc, INPUT_PULLUP);
  pinMode(dec, INPUT_PULLUP);
  pinMode(set, INPUT_PULLUP);
  pinMode(buzz, OUTPUT);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, LOW); 
  digitalWrite(buzz, LOW);
  if (EEPROM.read(add_chk) != check_val)
  {
    EEPROM.write(add_chk, check_val);
    EEPROM.write(add_hrs, 0);
    EEPROM.write(add_min, 1);
  }
  else
  {
    hrs = EEPROM.read(add_hrs);
    Min = EEPROM.read(add_min);
  }
  delay(1500);
  INIT();
}

void loop()
{
  if (digitalRead(stsp) == LOW)
  {
    lcd.clear();
    delay(250);
    RUN = true;
    while (RUN)
    {
      if (digitalRead(stsp) == LOW)
      {
        delay(1000);
        if (digitalRead(stsp) == LOW)
        {
          digitalWrite(relay, LOW); 
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("  TIMER STOPPED");
          lcd.setCursor(0, 1);
          lcd.print("----------------");
          delay(2000);
          RUN = false;
          INIT();
          break;
        }
      }
      digitalWrite(relay, HIGH); 
      sec = sec - 1;
      delay(1000);
      if (sec == -1)
      {
        sec = 59;
        Min = Min - 1;
      }
      if (Min == -1)
      {
        Min = 59;
        hrs = hrs - 1;
      }
      if (hrs == -1) hrs = 0;
      lcd.setCursor(0, 1);
      lcd.print("****************");
      lcd.setCursor(4, 0);
      if (hrs <= 9)
      {
        lcd.print('0');
      }
      lcd.print(hrs);
      lcd.print(':');
      if (Min <= 9)
      {
        lcd.print('0');
      }
      lcd.print(Min);
      lcd.print(':');
      if (sec <= 9)
      {
        lcd.print('0');
      }
      lcd.print(sec);
      if (hrs == 0 && Min == 0 && sec == 0)
      {
        digitalWrite(relay, LOW); 
        lcd.setCursor(4, 0);
        RUN = false;
        for (int i = 0; i < 20; i++)
        {
          digitalWrite(buzz, HIGH);
          delay(100);
          digitalWrite(buzz, LOW);
          delay(100);
        }
        INIT();
      }
    }
  }
  if (digitalRead(set) == LOW)
  {
    delay(500);
    while (min_flag)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("SET MINUTE: ");
      lcd.print(Min);
      delay(100);
      if (digitalRead(inc) == LOW)
      {
        Min = Min + 1;
        if (Min >= 60) Min = 0;
        delay(100);
      }
      if (digitalRead(dec) == LOW)
      {
        Min = Min - 1;
        if (Min <= -1) Min = 0;
        delay(100);
      }
      if (digitalRead(set) == LOW)
      {
        min_flag = false;
        delay(250);
      }
    }
    while (hrs_flag)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("SET HOUR: ");
      lcd.print(hrs);
      delay(100);
      if (digitalRead(inc) == LOW)
      {
        hrs = hrs + 1;
        if (hrs > 23) hrs = 0;
        delay(100);
      }
      if (digitalRead(dec) == LOW)
      {
        hrs = hrs - 1;
        if (hrs <= -1) hrs = 0;
        delay(100);
      }
      if (digitalRead(set) == LOW)
      {
        hrs_flag = false;
        delay(250);
      }
    }
    if (hrs == 0 && Min == 0)
    {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("  INVAID TIME");
      delay(2000);
    }
    else
    {
      EEPROM.write(add_hrs, hrs);
      EEPROM.write(add_min, Min);
    }
    INIT();
  }
}

void INIT()
{
  hrs = EEPROM.read(add_hrs);
  Min = EEPROM.read(add_min);
  sec = 0;
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Start / Set Time");
  lcd.setCursor(4, 1);
  if (hrs <= 9)
  {
    lcd.print('0');
  }
  lcd.print(hrs);
  lcd.print(':');
  if (Min <= 9)
  {
    lcd.print('0');
  }
  lcd.print(Min);
  lcd.print(':');
  if (sec <= 9)
  {
    lcd.print('0');
  }
  lcd.print(sec);
  min_flag = true;
  hrs_flag = true;
  delay(500);
}
//--------------(c) Electronics project hub -----------//

Note: The above program is same for both the countdown timer circuits (with and without relay).

 Prototype of countdown timer:

Arduino Countdown Timer with LCD and Buzzer

How to operate this countdown timer properly:

Buttons and its functions:

  • There are 4 buttons: Start/Stop, INC (increment), DEC (decrement) and SET.
  • Pressing start button will start the countdown. Long pressing start button will stop the timer.
  • INC button – increments minutes/hours.
  • DEC button – decrements minutes/hours.
  • SET – to set and save the time.

Setting countdown timer to 2 hours and 10 minutes as an example:

  1. Power the circuit on it will display 00:01:00 (HH:MM:SS).

2. Press SET button to set the time, it will ask you to set the minutes first:

Press INC / DEC buttons to set your desire minute, in this example we have set minutes to 10. You can set minutes from 0 to 59. Press SET to save the minute it will get stored to EEPROM of arduino.

3. Now the display will ask you to set hours:

Press INC / DEC to set your desire hours, here we have set hours to 2. You can set hours from 0 to 23 hrs. Press SET to save the time and it will get stored to EEPROM of arduino.

4. Now you have set the time to 2 hours and 10 minutes successfully, the display will return to its default screen:

5. Now press the start button from the default screen, it will start the countdown and relay gets activated (if you added one).

Once the time reaches 00:00:00, the buzzer will beep for 4 seconds and the relay gets deactivated. When you turn the circuit ON next time, it will remember the time which you have set previously, you may set a new time or just begin the countdown with the previously set time using start button.

Note: The minimum time you can set is 1 minute (00:01:00) and the maximum time you can set is 24 hours (23:59:00).

If you have any questions regarding this project, feel free to ask us in the comment section, you will get a guaranteed replay from us.  

Top comments:

I just wired this up and it works great. Thanks for the excellent code…….. this has all the features of a practical and easy-to-use countdown timer.

Ron Jodoin (Reader)

My nick name is blogthor, I am a professional electronics engineer specialized in Embedded System. I am a experienced programmer and electronics hardware developer. I am the founder of this website, I am also a hobbyist, DIYer and a constant learner. I love to solve your technical queries via comment section.