SlotCarDuino : Slot Car Racing Lap Timer

SlotCarDuino : Create a lap timing system. Minutes, Seconds, tenths of a second to be displayed with 7-segment LED digits. Race starter lights being an optional extra.

Here’s how it turned out :


Read more after the break…

Why ?

For Christmas 2009, as part of the fund-raising activities, the local school holds a fair in which games are played, gifts purchased, face-painting, tumbola … etc. You must know the thing. Lots of noise, kids spending pocket-money on sweets … etc. Overall, it’s a fairly-large fund-raiser for things like extra musical instruments, or extra nice-to-have facilities at the school.

Why write about this here ? Well, Mrs techcobweb and I have been asked to create a game based on slot-car racing. Set up a track, charge for a go racing the cars around our track. The idea is to time the laps, and record “top-gear style” the best times. Best lap time from 3 laps or so. Prizes for the best in age-range (keys stage 1, key stage 2 and “the rest”).

The hope is that competition to be the best will spur people to play multiple times to get their lap time higher up on the score-board, thus earning the school association more cash.

I want to accurately time laps, so I need something cool to do it. I didn’t want to buy any commercially-available timing unit specifically designed for the purpose, that’s too easy, no fun at all, and I wouldn’t learn anything as a result.

Instead, I thought I’d use it as another excuse to learn some more about simple electronics.

First thing, make some decisions to limit the scope of the project :

  • I’d ignore the “digital” scalextric system. We would not allow cars to switch lanes, so I only need to detect whether a car passes in a certain lane, rather than which car passed in which lane.
  • I’d use an infra-red beam, mounted vertically,  which is broken by a car passing the finish-line to detect the start/end of laps.
  • I’d use an arduino board as the microprocessor (or freeduino in this case, as I had one already).

Step 1 : Infra-red beam breakage

I got hold of a simple IR detector, and IR-emitting LED. Put a current through the detector, and read the voltage it lets through using analogRead() on the arduino, and you can tell if the IR light beam is intact or not.

Tip : You can’t see an IR beam with the naked eye, but if you use your mobile camera, where you can see a preview of what you’re pointing at, you can see it.

The IR emitters need to be always-on. So they only need a ground and +5v connection, and a resistor. I used a 55ohm resistor for this, safe enough I hope given the data sheet for the emitters.

These are mounted in a “gantry” above the track surface.


The track I used was one piece from the 2-piece pack of track interchange. It seems that scalextric track changed from the old system to the new system of connecting stretches of track together about 4 years ago. My thinking was that if I did the electronics timers in one of these pieces, then it can be connected to the old or the new track systems.

IR detectors are mounted on a small piece of vero board beneath holes cut into the track surface. I was surprised how soft the track was to cut, so I could do it easily with a simple craft knife.


The detector cable from the IR sensor plugs into an analog pin on the arduino. High readings when there is lots of IR light around, low when the car passes bye. Of course, everything is doubled-up to allow timing for two lanes of racing traffic. Software wise, I found that a single reading is not highly reliable, so I ended up taking the last 3 readings and averaging them to get the value to use.

Step 2 :Race starter lights

These are bi-color red-green LEDs, 2 anodes (one for each colour), and a common cathode. 2 wires connect these to digital pins on the arduino so they can be switched red, green or off on demand.


The lights themselves are then mounted in the same gantry ducting that houses the IR-beam emitters.

Step 3 : LED segments showing the timers

The “arduino playground” has lots written about how to control 7-segment LEDs. After reading these, it looked like Maxim 7219 chips would do what I wanted. Couldn’t find any suppliers except RS Components. They have fairly high delivery rates, but as I couldn’t find that part anywhere else there was little choice.

The LEDs themselves and all other parts came from BitsBox, an excellent site which only charges £1.50 per order.

Laying out a breadboard circuit using the 7219 chip, and 8 digits of 7-segment LEDs wasn’t easy. It took nearly 2 hours to cut all the wire and “weave” it together. By far the most complex things I’ve done electronically so far. Anyway, it seemed to work. I used a simple sketch to show the time since the board was last reset.


This amount of wires took 2 hours to lay out neatly on the breadboard. More like sewing than anything I’ve done since I made a cushion cover at school.

Step 4 : Software, controlling inputs and outputs

Now things are getting exciting. Connecting together the input sensors with the output starter-lights on the gantry and the two 4-digit timers was straightforward. I added a switch to control the selection of “numbers of laps”, “number of players”, and “which lane if there is only one player”, then I needed to write some code to control it all.

As I’m not using interrupts to latch the detection of a broken beam, I need all the code to be non-blocking. The libraries available on the arduino site contain Finite State Machine, and Scheduler, LedControl, Button and LED, all of which are useful for the programming.

After finding a bug in the FSM (Finite State Machine) library I was delighted when the author provided a fix overnight ! (Thanks Alexander Brevig).

Step 5 : Switches and software control

  • I opted for 3 switches. Reset (to reset the arduino), Select and Mode.
  • The reset switch needs to connected to the Reset line at one end, and the ground at the other. Couldn’t find that written anywhere in the arduino forums. Maybe it’s just obvious to most, but it wasn’t to me, so took some experimenting.
  • The other two switches are mounted on a piece of wood, connected to +5 via a 20kOhm resistor at one end, with the connection to the input pin to the arduino at that end of the switch, with ground on the other pole of the switch.
  • ie: A pull-up resistor. Someone said that a 20k creates less power drain than a 10k, so I thought I’d try that.
  • When the software uses this, it also enables the in-built 20k resistor in the arduino hardware.
  • Both the Select and Mode switches are de-bounced using the Button library.


Step 6 : Complete the software

At this point, I had little sketches to exercise all the small pieces of the solution. Now it’s time to pull it all together.

I created a state machine, which had a few states :

1. Setup number of laps state

  • Select button adds a lap to the lap count, wrapps from 9 to 1.
  • Mode button moves to state 2.

2. Setup number of players and lane used state

  • Select button toggles between:
    – 2 players, both laps
    – 1 player, left lap
    – 1 player, right lap.
  • Mode button switches to state 3

3. Start race mode

  • Flash the red starter-light LED on for a second, then off. for a second. Display “3” on all digits of all timers.
  • Do it again, using a “2”
  • Do it again, using a “1”
  • Blank the timer screens
  • Put the green “go” lights on.
  • Schedule an event to turn the green light off a bit later, regardless of our state.
  • Move to state 4.

4. Timing the race.

  • Collect lap-times for each lane.
  • When all lanes in use for this race has finished, move to state 5

5. Display the best lap time above each lane in use. Flash this on-off with a second frequency, so the user knows it’s the overall best lap time, rather than just the last one.

  • Mode button moves to state 1, so the whole race can start again.

So after a while getting this code nearly right, I was able to throw a post-it note through each lane to pretend that a car was passing over the lane.


Here is the arduino sketch : scalextric_lap_timer_sketch_v1t

Step 7 : First complete physical fitting

  • Soldering together a “timer gantry”. I found a piece of plastic “cable shield” was once again useful here. I could just about get a row of LED digits within the channel inside the shielding. It’s sticky-backed, so could easily be added to the original lighting gantry.
  • Creating the switch frame, soldering the wires to the central circuit board.
  • Soldering-together the central circuit-board, which collects all/most of the wires from the board.
  • Fasten the arduino to the board, using risers which accept a screw at both ends.
  • Attach the battery to the board, using a Velcro pad. Solder the batter connector to a power plug. (2.2mm, +ve is central terminal).

Step 8 : Hiding the gawp

Add some structure to fill-out the board a bit


Decorate with some “stone wall” features from a previous “plaster mould” project



Cover the electronics kit in a plastic bag for protection of what’s coming up…


Get some raw materials together :


office shreddings, placed on top of the structure, on which strips Mod-rock plaster is placed.





Paint matt black :



Then “dry brush” with grey, then white :



Then add some grassy bits :









Finished !



Parts List :

  • 3 x switches
  • 4 x 3mm red LEDs
  • 1 x ??uj capacitor
  • 1 x ??nj capacitor
  • 1 x maxim 7219 c?? chip
  • 1 x 16-pin integrated circuit mount
  • 1 x 8-pin integrated circuit mount
  • 2 x IR emitters
  • 2 x IR receivers
  • 1 x freeduino
  • 2-3m wire
  • 10cm x 12cm vero board to cut up
  • 1 x 2.2mm power jack
  • 60mm of cable ducting
  • oddments of wood
  • 30cm x 30cm hardboard base
  • a dozen or so screws
  • wood glue
  • plaster


Someone asked me “how do you know it’ll detect actual cars given that you’ve never hooked it up to a track before”. Well, I wrote a test program which counts how many sensor readings are taken as an object passed over the sensors. Then it got reported over serial. I found I could flick a post-it note through the gantry and have sixty readings as it flew past. Flicking a pencil as fast as I could (width-wise) registered a “broken beam” for 10 readings. So I figured as a car was longer, it would register as breaking the beam for much longer.

I finally got someone to come over and set some track up. A slot car running at full-speed (via a very long straight) registered the beam as being broken for 140 readings.

So I now know it works, and will not be too slow for a car to pass through without being detected.

Battery Consumption

It doesn’t seem to run for long with a standard 9v battery, as wierd things start to happen (lanes don’t register beam breakage). It’s fine to start with, but when the battery voltage drops to 7.2v the display driver stops working. I’ll use a wall-plug on the day I think, which isn’t a problem, as the scalextric needs a plug anyway.


204 solder joints. Whew !

Estimated cost of around £38. Which is more expensive than the official £26 retail version, but loads better than a small LCD screen, and this one does exactly what we want, and doesn’t look “plastic”…etc.

I enjoyed the hardware debugging phase a fair bit. Learned a bit more about capacitors, wiring layout, physical mounting.

The code I wrote is a mess. Need to get back into C++ to make it more object-oriented instead of using arrays.

Great fun building it.

I’ll update this post with feedback from when it gets used for real.

Post-script : How did it work on the actual event ?

So December came, and the weekend of the school fair arrived. Up fresh and early, with a car full of borrowed track we headed to the school. (No pictures as I didn’t think to get many, and I don’t want to show kids’ faces without permission..etc).

We weren’t short of helpers putting the track together. All the over-30’s were getting misty-eyed at the sight of the old-style cars. All the youngsters just wanted to see the biggest track most of them had ever had a race on.

All the help was rewarded with more “test laps” than absolutely necessary. The track itself had about a 10-second lap time with new magnet-enabled, can hardly drive them too fast off the corners, about 20 seconds with older non-magnet cars. Given that we had a selection of borrowed cars available, I tried them all. I found that the new cars are really dull/boring. They don’t come off easily enough. Completing a lap without skidding off wasn’t the challenge I remember from my 10-year-old days. I tried all the cars from the vintage mini, audi quatro, porche 9-11 and some tyrell F1 car. The most fun was had with these older cars. Get the speed just right, and the back would swing-out and you could “drift” around the corners, power-sliding all the way.

Then the crowds arrived.

It wasn’t long before I was grateful for the new cars. Because they didn’t come off the track very often we didn’t need a legion of helpers to recover cars from crash sites.

Practical point : We should have put a lower-age limit on the stand. When kids too small to understand the difference between “full-on” and “gently squeezed” had the controls every corner was accident-city. Putting crash barrier on the outside of all of the corners really paid off. Another thing we did was to race red and blue cars. We put red/blue stickers around the track so helpers could tell which lane to put cars onto when they came off. This is sometimes confusing, and can lead to situations where 2 cars are on the same lane or the wrong car passing under the gantry in the wrong lane (giving that lane owner a really great time!).

The “driver registration” process on the stand took ages. If anyone does this where the budget is higher, get yourself some RFID detector to register your driver with the machine. Sometimes the track was idle while we took driver details. Eventually we got it sorted.

Overall, the timer worked well. Some glitches (there must be some bugs still left in the code), but overall it worked.

The stall required loads of effort to keep it running, so it was really hard work continuously. As a result I was glad when the call went out to clear up.

I have no idea how much money was made. Not much. Lucky if we covered the cost of the prizes for “best lap time in age-group”. But it was hugely fun, and kids (pre-teens and 30+’s alike) said what a great success it was.

I’ve since been blamed for several kids demanding slot-car sets for Christmas. Especially with the James May “toy stories” episode on slot-cars nearly coinciding with the event. Shame none of them will get a lap timer like this !

Whew !  Wonder what we’ll need for the next event !

This entry was posted in Electronics and tagged , , , . Bookmark the permalink.

25 Responses to SlotCarDuino : Slot Car Racing Lap Timer

  1. Lou says:

    Cripes, you’ve been busy!

  2. dmt195 says:

    Great idea and well executed! Well done. A really good job. Is it used much?!

  3. Ron Carter says:

    Cool!! I am into slot cars and just getting into arduino based autopilots via Diydrones. This seems like a much more ambitious project than the drones. I might give it a try this winter.

    Thanks for putting it out here.

  4. Pingback: Home Easy Hacking Wiki « Notes from a small field

  5. Johnzy says:

    I working towards building this same project and trying to add the ability for the Arduino to drive the cars. I would like to record the best lap times and have the Arduino replicate the best runs. I think this could work if there were sensors at all the corners. With a little/a lot of extra work you could create some intelligent logic to drive an opponent car for solo races.

    Then there’s going to be an online database with a complete list of drivers and their best laps and track records …… and of course big screen TV’s, smoke and lasers and millions of viewers weekly and ……..

    “Dreamer, you know you are a dreamer
    Well can you put your hands in your head, oh no!”

    I’m am actually kind of green at all of this right now so I am still striving to make it half as far as you. Thanks for sharing. Really nice work!! Mega bonus points for the kick ass job you did of dressing it up!

    • techcobweb says:

      Johnzy, that sounds very ambitious, but possible if you do it in stages.
      I’m fairly green at electronics myself, but if you prototype every stage, and ask others for help when you get stuck it seems easy enough.

      Something based on this perhaps ? :

      It’s complete overkill for what I need at the school next month, but tempting to try…
      I think you’re right about needing sensors at various points on the track, to guide the u-controller when the car should speed up…etc. But that means a fixed track layout.

      Maybe some arduino which “learns” how fast it can go between section markers without flying off… calculating maximums for each section based on successive failures to beat the time it managed between 2 markers in the previous laps…

      These chaps mounted the arduino on a car with an accelerometer…
      Seems the wrong approach as it’s invasive on the cars, and adds weight…

      If I were doing this again, I might try measuring the cars from the sides, horizontally, with a reflective strip between lanes. When the car passes = no reflection…etc. Then the strip and stations at the side can be moved, and no need to cut holes in track..etc.

      Perhaps adding huge traffic lights based on this : (I have one ready for a future project, after seeing James post it).

      I also really like the idea of strapping a camera onto the car and taking a movie as it speeds around the track too. May post that if I get it going. With a camera-phone should be possible…

      Post a link back to me when you have it all working ! Good luck.

  6. Pingback: Ed's World » Blog Archive » Scout racing lights – naturally arduino powered!

  7. Dave Nice says:


    I’ve had a go with a friend at making something similar but less ambitious in terms of papier-mache etc!

    Instead of breaking an infra-red beam, we used reed switches from cycle computer detectors to watch the magnets come past.

    We did struggle with the magnets not triggering the arduino for long enough – the magnets are a lot shorter than the cars and the reed switch only trigger while the magnet’s directly over it.

    You say the infra-red being triggered 140 times for a car going over. That should easily be enough for me to detect the magnet – I wonder were you sleeping in between detections or in a tight loop?

    I think I need to investigate the interrupt function!

    Good work on a nice project.


    • techcobweb says:

      I used a regular arduino loop, and the only blocking I/O going on were serial write operations to the LED segment controller. See the code here.
      I decided that as I was getting so many readings while the car went over that I wouldn’t miss a car passing event. That’s why I didn’t explore the interrupt-driven approach.

      The interrupt features allow you to hook the rising edge of a pin, which can store an event in memory, so that the next time around your main non-interrupt loop you can detect that the event has occurred. Best of luck with that. Post a link to your project when you’re done ?

  8. Josh says:

    Nice project! I’ve tinkered with Arduinos for a while, and my kids just got a slot car system for the holidays, and I’ve been scheming ways to ‘improve’ it :).

    Ultimately I’d like to do what Johnzy mentioned in an earlier comment, and have the MCU driving the car. That’s seems awfully challenging, though, and so I started looking at lap-counting, speed detection, or timed action photos as starter projects.

    I wonder: did you consider mounting the IR horizontally with some sort of divider in the middle of the track (to hold the detector)? I’m not sure that offers any advantages over your approach, I’m just curious.

    Great job making this look nice — really impressive.


    • techcobweb says:

      Cool that you’ve your kids have a new toy 😉

      I didn’t consider the horizontal mounting angle no. It should make absolutely no difference that it’s horizontal rather than vertical mounting. Then you don’t need to doctor any track, and can put as many “timing gates” on the circuit as you want.

      I didn’t have any cars to check the gap between them. What is the clearance between-cars ?

      Interested to know how you get on. Go for it.

  9. Hi I’ve done a similar thing, but using a proximity sensor (more expensive than your version)! It currently only reliably records for one track.
    You can see the first proof of concept at . I have parts on order to output info to LCD screen rather than 7 segment displays, and to build a cut down arduino on stripboard so I don’t end up without my prototyping arduino!
    I love your enclosure, I hadn’t thought to model the timer into a piece of track, but one of the things I’d liked about my plans was that it could just be in any box that you could slide alongside any piece of track on any circuit.
    I’m slightly disappointed that someone has done this before me, and with a far better execution than mine will be – I suck at craft/modelling stuff!

    Anyway, pleased I found you project as you’ve given me some additional ideas and food for thought! Nice work!

  10. Pingback: » Blog Archive » Arduino + Scalextric = lap counter

  11. weldo says:

    What’s an ODT document? I thought Arduino sketches ended in PDE?

    • techcobweb says:

      It’s an open document text format, an OpenOffice document. I think MS Word can open it too.
      I used tabs in the arduino IDE, so there are several different files involved. I created a document to put the source into so I could add license information …etc.
      Easy enough to copy-paste if you need to I thought. Get back if you can’t read and I’ll convert to PDF.

      I’ve since given-up on that IDE, and switched to using Eclipse for various reasons, including the way it handles header files…etc.

  12. slot cars says:

    This is the sort of tenacious slot car wizzardry we love to see, good work!

  13. bilt says:

    Looks really well made, i wish i could make something like that…

  14. Ameen Padhiar says:

    me also designing the same project i got lot of help from yours

  15. James McLain says:

    Killer job. I’m very impressed.

  16. Pingback: Slot Car Racing | Digital Fanatics

  17. Nick says:

    G’day From down under techcobweb. I have replicated your project, and I am finding that the buttons will not get detected. I can see the program gets to that part of the program but it does not detect the change of state in any of the buttons? Is there a bug or am I missing something?


    • Nick says:

      Forgot to mention that I am compiling the code under Ardunio 1.0

    • Nick says:

      Found a fix. It seems that the Debounce lib is different to bounce lib. So the program will not recognise the switch inputs with bounce. you will need to use Debounce. Once I work out the difference I share but for now this is the solution if anyone else is having dramas.

      • Nick says:

        Bounce::Bounce(uint8_t pin,unsigned long interval_millis)
        Debounce::Debounce(unsigned long interval_millis, uint8_t pin)
        Now who would of thought they changed the veriables about.

  18. Pingback: SlotCarDuino – Slot Car Racing Lap Timer « freetronicsblog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s