Project showcase

Arduino Mutitasking: Clock + Stopwatch + Timer © CC BY-NC-ND

This project is about an Arduino running a digital clock, a stopwatch, and a timer simultaneously!

  • 28,387 views
  • 13 comments
  • 73 respects

Components and supplies

Apps and online services

About this project

1) Introduction

This project is about a digital clock plus a stopwatch (hundredths of seconds) and a timer (1 to 99 minutes) for Arduino.

Everything working simultaneuouly using only the internal clock of Arduino with excelent accuracy for non professional applications!!

It is an interesting use of multitasking with a single microcontroler and simple functions like millis().

Video

Video Description (Portuguese Version)

Video (Stopwatch - Comparative Test)

2) Material

  • Arduino UNO-R3
  • Multi-Function Shield

The Multi-Function Shield is used to simplify and speed up the prototype development.

Main features:

  • 4 digit 7-segment LED display module driven by two serial 74HC595's
  • 4 x surface mount LED's in a parallel configuration
  • 10K adjustable precision potentiometer
  • 3 x independent push buttons
  • Piezo buzzer
  • DS18B20 temperature sensor interface
  • LM35 temperature sensor interface
  • Infrared receiver interface
  • Serial interface header for convenient connection to serial modules such as Bluetooth, wireless interface, voice module, a voice recognition module, etc.

3) Computer Multitasking

There is a good explanation about Computer Multitasking at Wikipedia:

"In computing, multitasking is the concurrent execution of multiple tasks (also known as processes) over a certain period of time. New tasks can interrupt already started ones before they finish, instead of waiting for them to end."

"Multitasking does not require parallel execution of multiple tasks at exactly the same time; instead, it allows more than one task to advance over a given period of time. Even on multiprocessor computers, multitasking allows many more tasks to be run than there are CPUs."

The two ways of applying multitasking to the Arduino are using interrupts and millis() function.

The function millis()"Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days."

The main difference between delay() and millis() is that with the first, you wait for a certain period of time and with the second, you know how much time has passed.

Using millis() it is possible to control multiple events only by monitoring the time between start and stop of all procedures.

For example, when the procedure of stopwatch starts to run, a variable is set to initial time in miliseconds and then is calculated the difference between the current time read by millis() and the initial time.

And the same is for the timer procedure.

void readKey() {
 // Initial time for Stopwatch
 if (key1) {
  startStopwatchTime = millis();
 }
 // Initial time for Timer
 if (key2) {
  startTimerTime = millis();
 }
}
void loop() {
 // Stopwatch Mode
 if (mode == 1) {
  currentStopwatchTime = millis() - startStopwatchTime;
 }
 // Timer Mode
 if (mode == 2) {                  
  currentTimerTime = millis() - startTimerTime;
 }
}

Repeating this process is possible to move to different routines keeping all information about the lapse time of them.

Every time when a routine is restarted, the lapse time is updated considering the current millis() and the initial reference time.

This is the magic provided by the clock of microprocessor.

4) Setup of Device

- Hour Mode

  • Hour (0 to 23): press the Left button to add 1 hour.
  • Minute (0 to 59): press the Middle button to add 1 minute.
  • Next Mode: press the Right button to move to Stopwatch mode.

- StopwatchMode

  • Start/Stop: press the Left button to start or to stop the stopwatch.
  • Lapse Time: press the Middle button when stopwatch is running.
  • Reset: press the Middle button to reset the stopwatch when it is stopped.
  • Next Mode: press the Right button to move to Timer mode.

Notes:

  • The total time of the stopwatch is 299.99 seconds (5 minutes).
  • After 99.99 seconds, a second dot of display is shown (first at right) to indicate the virtual digit "1" to count until 199.99 seconds.
  • After 199.99 seconds, a third dot is shown to symbolize the virtual digit "2" to count until 299.99 seconds.

- TimerMode:

  • Start/Reset: press the Left button to start or to reset the timer.
  • Set timer: press the Middle button to adjust the total time (1 to 99 minutes).
  • Next Mode: press the Right button to move to Hour mode.

Notes:

  • When the countdown time is completed, a buzzer starts a warning sound.
  • The warning buzzer works in all modes.
  • The buzzer can be turned off only in the Timer mode.

Comments

Similar projects you might like

Stopwatch and Lap Timer with Arduino

Project tutorial by LAGSILVA

  • 22,659 views
  • 20 comments
  • 50 respects

Analog Clock with LED Matrix and Arduino

Project tutorial by LAGSILVA

  • 17,488 views
  • 17 comments
  • 65 respects

4-Stroke Digital Clock With Arduino

Project tutorial by LAGSILVA

  • 14,935 views
  • 15 comments
  • 45 respects

Amazing Binary Clock using LED Matrix Module

Project in progress by LAGSILVA

  • 11,921 views
  • 13 comments
  • 63 respects

Ternary Digital Clock with Arduino

Project tutorial by LAGSILVA

  • 5,998 views
  • 6 comments
  • 15 respects

Digital & Binary Clock In 8 Digits x 7 Segments LED Display

Project tutorial by LAGSILVA

  • 3,492 views
  • 3 comments
  • 11 respects
Add projectSign up / Login