Introduction: How to Make: Arduino Stopwatch

This is an instructables on how to make an Arduino stopwatch. I wanted to make this stopwatch because I like to keep track of how long my individual skecthes take when I'm drawing. I usually use an online stopwatch for this, so I thought it would be a fun idea to try and make a physical stopwatch.

Step 1: Getting the Right Materials

For this project you will need:

- An Arduino

- Two buttons

- Two resistors

- Around 14 wires (varying lengths)

- A cable to connect your Arduino to your laptop/computer

All of these items can be found in the base kit for Arduino.

https://store.arduino.cc/

Step 2: The Code

In order for the stopwatch to work properly, you will have to enter the following code:

unsigned long start, finished, elapsed;
void setup()

{ Serial.begin(9600); pinMode(2, INPUT); // this is the start button

pinMode(3, INPUT); // this is the stop button

Serial.println("Press 1 for Start/reset, 2 for elapsed time"); } //Here you can change the message your stopwatch will display before any buttons are pressed. Put the instructions here for people who have never used your stopwatch to instantly know what to do.

void displayResult()

{ float h, m, s, ms; unsigned long over; elapsed = finished - start; h = int(elapsed / 3600000); over = elapsed % 3600000; m = int(over / 60000); over = over % 60000; s = int(over / 1000); ms = over % 1000; Serial.print("Milliseconds so far: "); //The tekst that will be displayed before the amount of milliseconds passed.

Serial.println(elapsed); Serial.print("Elapsed time: "); //The tekst that will be displayed before the amout of time elapsed.

Serial.print(h, 0); Serial.print("h "); Serial.print(m, 0); Serial.print("m "); Serial.print(s, 0); Serial.print("s "); Serial.print(ms, 0); Serial.println("ms"); Serial.println(); }

void loop()

{ if (digitalRead(2) == HIGH) { start = millis(); delay(200); // for debounce Serial.println("Ready, set, go!"); } //Here you establish what happens when the first button is pressed and the message that it will display to the user

if (digitalRead(3) == HIGH) { finished = millis(); delay(200); // for debounce displayResult(); } } // here you establish what happens when the second button is pressed and the message that will be displayed.

Step 3: Assembling the Stopwatch

Here is a picture on how to assemble the stopwatch. All wires should be placed on the breadboard in these positions. Soldering is optional, make sure your stopwatch works correctly before you attempt this.

Comments

author
Swansong (author)2017-01-23

Thanks for sharing :)

About This Instructable

204views

1favorite

License:

More by yara-v:Arduino Morse Code GameHow to Make: Arduino Stopwatch
Add instructable to: