Project tutorial

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

Arduino stopwatch and lap timer with excelent accuracy and responsiveness!

  • 20,068 views
  • 18 comments
  • 40 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
Code for Arduino
/*
   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

Analog Clock with LED Matrix and Arduino

Project tutorial by LAGSILVA

  • 12,237 views
  • 8 comments
  • 39 respects

Complete Digital Clock Including Alarm and Motion Sensor

Project tutorial by LAGSILVA

  • 12,678 views
  • 11 comments
  • 50 respects

Swimming Pool Lap Counter

Project showcase by Ruben Zilzer

  • 4,163 views
  • 4 comments
  • 20 respects

Tiny Calendar and Clock Featuring Moon Phase in a LED Matrix

Project showcase by LAGSILVA

  • 6,075 views
  • 6 comments
  • 33 respects

4-Stroke Digital Clock With Arduino

Project showcase by LAGSILVA

  • 11,104 views
  • 9 comments
  • 39 respects

Arduino Nano LCD Stopwatch Without Potentiometer

Project tutorial by TechWithZan

  • 5,176 views
  • 9 comments
  • 14 respects
Add projectSign up / Login