What you build
A timer for a two-lane track. Both cars are staged in their start beams, the starter presses START, the tree counts down, and on green the cars go. The timer catches every jump start, times each lane to the thousandth of a second, prints a drag strip time slip and, in derby mode, runs four cars over four heats and crowns a champion.
- Four light gates: slotted photo interrupters, a start and a finish for each lane, on pins 2 to 5. Click the card beside a gate to push a car into its beam.
- START: an arcade button on pin 6.
- The tree: a red, yellow and green signal head on A0 to A2.
- Sound: an active buzzer on pin 7.
- The screen: a 20x4 character LCD with an I2C backpack at 0x27, on A4 and A5.
- The brain: an Arduino Uno.
How it works
Blocked is HIGH. Each gate shines infrared across a slot at a phototransistor. Light gets through and S reads LOW; a car cuts the beam and the board's pull-up takes S HIGH. The sketch watches for the moment each gate changes.
A clock that never waits. At green the sketch saves micros(), and a lane's time is the moment its finish beam is first cut, minus that. The loop has no delay() anywhere, so every gate is looked at thousands of times a second and a beam is seen within microseconds. micros() counts in steps of 4 microseconds, far finer than the millisecond it prints, and the unsigned subtraction stays right when the counter wraps.
A drag strip time slip. Every clean lane gets three numbers:
| Number | From | To | What it measures |
|---|---|---|---|
| Reaction | Green | Leaving the start beam | The driver |
| ET | Leaving the start beam | The finish beam | The car |
| Total | Green | The finish beam | What wins the race |
A car that leaves before green gets a red light and cannot win. Because the race is won on total, a quicker start can beat a quicker car: a holeshot.
Fair rules, chosen first. Two times less than a millisecond apart are a dead heat. A car not in after 6 seconds is a DNF. In derby mode every car runs once in each lane and its two times are added, because one lane is always a little faster and swapping cancels it out. A false start in a derby re-runs the heat.
The course
Build a race timer gets there in six lessons, all on the same wiring with a new sketch each time:
- Light gates: blocked reads HIGH, edges, and a car's speed from its time in the beam.
- Start signal: staging, three yellows and a green, and reaction time.
- Lane times: two lanes to the millisecond with
micros(), and a DNF. - Places on the display: first, second, the margin and a dead heat, laid out on a 20x4 LCD.
- False starts: red lights, time slips and a win on a holeshot.
- Project: a derby track: four cars, four heats, lanes swapped, a champion, then the real track.
Every step is checked against the running circuit, apart from the last, where you make the derby yours and share it.