Arduino Laser-based Timing System

31,016

111

35

Introduction: Arduino Laser-based Timing System

As part of my teaching, I needed a system to accurately measure how quickly a model vehicle travelled 10 meters. Initially, I thought I would buy a cheap ready-made system from eBay or Aliexpress, these systems are commonly known as light gates, photo gates or similar. It turned out that pre-built light gate timing systems are actually quite expensive though, so I decided to build my own.

The operation of a light gate timing system is pretty simple. Each light gate consists of a laser module at one side, this projects a laser spot onto a light-dependent resistor module (LDR) at the other side. By measuring the output of the LDR, the system can detect when the laser beam has been broken. Using two of these gates the system starts the timer when the first beam is broken and stops the timer when it senses the second beam has been broken. The resulting recorded time is displayed on the LCD screen.

Building a system such as this with students is a great introduction to coding, it is also a really useful classroom resource once it is finished. This type of system is great for STEM activities and can be used to measure how fast things like rubber band cars, mousetrap cars or pinewood derby cars travel a set distance.

Disclaimer: The solution presented here is far from optimal. I'm aware some things could be a lot better or more efficient. This project was initially put together on a very tight deadline and worked absolutely fine for the purpose intended. I have plans to release both a version 2 and version 3 of this system with improvements, please see the last step of the instructable. Implementation of the circuit and code is at your own risk.

Supplies

  • Arduino R3 (or compatible board) - £4.50
  • Adafruit feather wing protoboard - A small section of any type of protoboard is also fine - £1
  • LCD keypad shield - Ensure this is made to fit the version of the arduino you have - £5
  • 2 x Light Dependent Resistor (LDR) module - Searching ebay for "arduino LDR" should show plenty of options - £2.30 each
  • 2 x Laser module - Searching ebay for "arduino laser" should show plenty of options. Make sure the power of the laser is not greater than 5mW. - £2.25 for three
  • 4 x Small tripod - £3.50 each
  • 4x 1/4 inch nut - To fit a standard tripod thread - £2
  • Clear acrylic for Arduino case £3
  • M3 nuts and bolts - £2
  • Plastic PCD standoffs - Kits of these can be had for quite cheap on Ebay.- £6.80
  • 4 x 3D printed enclosures - Material cost was around £5.
  • Ribbon cable - £5

Total cost was around £55, this assumes access to both a laser cutter and 3D printer. Most of the cost here is for cases, nuts and bolts, etc. the actual cost of the electronics is only £22 so there is probably room for a lot of optimisation here.

Step 1: Program Adrunio

Upload the code below to the Arduino. If you are unfamiliar with how to do this, check out this great instructable.

The basic logic of the code is as follows:

  1. Turn on laser modules and check than each LDR can "see" the laser beam.
  2. Wait until LDR 1 detects a break in the laser beam, immediately start the timer.
  3. Wait until LDR 2 detects a break in the laser beam, immediately stop the timer.
  4. Show the resulting time on the LCD screen in milliseconds.

The code is only designed to time a single run, once the time from the screen has been noted down the reset button on the shield is used to restart the program.

LINK TO ARDUINO CODE

(FYI: The code is hosted on create.arduino.cc and I would love to have embedded the code here, but the Instructables editor doesn't allow the embedded iframe to display or work correctly. If anyone at Instructables is reading this, please implement this as a feature in the future, thanks)

Step 2: 3D Print Enclosures

The laser and LDR modules need to be held in place to ensure that no beam breaks occur as a result of the modules moving. 3D print the enclosures below and bolt the modules in place, the laser module will need to be held in place with a zip tie as it has no thru bolt hole.

Be sure to trap a 1/4 inch nut inside each of the cases, this will be used later to allow these cases to connect to the tripods. The two halves of the enclosure are held together with M3 nuts and bolts.

Step 3: Laser Cut Arduino Case

Laser-cut the files below from the 4mm thick clear acrylic. Line up the arduino R3 and protoboard with the holes on the acrylic pieces and bolt into place. Bolt the top piece of the case to the bottom using the PCD standoffs as spacers.

Step 4: Wire the Circuit

The LCD shield used in this project is explained in detail in this great instructable. The LCD screen and input buttons use some of the arduino's I/O pins however, for this reason all I/O for the laser modules and LDR's use pins 1,2,12 and 13 only.


Very little wiring is needed, but ensure the circuit is connected as shown in the diagram. I added some JST type connectors to the laser and LDR module wires to allow me to easily disassemble and store the entire setup.

Yes, arduino pins 1 and 2 are directly powering the laser modules with no in-line resistor. As the laser modules selected are designed specifically for use with arduino this shouldn't be an issue though. The laser modules draw a maximum power of 5mW, this means that at the 5V supply voltage of the pin, the module should be drawing around 1mA, this is well below the ~40mA limit for current supply on arduino I/O pins.

Step 5: Assemble and Tune

Finally, you are ready to assemble everything.

  1. Mount the LDR and Laser module cases on the small tripods.
  2. Position the Laser modules to shine directly at the LDR sensor

At this stage, you will need to fine-tune things a little. The LDR modules output a digital signal, a high signal (5V) indicating that no laser beam is detected, a low sign (0V) indicating that it can see the laser beam. The light intensity threshold at which the module switches from a 5V to a 0V output signal (and visa versa) is controlled by a potentiometer on the LDR board. You will need to adjust the potentionmeter so that the module switches between a 0V and 5V output when you expect it to.

Either gradually adjust the potentiometer until the system functions as expected, or use a multimeter to measure the LDR module output and tune as required.

Step 6: Operation and Further Work

You should now be ready to use the system! The images show the stages of operation.

  1. Press the select button to initialise the system.
  2. Align the lasers so that they shine directly on the LDR sensor.
  3. The system is now armed. Set you model car going.
  4. The system will start timing once the first laser beam is broken.
  5. The system will stop once the second laser beam is broken.
  6. The time in milliseconds is then displayed on the screen.
  7. Press the reset button to time another run.

I will probably create a version 2.0 of this system as there are some obvious improvements that could be made:

  1. There is no need to power the laser modules from the Arduino, they could be battery powered and simply switched on when needed. When I designed the system, wiring the laser modules to the Arduino for power seemed like the simplest solution, in practice, this results in long cable runs that get in the way.
  2. Condenser lenses are really needed on the LDR housings. Lining the laser dot up exactly with the centre of the (very small) LDR sensor is very tricky and can sometimes take several minutes, using a condenser lens would give the user a much bigger target to aim at with the laser dot.

I'm also now even thinking about a version 3.0 that is fully wireless and just connects to my laptop using Bluetooth, this is a much bigger project for another day, however.

STEM Contest

Runner Up in the
STEM Contest

Be the First to Share

    Recommendations

    • Leather Challenge

      Leather Challenge
    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge
    • Remote Control Contest

      Remote Control Contest

    35 Comments

    0
    JonathanW104
    JonathanW104

    6 months ago

    I hope to do something similar, for bicycles. I have tape switches, so easier than lasers, but I will need to output to a dot matrix printer (and a data logger). Will steal rom ths and other projects.

    0
    Chip Geek
    Chip Geek

    2 years ago

    An idea: You could get by with only 1 laser and 1 detector. Just add 2 mirrors like the below drawing. "/" and "\" are mirrors, "-" and "|" show laser beam path. Car travels from top to bottom of my (very crude) picture.

    /----------- <== Laser at start line pointing to first mirror
    |
    |
    |
    \----------- ==> photo detector on Adruino at finish line

    The first time the detector sees the beam is blocked is the start, the second time is at the finish. This also greatly simplifies the wiring since only the laser needs power (could be battery powered - no wires needed at all).

    For very accurate timing, read the data sheet for the Atmel ATmega328 chip used. Look for "Input Capture" for Timer1, PB0, pin 14, Arduino D8. You can get sub-microsecond timing (not only millisecond for your code). By adding 2 more mirrors, you could also get the velocity at the finish line.

    Contact me if you'd like some help on this. I could write the code for you if you want.

    0
    bpark1000
    bpark1000

    Tip 2 years ago on Step 6

    LDR's are notoriously slow and prone to aging. Better would be photodiodes (small pieces of solar cell will work fine, along with trans-impedance amplifier). Even better is to modulate the beam with a high-speed signal (simple 50% duty square wave is fine) and demodulate that on the other end. This is easy when the same computer is controlling both ends (turn Tx beam on, wait to center of "on" pulse, read Rx output, turn Tx beam off, wait to center of "off" pulse, read Rx output). Subtract the latter reading from the former to get the intensity of the laser beam. Room light is rejected as it will make same reading for both which is cancelled out.
    Use visible laser to make alignment easier (you will need modulatable laser). Put Rx end in a tube to reject room light.

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    Hi. Thanks very much for this. I will certainly consider this approach on future projects. I think the ultimate aim with this is to make all sensors and Tx sources wireless using nrf24l01 modules, would synchronising the modulated signals at Tx and Rx still be possible in this case? Or would a different approach be a better bet?

    0
    bpark1000
    bpark1000

    Reply 2 years ago

    So you are going to send the received optical signal over an RF link? That will impose uncertain delay. Both ends will need wires anyway for power! If you object to wires crossing field, use optical retro-reflector (bike reflector) and put optical Rx & Tx on the same end!
    Yes you can synchronize, but additional algorithm is needed to synchronize. Since beam will be "on" most of the time, you will have long time to sync. You can use "Costas loop" (done in software) to do this. Normally this would be difficult, but since you are running at low frequency, the "lock in" need be only over +/-1% of the carrier frequency. (Use crystal oscillators on both ends). You can also use "incoherent" method (multiply received signal by locally-generated carrier and carrier shifted by 1/4th period. Each of these is low-pass filtered (~100Hz). Result is the sum of the 2 filtered results. This will give slower response then the coherent method (which can respond within 1 cycle of the carrier).

    0
    jpswensen1
    jpswensen1

    2 years ago

    Any idea on the latency and or response time of this setup? That is, how long after and object passes does the arduino detect the object? milliseconds? microsecond?

    I was just wondering if the car is going too fast whether this setup would miss detecting it.

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    Hi. Honestly I have not tested the latency or response time. All objects I measured using the system were moving at <2m/s over a 10m course, there were also large measurable differences in times between different cars. As mentioend in some other comments, there is better (faster/more accurate) Tx and Rx hardware, I'll probably look to make a version 2 of the system rather than test the accuracy of this one.

    0
    Reyes23
    Reyes23

    2 years ago

    Nice project! What is the total cost of it?

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    Hi. I'll try and update the instructable with component costs in the next few days.

    0
    TheDoblerones
    TheDoblerones

    2 years ago

    Nice Project!
    If you have the time and will to improve your Arduino Code I would highly suggest you reading about external interrupts. They make it a lot easier to detect a signal change.

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    Great suggestion, thanks. If you have a link to a good resource on interrupts please let me know.

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    Danke!

    0
    akhtarkh
    akhtarkh

    Question 2 years ago on Step 1

    what software/application have you used to make the circuit diagram? It dose not look like fritzing.

    0
    Joe Palmer
    Joe Palmer

    Answer 2 years ago

    The circuit diagram was made using tinkercad circuits. It is more of a schematic rather than a proper circuit diagram as the exact components were not avilable in the editor.

    0
    AlejandroS101
    AlejandroS101

    2 years ago

    Nice Project!
    As a teacher you can show variants of the sensors for the laser light.
    An example may be the use of common red LEDs attached to an integrated comparator to show that all semiconductors are sensitive to light.

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    I think there is a real opportunity here to further develop a project such as this for STEM. Students could be set the fairly striaghtforward task of measuring the time a model car takes to travel a set distance, then introduced to various ways to do this. There are also many "levels" to which the students can accomplish the task allowing for lots of differentiation in marking. Ironically the solution I present here is probably the most basic level, more able students could look to replace the Tx and Rx hardware with faster or more reliable components, improve the code for robustness or investigate wireless options.

    0
    PeterD304
    PeterD304

    2 years ago

    Photodiodes like the BPW34 are much faster than LDR's. Perhaps you should try using those instead.

    0
    Joe Palmer
    Joe Palmer

    Reply 2 years ago

    Thanks, a few people have mentioned this. As a result I will use improved Tx and Rx hardware for the version 2.

    0
    starphire
    starphire

    Reply 2 years ago

    I was going to note this as well, but I think it's most helpful to point to a resource that explains the complexities of LDR response times (summary: they are variably slow depending on the photocell, light levels, and how it's being measured). But even at their best, the sluggish "fall time" in a use like this probably exceeds a 1ms count of your Arduino. Here's a good writeup on their properties: http://www.ladyada.net/media/sensors/gde_photocell... .
    I agree that a silicon photosensor is much more suitable, as even the slowest phototransistor will take less than 1ms to respond to a break in the beam. But in the spirit of keeping things simple for beginners, a nice breakout board that's sensitive to visible wavelengths, has a simple analog output, and is inexpensive would be the ticket. That's surprisingly hard to find, as most such photosensors are for IR only and have permanent filters to block out visible light. But here's one that would fit the bill: https://www.adafruit.com/product/1384

    The small size of silicon photosensors makes alignment more finicky, but this can be overcome with a small convex lens mounted at the focal distance in front of your sensor. Another trick is to put the laser diode and the sensor next to each other facing the same direction, and use a mirror to reflect the beam back to the sensor. Now you can have it all aligned in one block, making alignment in setup fast and foolproof if you use a retroreflector (bicycle reflector!) as the mirror.