Project showcase

Stopwatch and Lap Time Counter © CC BY-NC-SA

This project is about a stopwatch including the feature of lap time counter and controlled by Arduino (Nano or Uno).

  • 14,931 views
  • 6 comments
  • 26 respects

Components and supplies

Apps and online services

About this project

Hello everybody,

This is a very simple project about a stopwatch using Arduino Nano (or Uno R3) and a MAX7219 LED display (8 Digits x 7 Segments). The first 4 digits of display show the time in seconds and tenth of seconds. The another 4 digits show the last lap time.

Due to the number of digits available on display, the maximum time count is 999.9 seconds (16 minutes and 39.9 seconds) and with a really good accuracy comparing it with another stopwatches.

Let's see it!

Video

Materials List:

  • 1 x Arduino Nano (or Uno R3 as optional)
  • 1 x MAX7219 LED Display (8 Digits x 7 Segments)
  • 3 x Tactile Button Switches
  • 1 x Breadboard
  • 1 x Wires (set of jumpers)

Notes:

  • The advantage of use MAX7219 is because it uses only 3 data pins of Arduino to control the display.
  • Arduino Nano represents a more compact package.

Schematics

The assembly of the components is very simple. Just follow the schematic taking care with wire connections.

Setup

There are only 3 tactile buttons with the following functions:

  • Reset the display (1st button at left)
  • Start/Stop the Stopwatch (2nd button at center)
  • Lap Time (3rd button at right)

The running time in tenth of seconds is shown at first 4 digits at left of display. The lap time is shown in the last 4 digits at right of display.

Further applications

With minor update in the code is possible to use sensors (LDR or IR) in place of buttons Start/Stop and the Lap Time to control automatically the stopwatch.

Code

Stopwatch Arduino's CodeArduino
Stopwatch Arduino's Code
/*               Stopwatch with Arduino Nano
        (MAX7219 LED Display - 8 Digits x 7 Segments)
                    V1.0 - 01.Jul.2016
                        by LAGSILVA
*/

#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)
  There is only one display with MAX72XX
*/


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

int k, lastTime, diffTime;
int milhar, centena, dezena, unidade;
int milhar1, centena1, dezena1, unidade1;

int pinStartStop = 4;          // Start-Stop Pin
int pinLap = 3;                // Lap Time Pin

bool statusSwitch1 = false;

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


void setup() {

  pinMode (pinStartStop, INPUT_PULLUP);
  pinMode (pinLap, 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(3);            // Sets the debounce time in milliseconds
  SW2.attach(pinLap);
  SW2.interval(3);

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

  lc.setDigit(0, 7, 0, false);
  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, false);
  lc.setDigit(0, 1, 0, true);
  lc.setDigit(0, 0, 0, false);

}


void loop() {

  lastTime = 0;
  diffTime = 0;

  for (k = 0; k <= 9999; k++) {


    SW1.update();

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

    if (statusSwitch1 == true) {

      milhar = k / 1000;
      centena = (k - milhar * 1000) / 100;
      dezena = (k - milhar * 1000 - centena * 100) / 10;
      unidade = k % 10;

      lc.setDigit(0, 7, milhar, false);
      lc.setDigit(0, 6, centena, false);
      lc.setDigit(0, 5, dezena, true);
      lc.setDigit(0, 4, unidade, false);
    }
    else {
      k = k - 1;
    }


    SW2.update();

    if (SW2.fell()) {

      diffTime = k - lastTime;
      lastTime = k;

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

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

    }

    delay(99);

  }

}

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

  • 13,780 views
  • 12 comments
  • 51 respects

Swimming Pool Lap Counter

Project showcase by Ruben Zilzer

  • 4,228 views
  • 4 comments
  • 20 respects

Tiny Calendar and Clock Featuring Moon Phase in a LED Matrix

Project showcase by LAGSILVA

  • 6,076 views
  • 6 comments
  • 33 respects

4-Stroke Digital Clock With Arduino

Project showcase by LAGSILVA

  • 11,683 views
  • 14 comments
  • 39 respects

Arduino Nano LCD Stopwatch Without Potentiometer

Project tutorial by TechWithZan

  • 5,989 views
  • 9 comments
  • 16 respects
Add projectSign up / Login