Arduino + Scalextric = lap counter

I bought an Arduino board last year and have been playing around with it on and off since.  I’ve had a few ideas for projects but not really got around to completing anything except monitoring my gas meter.

For a few months I’ve been hankering after a scalextric (even before James May’s excellent Toy Stories programme about it) so when a friend invited me round to have a go on his, I jumped at the chance!

I took along my arduino, he dug out a pair of cycle computer sensors and we had a go at hacking together a lap counter. We sellotaped the cycle computer sensors (reed switches) under the track, wired it up, and I wrote a bit of arduino code to poll for a change in voltage and increment the lap count.

The code worked in testing, but once we actually drove the cars round a lot of the laps weren’t registered.  I think the problem was that the magnet in the bottom of the car is quite small and isn’t close to the reed switch for long as the car drives over.  My poll frequency was not high enough to keep up.  The obvious solution was to increase the polling frequency but I’m not massively keen on polling and was keen to investigate arduino interrupts.

The standard arduino has two interrupts that are immediately available (see the arduino documentation).  The arduino comes with pullup resistors built-in for the digital inputs, so I connected the reed switches between the input pins and the ground pin.  Because the reed switch connects the input to ground, I used the FALLING mode of the interrupt.  Again, the arduino documentation explains how to enable the pullup resistors.

At this point a function in the arduino code gets called each time a car drives over the sensor – it’s just a case of writing some code to track the number of laps and the times of each lap. I’ve used Andy’s arduino Nokia LCD library to handle drawing to the screen.

The main problem I’ve had with this project is the reed switches.  First first switch I tried didn’t work correctly, the second switch didn’t seem sensitive enough to trigger reliably – I couldn’t put the switches directly under the centre of the car (I think the metal rails interfered), and having them slightly off centre seemed hit and miss.  I’ve upgraded to some slightly bigger switches which seems to have made things a lot more reliable.  Of course, if your scalextric car doesn’t have magnatraction, it won’t work!

The counter doesn’t look as good as the SlotCarDuino project, I’m not quite as creative on the hardware side, but hasn’t been too hard to put together and hasn’t involved cutting my track up at all 🙂

In terms of ideas for the future, I quite like the idea of publishing laps across the network using my network shield and providing a richer web-based interface.  I plan to add in sound to indicate that a lap has registered and whether it’s a best lap.

4 Comments to “Arduino + Scalextric = lap counter”

  1. Gordon 9 September 2013 at 17:14 #

    Nice write up! I’ve just taken delivery of my first Arduino and coincidentally taken my old Scalextric set down from the loft for my 7yo son to play with so it set me thinking of projects to do with both.

    In an even bigger coincidence I yesterday removed a cycle computer from an old bike so I’m (almost) all set!

    I’ll blog if I get it to work 🙂

  2. Dave Nice 10 September 2013 at 18:08 #

    Brilliant that you found it useful. Definitely give it a go, it’s a good intro to using the Arduino and fun to boot 🙂 And I’d love to see a blog post if you get round to it.

  3. TomRigby 5 April 2016 at 19:57 #

    I am using a reed switch for a project I am doing, where I pedal and the car movs. I want to register laps and have has some success. However when I cycle fast, the reed switch must be picking up an electromagnetic field because it is registering laps when the car is nowhere near! Do not know what to do!

  4. Dave Nice 16 April 2016 at 08:30 #

    Hey,

    You could try shielding the reed switch with some grounded metal? Need to be careful not to short circuit anything though!


Leave a Reply