Arduino Controlled Finish Line

26,753

27

30

Introduction: Arduino Controlled Finish Line

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.

Features:
   - 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

Tools:
- 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!

Share

    Recommendations

    • Metalworking Contest

      Metalworking Contest
    • Tiny Home Contest

      Tiny Home Contest
    • Fix It! Contest

      Fix It! Contest

    30 Discussions

    hi,im working on this thanks for sharing!

    i have some question...

    1.sorry i messed up is it 330k ohm or 330 ohm?

    2.the photosensor wiring the long feet or the short one on to the ground?

    i will put in on youtube and credits to you after the project is done!

    keep sharing!

    7 replies

    Hi its me again
    Finally i made this!
    And "unluckily" i forgot to powered it off after using for couple of hours and the 9v battery is drained out,i do search some arduino power consumption and how to reduce it,is it okay if i add/use Power Sleep Mode instead Active Mode?,the code written like this

    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

    Does it affect the function?
    I will post everything after the beta version is done,thanks for all contribution!

    Don't know how low-power mode will affect the code, probably depends on where you put it. (I've never tried low-power). Maybe have a check for no activity for a while? Also, you could add a 5V wall power plug to the arduino (instead of battery).

    Thanks for reply!
    Okay thing gets clearer,i didnt use the radioshack because is not available at my country,so i use photoresistor the black glass,looks like the pic that i attach here it says ir receiver 940nm,or can i use this kind of sensor? (picture 2)

    ps. I have an idea maybe you can make a starting gate with red green yellow start gate with sound like in circuit race :p

    IRReceiverF5940nm940_1.jpg.jpgimages (16).jpeg

    The sensor that I used is actually a phototransister. The first picture that you show looks a lot like a phototransistor. The second picture is a photo-resistor, which is much different. You could make it work, but you'd have to change the circuit. Also, photo-resistors are quite slow to react to a change in light; several tens of millisecond, while the phototransistor only takes a few microseconds. So, you timer would not be very accurate if you used a photo-resistor.

    Yes! You could add a starting gate with colored lights, and even sounds. That would be cool!

    Okay i will not use the photoresistor,just for make sure,so the black glass phototransistor is okay to replacing the radioshack sensor that you use?, and the others part is same as the schematic.

    I'm sorry im just try to figure it all in the right place i'm halfway trough this.

    It is hard to tell without looking at the specifics of the components you are trying to use. I believe that 940nm is okay (that is in the infrared spectrum and there was enough ambient infrared when I tested my sensor to get it to work (a room with incandescent bulbs -- or outdoor light works great). Other than that, I really don't know anything about your sensor. You might have to adjust the sensor resistor to get the sensitivity correct. A potentiometer with the right range (0 - a few hundred K ohms is good) works well for this. It is best to just temporarily wire things up to test it. you can always unsolder/cut the wires and resolder if you are careful.

    330K ohms for the sensor resistor. Usually the ground (cathode) is the shorter wire, but it would be best to look at the datasheet for the particular sensor you have (if you can find it). You can also temporarily wire the components together (breadboard, alligator clips, paper clips, whatever) and see which way works. You shouldn't be able to break it, even if you get it backwards -- at least not a photosensor.

    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&paste the error msg here if that will help.

    1 reply

    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

    Is it easy to scale up to 6 lanes? I am an electronics newb, so any assist would be amazing.

    2 replies

    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).

    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.

    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?

    I was wondering if I can get some advice on a bit of a problem I have with this sketch

    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.

    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.)

    Where things go awry is when I want to add another lane to the sketch

    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

    When loaded up to the Arduino, the new "lane 3" led stays lit continuously while the first 2 behave normally

    I've checked the photo transister to confirm that it was working normally

    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.

    3 replies

    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.

    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.

    Ted

    Thanks!

    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)

    const int ledPin1 = 12;
    const int ledPin2 = 13;
    const int ledPin3 = 11;
    const int sensorPin1 = 2;
    const int sensorPin2 = 3;
    const int sensorPin3 = 4;
    const int TIMEOUT = 2000; // milliseconds

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

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

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

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

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

    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.

    Ted