Introduction:
Ready to take your Arduino skills to the next level? In this comprehensive guide, we’ll show you how to build a custom stopwatch with Arduino. This project includes everything you need: a detailed parts list, easy-to-follow code, and STL files for 3D printing your own enclosure. Whether you’re a hobbyist or looking for a fun challenge, this guide will help you create a functional and stylish stopwatch.
The Parts
Parts Download/Excel (8.9 KB)
Starter Box
- 1 x Arduino Microcontroller
- 1 x LCD Display
- 1 x Power Cable
- 2 x Connector Plugs
- 1 x Breadboard
- 1 x White Button
- 1 x Black Button
- 4 x 1k Ohm Resistor
- 1 x Potentiometer
Laser Case
- 1 x Laser
- 1 x Battery
- 1 x Battery Holder/Switch
Photoresistor Case
- 1 x Photoresistor
- 2 x Connector Sockets
Misc.
- 1 x Glue
- 1 x 22 AWG Red Wire
- 1 x 22 AWG Black Wire
- 3D Printed Enclosure Below
Code
Here’s the Arduino code you’ll need. Feel free to modify it to suit your preferences.
Arduino Code Download (3.5 KB)
If you need assistance setting up Arduino, please review this Digi-Key post: How to Get Started with Arduino.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2); //assigning pins for LCD
double startTime; //declaring variables for time, buttons, laser, states
double finishedTime;
double elapsedTime = 0;
int start = 0; //start button state
int startBtn = 13; //start button pin
int photoresState = 0; //photoresistor state
int photoRes = 11; //photoresistor pin
int reset = 0; //reset button state
int resetBtn = 12; //reset button pin
void setup()
{
lcd.begin(8,2); //to start LCD. Our LCD's memory is stored the same as an 8*2 display even though it is 16*1
lcd.clear();
Serial.begin(9600);
pinMode(startBtn, INPUT); //declaring start button as input
pinMode(photoRes, INPUT); //declaring photoresistor as input
pinMode(resetBtn, INPUT); //declaring reset button as input
}
void loop() {
start = digitalRead(startBtn); //reading button states
photoresState = digitalRead(photoRes);
reset = digitalRead(resetBtn);
startTime = millis(); //declaring start as millis. Millis is a onboard clock for arduino
if (start == LOW) { //If start button isn't pressed, display "Press Start" on the LCD.
lcd.clear();
lcd.print("Press");
lcd.setCursor(0,1); //for a 16*1 lcd with 8*2 memory this will set the cursor at the 9th column
lcd.print("Start");
delay(100);
}
if (start == HIGH) { //If start button is pressed, start loop
lcd.clear();
while (photoresState == HIGH) { //while laser is hitting photoresistor continue loop
finishedTime = millis(); //delcaring finished to what millis is when the two above conditions are met
elapsedTime = (finishedTime - startTime) / 1000; //math to show the amount of time elapsed since button was pressed. Divided by 1000 to show in seconds
lcd.print(elapsedTime); //printing elapsed time
lcd.setCursor(0, 1); //for a 16*1 lcd with 8*2 memory this will set the cursor at the 9th column
lcd.print("secs"); //printing "secs" starting from the above set cursor
lcd.setCursor(0, 0); //returning cursor to first column
photoresState = digitalRead(photoRes); //reading current state of photoresistor
if (photoresState == LOW) { //if the laser is not hitting the photoresistor break
break;
}
}
}
if (photoresState == LOW) { //if the laser is not hitting the photoresistor -
lcd.clear();
delay(500);
while (reset == LOW) { //while reset button isn't pressed display time.
lcd.print(elapsedTime);
lcd.setCursor(0, 1);
lcd.print("secs");
lcd.setCursor(0, 0);
reset = digitalRead(resetBtn);
}
}
}
3D Printable Enclosure: Download the STL files to 3D print your own enclosure and give your stopwatch a professional finish.
3D Printed Starter Box:
Starter Box (27.4 KB)
3D Printed Finish Line Case:
Finish Line Case (56.8 KB)
How to Assemble:
- Connect Components: Follow the schematic below to wire your LCD display and push buttons.
- Upload Code: Use the Arduino IDE to upload the provided code.
- Print and Assemble: Use the STL files to print the enclosure and put everything together.
Arduino Pinouts:
Pin 13 = Start, or the white button.
Pin 12 = Reset, or the black button.
Pin 11 = Photoresistor.
Pieces in the 3D Printed Enclosure
Join the Discussion: Have you built your own Arduino projects? Share your experiences or ask questions about this project in the comments below. Don’t forget to like and share if you found this guide helpful!