Project showcase

Stopwatch and Lap Timer with Arduino © CC BY-NC-ND

Arduino stopwatch and lap timer with excelent accuracy and responsiveness!

  • 32,122 views
  • 26 comments
  • 61 respects

Components and supplies

Apps and online services

About this project

1- Introduction

Stopwatches are very useful in several applications and made by yourself using an Arduino, it is really more interesting!

This project is really simple, easy to be assembled using few components and has an excellent accuracy and responsiveness including the following features:

  • The stopwatch shows the time in minutes, seconds and tenth of seconds.
  • The lap timer shows the time in seconds and hundreths of seconds.
  • Internally the time count is in miliseconds by the clock of microcontroler.

Video: Stopwatch & Lap Timer

2- Material List:

  • Arduino Nano (Uno R3 as optional)
  • LED Display with MAX7219 (8 Digits x 7 Segments)
  • Tactile Button Switches
  • Breadboard
  • Jumper Wires

3- Operation

There are 3 tactile button to control the stopwatch:

  • Left: Reset the Stopwatch
  • Middle: Start/Stop the Stopwatch
  • Right: Lap Time

The first 4 digits at left show the stopwatch time and the 4 digits at right are for the lap timer.

Notes:

  • Due to the number of digits available in the LED display, the maximum time count is 9 min 59.9 seconds.
  • For same reason, the lap timer is limited to 99.99 seconds.
  • Beyond these limits, the symbols "----" indicate the overflow of time.

Code

Stopwatch_with_Arduino_Nano_in_Double_LED_Display_V1.2.inoArduino
/*
   Project:     Stopwatch with Arduino Nano
   Hardware:    Arduino Nano - 8 Dig x 7 Seg LED Display
   Revision:    1.2
   Date:        03.Mar.2019
   Author:      LAGSILVA
   License:     CC BY-NC-ND 4.0
                (Attribution-NonCommercial-NoDerivatives 4.0 International)
*/

#include <LedControl.h>       // Library for LED control with MAX72XX
#include <Bounce2.h>          // Library for Bounce of switches

/*
  Pins of Arduino Nano for LedControl:
  Pin #7 is connected to DataIn (DIN)
  Pin #8 is connected to CLK (CLK)
  Pin #9 is connected to LOAD (CS)
*/

// LedControl(int dataPin, int clkPin, int csPin, int numDevices)
LedControl lc = LedControl(7, 8, 9, 1);

long tn, lastTime, diffTime, deltaT;
int milhar, centena, dezena, unidade;
int milhar1, centena1, dezena1, unidade1;

byte pinStartStop = 4;        // Start-Stop Pin
byte pinLapse = 3;            // Time Lapse Pin

bool statusSwitch1 = false;

Bounce SW1 = Bounce();        // Define Bounce to read StartStop switch
Bounce SW2 = Bounce();        // Define Bounce to read Lapse switch


void setup() {

  pinMode (pinStartStop, INPUT_PULLUP);
  pinMode (pinLapse, INPUT_PULLUP);

  // After setting up the button, setup the Bounce instance
  SW1.attach(pinStartStop);   // Sets the pin (Internal Pull-Up)and matches the internal state to that of the pin
  SW1.interval(4);            // Sets the debounce time in milliseconds
  SW2.attach(pinLapse);
  SW2.interval(4);

  lc.shutdown(0, false);      // The MAX72XX is in power-saving mode on startup, we have to do a wakeup call
  lc.setIntensity(0, 3);      // Set the brightness of display between 0 and 15
  lc.clearDisplay(0);         // Clear the display

  lc.setDigit(0, 7, 0, true);
  lc.setDigit(0, 6, 0, false);
  lc.setDigit(0, 5, 0, true);
  lc.setDigit(0, 4, 0, false);

  lc.setDigit(0, 3, 0, false);
  lc.setDigit(0, 2, 0, true);
  lc.setDigit(0, 1, 0, false);
  lc.setDigit(0, 0, 0, false);

}


void loop() {

  SW1.update();   // Start-Stop

  if (SW1.fell()) {
    statusSwitch1 = !statusSwitch1;
  }

  if (statusSwitch1 == true && tn <= 599900) {

    tn = millis() - deltaT;

    milhar = tn / 60000;
    centena = (tn / 10000) % 6;
    dezena = (tn / 1000 ) % 10;
    unidade = (tn / 100) % 10;

    lc.setDigit(0, 7, milhar, true);
    lc.setDigit(0, 6, centena, false);
    lc.setDigit(0, 5, dezena, true);
    lc.setDigit(0, 4, unidade, false);
  }

  else {

    deltaT = millis() - tn;

    if (tn > 599900) {        // Overflow Warning for Stopwatch: "----"
      lc.setRow(0, 7, 1);
      lc.setRow(0, 6, 1);
      lc.setRow(0, 5, 1);
      lc.setRow(0, 4, 1);
    }

  }


  SW2.update();   // Lap Time

  if (SW2.fell()) {

    diffTime = tn - lastTime;
    lastTime = tn;

    milhar1 = diffTime / 10000;
    centena1 = (diffTime / 1000) % 10;
    dezena1 = (diffTime / 100) % 10;
    unidade1 = (diffTime / 10) % 10;

    lc.setDigit(0, 3, milhar1, false);
    lc.setDigit(0, 2, centena1, true);
    lc.setDigit(0, 1, dezena1, false);
    lc.setDigit(0, 0, unidade1, false);

    if (diffTime > 99990) {   // Overflow Warning for Lap Time: "----"
      lc.setRow(0, 3, 1);
      lc.setRow(0, 2, 1);
      lc.setRow(0, 1, 1);
      lc.setRow(0, 0, 1);
    }

  }

}

Schematics

Breadboard Schematic
Breadboard schematic for Arduino Nano

Comments

Similar projects you might like

Arduino Mutitasking: Clock + Stopwatch + Timer

Project showcase by LAGSILVA

  • 39,937 views
  • 13 comments
  • 78 respects

Reaction Timer - F1 Style

Project showcase by LAGSILVA

  • 4,801 views
  • 4 comments
  • 17 respects

Scrambled Digits Clock with Alarm

Project showcase by LAGSILVA

  • 3,409 views
  • 7 comments
  • 13 respects

Analog Clock with LED Matrix and Arduino

Project showcase by LAGSILVA

  • 22,452 views
  • 17 comments
  • 79 respects

Ternary Digital Clock with Arduino

Project showcase by LAGSILVA

  • 8,076 views
  • 6 comments
  • 19 respects

4-Stroke Digital Clock With Arduino

Project showcase by LAGSILVA

  • 18,135 views
  • 15 comments
  • 48 respects
Add projectSign up / Login