We recently got hold of a "Crazy Cart", a seriously cool cart to race around with. As we only have one, I did want to have something to make the driving a bit more competitive, so I build an Arduino Based Lap Timer.
The Lap timer uses an "Infrared light bridge" (Velleman PEM10D) to detect when something crosses the line. The nice thing about this light bridge is that it only needs on one side electronics. The other side just needs a passive reflector. If you do not want to buy this light brigde, you can use an laser bean on one side and a photodiode on the other side, but that will require "electronics" on both side.
Besides that I added one of those cool thermal printers, so I can print out the actual lap time and total time.
To display the time and lap count I use these large Adafruit (i2c controlled) 7 segment display.
The frame is constructed by Makerbeam components.
Step 1: Putting Everything Together
We (Me and Levi(13)) build a basic A frame out of makerbeams, using the 45 degrees brackets to create a self standing structure.
To mount the LCD panels, button face plate (created out of 2mm Aluminum plate on my CNC) and arduino to the makerbeam we use M3 spacers which are threaded on both sides, allowing us to easily screw everything together. If you do not happen to have a CNC machine, you can of course 3D print a face plate or just cut something out of thick carton.
In the back we create a simple rectangle out of makerbeam to tightly fit the Thermal printer. and we use some brackets as holders for our LiPo Battery.
The Arduino with an protoboard are mounted on the back.
Step 2: Connecting All the Electronics
The buttons are connected with 10K resistors, this is then connected to ground and an Analog port on the arduino. This allows you to easily connect multiple buttons to a single port on the arduino. If the 3rd button is pressed it has to travel thru 3x 10K resitor, based on the the analog value changes depending on how many resistors are traveled thru.
7 Segment Display:
I am using the large Adafruit 7 Segment displays with I2C backback, I2C allows you to connect multiple devices on a 2-wire communication network. Each I2C device does need an unique address! Out-of-the-box each adafruit 7 segment display has the SAME address, so you need to solder one of the address pins on the 7 segment display to make sure each display has a different address.
For power I am using a 11.2 Volt LiPo battery, which easily can power the arduino, printer and sensors for a long time. Different components use different power. The light bridge need 12volt, so it is directly connected to the battery. The thermal printer want power between 5 and 9 volt. I am using a step down power module to convert the LiPo power to 8 volt. This is then supplied to the raspberry and (via the VIN port) to the thermal printer.
I have placed a switch between the battery and all the electronics, so I can easily turn everything on / off.
I am using one of those cool thermal printers from sparkfun. They connect via Serial, as I want to leave the hardware serial port for debugging, I am connecting it so pin 2/3 and using software based serial. (so no real UART is used).
Infrared Light Bridge:
I am using a Velleman PEM 10D, infra red light bridge. I used an infrared transmitter and received in the box and an external reflector. If you do not want to buy this sensor, you can create a "light bridge" in many other ways. One could be an light diode or infrared receiver LED and point a battery powered laser pointer at it.
Step 3: The Software
Enclosed is the Arduino software code I wrote for my Laptimer.
Just load this in the Arduino software, make sure you have set the correct Arduino board for your setup and configure the varianbles in the top of the code if needed.
When you run the software, it has 2 "Modes".
- Race mode: This is started by clicking the left "race" button. This will start the laptimer. It uses a "flying start" principle. So there is no count down, just start racing, when the first time you cross the line, the timer will start. It will display the amount of laps still to go on the top 7 Segment display and the time on the 2nd 7 segment display.
-Setup mode: When you click on the "menu", 2nd button, you can setup how many laps you want to race. By turning the pot-meter you can select between 1 and 9 laps.
In the code you will find the variable int clockSync = 7600;
This variable allows you to calibrate the time. If you find that the laptimer runs too fast, increase the number a little bit, if you find the timer runs to slow decrease the number :-)
An other important variable is the int minLaptime = 1000;
This variable is used to make sure then when you trip the sensor it can not directly be tripped again, thinking you have finished. By default the minimum time is 10 seconds (1000 milliseconds). If you racing something that will go faster then 10 seconds, you will need to decrease this minLapTime variable.
Feel free to modify / copy / distribute the code in any form or shape you like.
Step 4: Use Cases
So what can you use this lap timer for.... well anything when you want to be competitive without directly racing another person.
We have use it for our crazy cart, running and cycling around the house...
As long as you position the light brige sensor correctly, you can have a lot of competitive fun! The sensing range of the PEM10D is 10 Meters (33 feet), so you can really have a big start/top line.
Have fun racing!!!