Stopwatch - Stopwatch Using Arduino with 7 Segment Display

Stopwatch Using Arduino with 7 Segment Display

In this post we are going to construct a stopwatch circuit using 7 segment LED display and Arduino. We will be exploring the concepts related to interrupts and display driver ICs which are crucial for understand this project. This project was suggested by Mr Abu-Hafss who is one of the avid reader of this website.

By Girish Radhakrishnan

 

Introduction

Stopwatch is a device which helps to track brief period of time from hours to milliseconds range (mostly). Almost all cheap digital wrist watches equipped with stopwatch functionality, but none of the watches can give the zest of making one for our self and also finding a stopwatch with 7 segment LED display is exceptional.

Mr Abu-Hafss suggested us to design a stopwatch with 4 displays, two for minutes and two for seconds (MM:SS) configuration. But for most of us it may not be a feasible design, so we added two more display for millisecond range so now the proposed design will be in MM:SS:mS configuration.

If you just need MM:SS configuration for some reason, you no need to connect the millisecond range 7 segment displays and its driver ICs, the whole functionality of the circuit still be unaffected.

The circuit:

The proposed stopwatch consists of six IC 4026 which is seven segment display driver, six 7 segment LED displays, one Arduino board, a couple of push buttons and couple of 10K resistors.

Now let’s understand how to connect IC 4026 to 7 segment display.

The 7 segment display can be any common cathode display of any colour. The 7 segment display can get easily killed by 5V supply, so a 330 ohm resistor is mandatory on each segment of the display.

 

Now let’s see the pin diagram of IC 4026:

 

 

IC 4026 Pinout - Stopwatch Using Arduino with 7 Segment Display

 

  • The pin #1 is clock input.
  • The pin #2 is clock disable, it disable the count on display if this pin is high.
  • The pin #3 is display enable; if this pin is low the display will be tuned off and vice versa.
  • The pin #5 is carry-out, which becomes high when IC counts 10.
  • The pins 6, 7, 9, 10, 11, 12, 13 are display outputs.
  • The pin #8 is GND.
  • The pin #16 is Vcc.
  • The pin #15 is reset, if we high this pin the count turns to zero.
  • The pins #4 and #14 are not used.

Display connection diagram:

 

Display connection diagram:

 

Any one of the GND pin of 7 segment display can be connected to ground. The IC must be powered from 5V supply or Arduino’s 5V output pin.

The above schematic for just one display, repeat the same for five other displays.

Here is the rest of the schematic:

 

Stopwatch Using Arduino with 7 Segment Display

 

The circuit may be powered from 9V battery. The are two buttons provided here one for starting the time and another for stopping. By pressing reset button on Arduino, the time count will be reset to zero on display.

The two push button are connected to pin #2 and #3 which are hardware interrupt of Arduino / Atmega328P microcontroller.

Let’s understand what interrupt is:

There are two types of interrupts: hardware interrupt and software interrupt. Here we are using only the hardware interrupt.

An interrupt is a signal to the microcontroller, which will makes the microcontroller to respond immediately to an event.

There are only two hardware interrupt pins in Arduino boards with ATmega328P microcontroller; pin #2 and #3. Arduino mega has more than two hardware interrupt pins.

The microcontrollers can’t do two functions at same time. For example checking for button press and counting numbers.

The microcontrollers cannot execute two events simultaneously, if we write a code for checking button press and counting numbers, the button press will get detected only when the microcontroller reads the button press detection piece of code, rest of the time (counts the numbers) the button doesn’t work.

So there will be delay in detection of the button press and for some reason if the code gets halted temporarily, the button press may never get detected. To avoid these kinds of issues interrupt is introduced.

The interrupt signal is always given highest priority, the main function (main lines of code) will be halted and executes the (another piece of code) function assigned for that particular interrupt.

This is very important for time critical applications like stopwatch or security systems etc. where the processor need to take immediate action in response to an event.

In Arduino we assign hardware interrupt as:

attachInterrupt(0, start, RISING);

  • “0” means the interrupt number zero (in microcontrollers everything starts from zero) which is pin#2.
  • “start” is name of the interrupt function, you can name anything here.
  • “RISING” if the pin #2 (which is interrupt zero) goes high, the interrupt function executes.

attachInterrupt(1, Stop, RISING);

  • “1” means the interrupt number one which is pin #3.
  • “Stop” is name of the interrupt.

We can also replace “RISING” with “FALLING”, now when the interrupt pin goes LOW the interrupt function executes.

We can also replace “RISING” with “CHANGE”, now whenever the interrupt pin goes from high to low or low to high, the interrupt function executes.

The interrupt function can be assigned as follows:

void start() //start is the name of the interrupt.

{

//program here

}

The interrupt function must be short as possible and delay() function cannot be used.

That concludes the hardware interrupt; software interrupt related to Arduino will be explained in future article.

Now you know why we connected the start and stop push buttons to interrupt pins.

Connect the circuit as per the diagram; rest of the circuit is self-explanatory.

Program:

//----------------Program Developed by R.GIRISH---------------//

int vmin = 0;
int vsec = 0;
int vms = 0;
boolean Run = false;
const int Min = 7;
const int sec = 6;
const int ms = 5;
const int reset_pin = 4;
void setup()
{
pinMode(Min, OUTPUT);
pinMode(sec, OUTPUT);
pinMode(ms, OUTPUT);
pinMode(reset_pin, OUTPUT);
digitalWrite(Min, LOW);
digitalWrite(sec, LOW);
digitalWrite(ms, LOW);
digitalWrite(reset_pin, HIGH);
digitalWrite(reset_pin, LOW);
attachInterrupt(0, start, RISING);
attachInterrupt(1, Stop, RISING);
}
void loop()
{
if (Run)
{
vms = vms + 1;
digitalWrite(ms, HIGH);
delay(5);
digitalWrite(ms, LOW);
delay(5);
if (vms == 100)
{
vsec = vsec + 1;
digitalWrite(sec, HIGH);
digitalWrite(sec, LOW);
vms = 0;
}
if (vsec == 60)
{
vmin = vmin + 1;
digitalWrite(Min, HIGH);
digitalWrite(Min, LOW);
digitalWrite(reset_pin, HIGH);
digitalWrite(reset_pin, LOW);
vsec = 0;
}
}
}
void start()
{
Run = true;
}
void Stop()
{
Run = false;
}

//----------------Program Developed by R.GIRISH---------------//

 

Now that concludes the code.

If you have any further questions regarding this Arduino stopwatch with 7 segment display project, please feel free to express in the comment section, you may receive a quick reply.

2 thoughts on “Stopwatch Using Arduino with 7 Segment Display

  1. Have questions? Please feel free to post them through comments! Comments will be moderated and solved ASAP.
  2. Hi swagatam,
    i have a question on cd4026.
    This ic can power supply directly an seven segments display or i need of driver for example transitors?
    thank you
    Andrea

    • Hi Andrea yes it will be able to illuminate the modules directly, because the display digits require not more than 10mA to light up which can be easily obtained from the IC output pins.



Leave a Comment