Microcontrollers are great at blinking LEDs and reading sensors.  With that in mind, I built this simple electronic finish line so that my 5 year-old son could easily see which of his hot wheels finished first.

Note: I've found some improvements since I wrote this: use an IR emitter/detector pair with a higher resistance on the detector (330K ohms instead of 56K ohms).  Also, A "mini" arduino should work just fine -- the adafruit.com "Trinket" for example.

   - First place displayed
   - Ties displayed
   - Automatic reset
   - Easy operation and reading
   - 20 microsecond accuracy

With some basic soldering skills and woodworking skills, you should be able to complete this build in only a few evenings.

Step 1: Materials and Tools Needed

Major Components:
1 - Arduino (any arduino compatible) -- Adafruit .com has a very inexpensive (about $8) mini-arduino called the "Trinket"  that should work just fine (I haven't tried it yet).  This design should work with 5 volt or 3 volt arduinos -- in some ways, 3 volts is better (less power)
2 - 56K 330K ohm resistors (1/4 watt) [I have found that IR photosensors need higher ohm resistors (for more sensitivity)]
2 - 330 ohm resistors (1/4 watt) (or 4, if using IR emitter leds).
2 - LEDs (red, green, blue, you choose!)
2 - IR Phototransistors (Radio Shack #276-0145)  or Radio Shack #276-0142: Emitter & Detector pair (the emitter can be setup on a "bridge" pointing down at the detector, to make the detector work better.)  If you do use the IR emitter leds, wire them up to your battery, or input power, with a 330 ohm resister in series (like on the red leds).
1 - 9 volt battery and adapter for arduino

Additional Materials:
- Wire
- Shrink tubing
- Small wood screws - 3/8 inch long (x6)
- Small washers (x8)
- 1/2 x 6 x 10 inch board used as a base (I used oak, but could be any wood)
- Self adhesive felt feet (x4)
- Cardboard / Poster board
- Packing tape
- Hot Wheels track and track connectors

- Soldering Iron
- Wire cutters/strippers
- Drill and drill bits
- Screw driver
- Manual Staple gun
- Scissors
- Pencil
- Tape measure

Step 2: Source Code

// This is the arduino sketch: Open the arduino IDE,
// create a new file and copy/paste the following code into it.
// Don't forget to upload the code to your arduino!

* Finish Line Detector
* Lights up LED 1 or 2 depending on which sensor is tripped first
* Both LEDs light up in the case of a tie
* Accuracy:
* As there are only a few lines of code in the loop
* (actually more instructions after it gets compiled) and considering
* that the arduino runs at 16Mhz (million cycles per second),
* we have an accuracy much better than a millisecond.
* With an oscilloscope, I determined that the code actually takes about
* 20 microseconds to execute. Should be good enough.
* Author: Ted Meyers - February 2, 2011

const int ledPin1 = 12;
const int ledPin2 = 13;
const int sensorPin1 = 2;
const int sensorPin2 = 3;
const int TIMEOUT = 3000; // milliseconds

// Setup runs once, at start
// Input and Output pins are set
void setup(){
   pinMode(sensorPin1, INPUT);
   pinMode(sensorPin2, INPUT);
   pinMode(ledPin1, OUTPUT);
   pinMode(ledPin2, OUTPUT);

// Called repeatedly
void loop() {
   // Get the Sensor status
   int status1 = digitalRead(sensorPin1);
   int status2 = digitalRead(sensorPin2);

   // Set the output LED to match the sensor
   digitalWrite(ledPin1, status1);
   digitalWrite(ledPin2, status2);

   if (status1 == HIGH || status2 == HIGH) {
      // A sensor was tripped, show the results until timeout
      delay(TIMEOUT); // Wait for timeout

Step 3: Build the Base

You will want to start with a board about 1/2 x 6 x 10 inches; the dimensions don't have to be exact.  Cut the board to size if needed.

Make a line about  1.5 inches parallel to the long end for placing the holes for the 2 sensors and 2 LEDs.  For the track I used, the sensors need to be 1.75 inches apart, mark these positions.  Next mark the positions for the LEDs about 1.25 inches out from the sensors.  Next draw the center lines for the two track lanes going through the sensor marks and perpendicular to the long side of the board.  These lines will be used when mounting the track connector piece.  While not necessary, I also marked lines to show where the track is placed.

The last hole is for the wires to go through to the bottom of the board.  It's placement is not critical, just as long as it is not in the way.

Drill the holes.  For the sensors, drill a 1/4 inch hole about half way though the bottom, and a 5/32 inch hole the rest of the way (this keeps the sensor from going all the way through from the bottom to the top, and also lets less light come in from the side).  For the other 3 holes, drill a 1/4 inch hole all the way through (if you want, drill a larger hole for the wires, it will make it easier to push them through later on).

Step 4: Schematic

Note: I've found that a higher resistance makes the IR sensors more sensitive, I am now recommending 330K ohm resistors here.

It's a fairly simple circuit, I did not use a circuit board, just soldered the sensors/LEDs to wires along with the resistors and soldered the wires together as shown.  Start by soldering long wires to the sensors and LEDs.  Now solder in the resistors and the rest of the wires (power, ground, signals).  Just make sure the wires are all long enough.   Next place the LEDs/sensors in the mounting holes in the bottom of the base built in the previous step, and push the wires through the wiring hole to the top.

Finally, plug the wires into the appropriate pins on the arduino, and test it out.  (You may have to almost completely cover the sensors to block enough light to trigger them.

Step 5: Mount Components to Base

Put the LEDs and sensors in their holes in the base (underneath).  Bend the wires flat to the base and staple in place.  Be careful not to put a staple through any wires.  Push the wires through the hole to the topside of the base.

Turn the base over and staple the wires in place on the top.

Finally, plug the wires into the arduino and test.

Step 6: Finishing Up

Stick on felt feet to the corners of the bottom of the base.

Cut a piece of cardboard or poster board to cover the wiring and tape it in place to bottom of base.

Turn  the base right side up and use the center lines marked in step 3 to position the 2 track connectors and make marks for the screw holes using the existing holes in the connectors.  Drill the holes for the screws (using a drill bit slightly smaller than the screws).

Screw the track connectors in place, putting two small washers between the base and track connector under each screw (for spacing).

Use 2 of the mounting holes in the arduino to make marks on the base for screw holes.  Drill the two holes (again with a smaller drill bit than the wood screws).  Finally screw the arduino to the base.

Attach some hot wheels track to the connectors on the base and you are done!

Step 7: Usage

The track works best when directly under an infrared light source.  Any incandescent light will do just fine.  If the finish line triggers on it's own, you will need to reposition your light and/or finish line, or get a brighter light.

Try to set up the track so that both lanes are at an equal height and slope.

After each race, the timer will display the results for 3 seconds and then automatically reset.

When you get tired of racing, try modifying it to send the difference in time between the two lanes to the computer over the serial port.  Another fun modification would be to use the two sensors to calculate the speed of one car.  Good Luck!

Hope you have as much fun as we did!

<p>Looks like a great project and I'm giving it my best. However, every time I try and load the sketch to my Arduino uno or my nano I get the same response. An error msg. I can load the basic sample sketches like BLINK etc. whithout any problems. I can copy&amp;paste the error msg here if that will help.</p>
Yes, send me the error message. Could be that the newer Arduino versions aren't compatible with this old sketch. I'm good at debugging this type of problem.
This looks like a great project and very detailed. Has anyone tried scaling this up to 4 or 6 lanes and been successful and have a sketch they could share? Thanks
<p>Is it easy to scale up to 6 lanes? I am an electronics newb, so any assist would be amazing.</p>
<p>One more point, eventually you will run out of input/output pins on your arduino if you try to scale up too much (you will need 1 input and 1 output per lane). But 6 lanes is fine for most arduino boards (you typically have 14 digital pins plus the 6 analog pins can also be used).</p>
<p>Yes,6 lanes is just like make 2 - 3 times more. Although if you are new to electronics it can be frustrating and you might want to build two lanes before trying something more ambitious.</p>
<p>Hi I tried making this project with regular photoresistors that came with my arduino kit so i went to radio shack and got the emmitter and reciver pair so two questions one do you need multiple emitters or can I use one for multiple recievers? Two do I need to setup the emitter as an LED that is always on or can i just conntect it to power and have it always emitting?</p>
<p>Great build - really enjoyed. One problem. The two phototransistors listed aren't the same. You can see that by comparing the following two specs:</p><p><a href="http://support.radioshack.com/support_supplies/doc32/32130.htm" rel="nofollow">http://support.radioshack.com/support_supplies/doc...</a></p><p><a href="http://www.radioshack.com/product/index.jsp?productId=2049723" rel="nofollow">http://www.radioshack.com/product/index.jsp?produc...</a></p><p>I had luck with the transistor ending in 0145. I'll try and figure out how to make 0142 work. </p>
I was wondering if I can get some advice on a bit of a problem I have with this sketch<br><br>I would like to scale this up to a pine car track - about 4 lanes. My goal is to use it as something the Scouts could contruct themselves so this design is perfect for us.<br><br>I can get the 2 lane version to work very well - I've actually went as far as modding it as a rudimentary lane judge (first place lights first, 2nd place lights after 3 seconds, etc.) <br><br>Where things go awry is when I want to add another lane to the sketch<br><br>I basically added another set of pin definitions for the additonal phototransisitor and led (modelled from what what's coded in the sketch) and assign the phottransistor to pin 4, the LED to pin 11<br><br>When loaded up to the Arduino, the new &quot;lane 3&quot; led stays lit continuously while the first 2 behave normally <br><br>I've checked the photo transister to confirm that it was working normally<br><br>I'm wondering if there's something fundamental here that I'm missing in the code - I was wondering if anyone could offer any suggestions.
Great project idea! My project is actually my proof of concept first step towards building a pinewood derby lane judge. (I really need to get started on that project, again.) I was thinking of using blinking LEDs to show second and third place.<br><br>Anyway, for your problem, I suspect it is just a bug in your sketch, as the additional lane sensor and LED should be no problem (sometimes simple things can be really hard to catch, I've been there). I could help you a lot better if you were to send me a copy of your sketch. If you don't mind, go ahead and email me your sketch.<br><br>Ted
Thanks!<br><br>Here's the sketch so far - like I said, I'm just replicating what's already in place - right now LED 1 and 2 are just being looked at - 3rd lane LED still lights continous, but it won't impact the logic on the 2 lanes (it does go wierd when I put the 3rd LED in the if statement, obviously) <br><br> const int ledPin1 = 12;<br> const int ledPin2 = 13;<br> const int ledPin3 = 11;<br> const int sensorPin1 = 2;<br> const int sensorPin2 = 3;<br> const int sensorPin3 = 4;<br> const int TIMEOUT = 2000; // milliseconds<br> <br>// Setup runs once, at start<br> // Input and Output pins are set<br> void setup(){<br> pinMode(sensorPin1, INPUT);<br> pinMode(sensorPin2, INPUT);<br> pinMode(sensorPin3, INPUT);<br> pinMode(ledPin1, OUTPUT);<br> pinMode(ledPin2, OUTPUT);<br> pinMode(ledPin3, OUTPUT);<br> }<br> <br>// Called repeatedly<br> void loop() {<br> // Get the Sensor status<br> int status1 = digitalRead(sensorPin1);<br> int status2 = digitalRead(sensorPin2);<br> int status3 = digitalRead(sensorPin3);<br> <br> // Set the output LED to match the sensor<br> digitalWrite(ledPin1, status1);<br> digitalWrite(ledPin2, status2);<br> digitalWrite(ledPin3, status3);<br> <br> if (status1 == HIGH || status2 == HIGH) {<br> // A sensor was tripped, show the results until timeout<br> delay(TIMEOUT); // Wait for timeout<br> }<br> <br> if (status1 == HIGH || status2 == HIGH) {<br> // A sensor was tripped, show the results until timeout<br> delay(TIMEOUT); // Wait for timeout<br> }<br>}
I can't find anything wrong with your sketch. You might try swapping your lane 3 phototransister input with the lane 1 phototransister and see if you get the same behavior. I can't think of any other reason that what you have shouldn't work, other than the phototransister circuit not working.<br><br>Ted
<br>Thanks to checking that for me Ted <br><br>OK - at least the code seems sound - I'll recheck the components - I may also a try different breadboard - in case there's a short somewhere on it. - At least now I know where to focus<br><br>Thanks for your help - I'll let you know when I get it sorted out. <br><br>
See the text under the picture; it starts with &quot;// This is the arduino sketch&quot; and goes to the last line with &quot;}&quot;. Select all of those lines with the mouse, do a &quot;ctrl-c&quot; (copy).<br>Start the arduino IDE that you downloaded and installed. In the white text area that says something like &quot;sketch_sep 25&quot; at the top, do a &quot;ctrl-v&quot; (paste). This should put the code in the arduino IDE. Now, make sure that your arduino is connected to the computer with a USB cable and press the &quot;upload&quot; button -- it kind of looks like this: &quot;[ -&gt; | ]&quot;. The arduino should start blinking, and eventually the IDE will say it has completed. At that point, the arduino is programmed and ready to use.
in what part of the software that i download do i paste this because there's alot of files. like this <br> <br>drivers <br>examples <br>hardware <br>java <br>lib <br>libraries <br>references <br>tools <br>arduino <br>revisions <br>cygconv-2 <br>cygwin1 <br>libus0 <br>rxtxserial <br> <br>in which one of those? <br>
I would suggest that you find a tutorial on arduino and work through it first, before attempting this project; I think that this project may be too advanced for a first arduino project. There are many, many fine arduino tutorials out there. Find one that shows you how to make a blinky LED, that would be a good start.<br><br>LadyAda's tutorial is a good start: http://www.ladyada.net/learn/arduino/
Hey man,<br><br>i was just wondering if this was the exact code you used for your project, as im trying to recreate it but getting not changes and help would be great!<br><br>thanks<br> holmez
Yes, that is exactly the code I used on my project. If you give me some more details about the problem that you are experiencing, I may be able to help.<br><br>Ted
just getting no reactions to the code is uploading fine, i believe my setup is the same as yours but im using a breadboard instead of placing straight into the arduino, i was possibly thinking it was a problem with the phototransistor !??!?!<br><br>holmez
Make sure you are connected to the right pins on the arduino. Also, make sure the phototransistor wires are not connected backwards. Try putting a bright light in front of the sensor when testing. The only other thing I can think of is to try some different resistor values on the resistors connected to the phototransistor, especially if you are using a different phototransistor then the one I used.<br><br>Ted
hi' I'm trying to do this for my son but I don't know how to paste the code to the arduino. I dowload the sofware and i conect the board to the computer but thats all. I conect the phototransistor and I connect a resistor to it and also to the led. but it doesn't do anything. when I connect the led cable to the pin 1 it does turns one but but it doesn't do it on any other. can you please help me.
See the text under the picture; it starts with &quot;// This is the arduino sketch&quot; and goes to the last line with &quot;}&quot;. Select all of those lines with the mouse, do a &quot;ctrl-c&quot; (copy).<br>Start the arduino IDE that you downloaded and installed. In the white text area that says something like &quot;sketch_sep 25&quot; at the top, do a &quot;ctrl-v&quot; (paste). This should put the code in the arduino IDE. Now, make sure that your arduino is connected to the computer with a USB cable and press the &quot;upload&quot; button -- it kind of looks like this: &quot;[ -&gt; | ]&quot;. The arduino should start blinking, and eventually the IDE will say it has completed. At that point, the arduino is programmed and ready to use.

About This Instructable




More by TedMeyers:Robotic Rover Wireless Quiz Game Arduino Controlled Finish Line 
Add instructable to: