Measuring Projectile Velocity

(Updated 9/6/2010 – scroll down for final results)

I’ve got a couple friends who enjoy building spud guns and other sorts of “just for fun” air rifles. They’re pretty nifty to shoot, especially since ammo is flexible. Even a wad of paper towels wrapped in tape will do the trick. All you need is something that forms a relatively good seal with the inside of the barrel.

So being the EE that I am, this got me to thinking: wouldn’t this be even more fun if we could measure muzzle velocity? It shouldn’t be all that hard; we could just hook up a couple LEDs and photo-detectors, fire through the beams, time it with a microcontroller, and voilà! So, that’s precisely what I did, except that I decided to go with a couple cheap laser diodes instead of LEDs. Here’s the end-product in all its wooden glory:

The Box

Top View

In the first image you can see one of the two laser diodes poking through the right side of the wooden enclosure (and held precisely in place by hot glue). The two lasers are aimed at PIN-type photodiodes which are mounted on the other side of the box, spaced 2″ apart, and covered with IR-blocking film (to prevent difficulties with ambient light):

Photodiodes Plus IR-Blocking Film

The two photodiodes are wired in reverse-bias as shown in the following schematic:

Sensor Schematic

Now if you’re unfamiliar with photodiodes, you can essentially think of them as light-dependent resistors. (Although to be precise, they should really be modeled using a light-dependent current source as discussed here.) In total darkness, they’ll exhibit very high resistance when reverse-biased. However, expose them to light, particularly infrared light (at least in this case), and their resistance drops substantially. Thus, whenever the laser beam is striking a photodiode, its resistance is quite low. When this happens to D1 in the schematic above, the voltage at point A rises closer to the 5V supply. However, if the beam is broken, the photodiode’s resistance rises, causing the voltage at point A to drop towards 0V (GND).

We can use this change in voltage to determine when the laser is being blocked by a projectile. This is done using a high-speed operational amplifier (op-amp) wired as a comparator. The potentiometer (POT) shown in the schematic above is tuned so that its output voltage is just between the “blocked” and “unblocked” voltages of the photodiodes. The outputs from the op-amp then saturate at 5V whenever the lasers are unblocked. However, if the lasers are blocked, the op-amps will output approximately 0V. This change from 5V to 0V then represents the entry of a projectile and is detected by an AVR microcontroller, the ATMega128. It’s part of a development board I’ve had for several years now, the Olimex AVR-MT-128 (details here). The development board really isn’t important at all – it simply provides screw terminals for easy connection to the AVR’s I/O.

So once the microcontroller powers up and initializes its LCD display, it sits and waits for its two inputs to change state. If the leading photodiode goes low (0V), an interrupt is triggered that starts an internal counter. The counter runs until the trailing photodiode goes low, at which point the counter is stopped, the projectile’s velocity is calculated based on the known separation between photodiodes, and the LCD display is updated like so:

Display Closeup

The “mode” you see displayed above indicates the speed of the MCU’s internal 16-bit counter. If a slow-moving projectile (less than ~150ft/s) is expected, you can use the pushbuttons to specify slow mode, which causes the internal timer to count at a much lower frequency. This allows slow-moving projectiles to be measured without counter overflow. However, if you’re firing high-speed projectiles, you’ll want to use fast mode. This will kick up the counter’s frequency to 16Mhz to provide better speed resolution.

My initial testing was performed by shooting rubber-bands through the lasers. It turns out they fly at between 40 and 80 ft/s depending on how much you initially stretch them. I also tested out the timing accuracy of the system by using an arbitrary waveform generator in place of the photodiodes. Results looked very good: fast mode accuracy should be less than 0.1% at speeds of about 1000 ft/s. Max speed is limited to 10,000ft/s.

Code for the ATMega128 can be downloaded here: fps_meter_code.zip.

Finally, the following is a fairly complete bill of materials in case you want to try this out:

  • PIN photodiodes: BPW34
  • Operational Amplifier: EL5444
  • 5V switching regulator (to power development board): V7805-500
  • Linear 3.3V regulator (to power lasers): UA78M33C
  • 1k resistors (in series with photodiodes)
  • 10k potentiometer (to set the photodiode “trigger” threshold)
  • Laser diode modules (pulled from two cheap laser pointers)
  • AVR development board: AVR-MT-128 (but really, a single ATMega will do)
  • IR-blocking film: Wowfil samples
  • Some scrap wood and screws

Update (8/29/2010): I have now tested the meter successfully with two different air rifles – a .20 and a .22 caliber pellet gun. The .22 was tested first and proved rather anemic. Initially it couldn’t even break through the cardboard box we were using to catch the pellets. With a few extra pumps its rounds reached 140ft/s, but that’s still rather slow. The rifle seems to have difficulty holding pressure. We had better luck with the 0.20 cal – its pellets reached a top speed of 590ft/s – this was enough to penetrate two layers of cardboard and nearly the full thickness of a piece of 1×6 pine wood. I should also note that using such small rounds made it slightly difficult to trip the laser sensors. However, once we had the rifle lined up properly and leveled, everything worked great!

Update the Second (9/6/2010): This afternoon I took the meter out to my uncles’ shooting range for a bit of live-fire testing. The first thing I learned is that the device I’ve made is called a chronograph and that apparently you can buy these for not much money. No doubt the store-bought varieties provide many additional features and are easier to use; but where’s the fun in that?

Well, we started out “testing” with a .45 ACP using standard Remington FMJ rounds (230 Grain). The chronograph was setup about eight feet in front of the table from which we were firing. I had considered firing at point-blank range, and while this would have been much easier, the smoke and flames from the barrel may have presented a problem for my electronics (i.e. inaccuracies, melted plastic, etc). Of course, the long-distance alternative could have led to my blasting my poor development board into oblivion. Thankfully, I’m a better shot than that; although just barely. To perform the test, I pinned a little black target to the back of the device, then aimed for the center of the dot. After a few tries, the round passed through both beams and registered about 850 ft/s – pretty much what you would expect for this type of ammunition (see this Wikipedia entry on the .45 ACP).

Range Test: .45 ACP SetupNext up, we tried out some Magtech Auto+P rounds – 185 Grain, JHP. As promised, these provided substantially more power. You could certainly hear and feel the difference. That is, when they would fire – a number of them were just a bit too long to fit completely in the chamber. I’m not sure whether this was a defect or if they were just too big for this particular gun. But anyway, a couple different shots both registered about 1150 ft/s:

Range Test: .45 ACP ReadoutSo after all of this testing, I’m thinking about making a couple of changes to the system. For one thing, having to adjust the threshold potentiometer for changing lighting conditions is a little frustrating. The IR-blocking film just isn’t quite cutting it, although I’m sure it helps. But I’d like to try using the AVR to dynamically generate one or two analog outputs for use as thresholds. I’ve actually done something very similar in the past with the same photodiodes. I simply programmed the AVR to ramp up its output voltage until the comparator switched state. Then it automatically reduced the output voltage a little to give some room for noise. This varying analog output, by the way, was created by adjusting the duty cycle of a low-pass filtered PWM output. Setting the filter’s cutoff frequency to less than 1/100th of the PWM frequency nicely converts a square wave into a DC value (and the lower the cutoff frequency, the smoother your final output will be).

To compensate for changing lighting conditions, I might also try connecting the two photodiodes directly to the analog inputs of the ATMega128. I’d still use the external comparator for timing measurements, but this would allow me to directly determine the best analog threshold to be generated by the AVR without the need for scanning. I could also add transistors to the lasers so that the AVR could turn them off briefly for calibration. I might also just high-pass filter the photodiode output to completely eliminate any shifting DC offset. I’ve tried this before on a similar project with good success.

The other thing I’d like to do is make the sensing area a little wider. It’s pretty tough to reliably hit two 1/8″ laser beams. Perhaps a couple of line lasers and photodiode arrays would do the trick. Or maybe there’s a better non-optical sensing option out there I haven’t heard of yet…?

46 thoughts on “Measuring Projectile Velocity”

  1. hello i was reading your article with great interest. the machines i work with have a similar system to sensoring how hard you hit the machine…check my website.
    can this device be hooked up to a score board to give measurments on a large screen?
    so in your case how fast an object was but on a screen for an audience to watch instead of the tiny lcd screen?
    and can the readings be changed for tons per squaure inch of force or what ever is the equivilent power settings ?

  2. Sure, the development board used here has a DB9 serial port which could be programmed to send readings to an external display of some sort. This sensor might be a bit tough to implement with your boxing machines, since you’d need laser beams shining from one side of the machine to the other. A force sensor of some sort might be better. That could give you a reading in kN or lbf, which you could then convert to pressure (psi, kpa, etc.) given a certain area.

  3. this post couldnt have come at a better time. I’ve been trying to put together a paintball chronograph with an arduino and slightly different sensors. Expect some questions from me soon 😛

    1. Cool, so you’re using IR sensors and receivers? That was my first thought too, but I was worried that the light from the IR transmitter might diffuse too much – hence the laser. Good luck with it! I doubt you’ll need to go all the way to ASM (assembly) for the timing, unless you’re really picky about accuracy. The built-in counters on the ATMega chips work really well, especially if clocked with an external crystal. Running on the Arduino platform might present additional overhead though… I’m not sure.

  4. hey man

    total AVR noob

    how do i open the code i downloaded? i would love to give this ago

    i usually use arduino which had noobified me lol

    awesome work

    Ste 🙂

    1. Haha, no problem – to open the project and code, start by downloading AVR Studio 4 here: http://www.atmel.com/dyn/products/tools_card.asp?tool_id=2725

      That’ll let you open the project file (FPS.aps) found in that ZIP. You should see a listing of the source files on the left side of AVR Studio. You can click each file to view it. Of course, you can also just open any of the source files (with the *.c or *.h extensions) using any text editor.

      Now actually before you do any work with that code, you’ll also need to get AVR-GCC in order to compile C code for the AVR (assuming you don’t want to use assembly): http://winavr.sourceforge.net/

      There’s actually a pretty good tutorial describing how to work with AVR Studio 4, including how to program chips and such: http://imakeprojects.com/Projects/avr-tutorial/

      Good luck!
      -Mike

  5. I have been trying to build something just like this for a while now. After about 6 revisions, I’ve ended up with something almost identical to what you made, but it’s still not working. I think my problem may be the op amps I’m using. I’m using some 741 op amps I had laying around. I looked up the datasheet for the ones you are using and noticed they are 100 MHz. Could it be that the ones I’m using are too slow?

    1. Hi David,

      Well I haven’t tried this with the 741, but I don’t think that’s your problem. I did some rough calculations just to check. Let’s say you’re firing a projectile 10mm long at 1000fps, and your sensor is also 10mm wide. Converting, that’s a speed of 308,400mm/s. The projectile will be blocking your sensor (at varying degrees) for (10mm x 2)/308400 = 65.6us. The slew rate of the LM741 is about 0.5V/us, so it should have no problem acting as a comparator. In fact, if your output is swinging between 0V and 5V, you should only need a period of 10us for that to happen.

      Have you tested your detection circuit with something slow-moving to verify its operation? If you have, can you get your hands on a scope to measure the output of your 741 while firing a projectile past your sensors? If the scope detects a pulse, that means your MCU is doing something wrong. Either the interrupt isn’t configured correctly, or the code is missing something… Let me know what you find.

  6. I don’t have access to a scope, but I have tested each sensor with my multimeter and it does swing high when the sensor is blocked. I suspected that it was a speed problem because when the sensors are hooked to the microcontroller everything works like it should up to about 150 fps. Anything faster than that doesn’t register at all. Unfortunately, my meter is way too slow to check if the sensors are picking up something moving quickly. I don’t know if it would matter or not, but the 741s I used were leftovers from when my dad was in college. I don’t know if they have changed since then. I ordered some faster ones anyway just to give it a try. I guess I’ll just keep fiddling and try to find a scope to use. Thanks for your help.

    1. Hmmm, well it could be the op-amps. Have you also checked the specs on the photo-detectors you’re using? The PIN photodiodes I used above react incredibly fast, but photoresistors typically have rise and fall times measured in milliseconds, not microseconds.

      1. The photodiodes I’m using have rise and fall times of 6 ns. I was originally using phototransistors which were too slow, but I didn’t need to use the op amps with them. So when I switched to the photodiodes I didn’t realize I would need the op amps. I’ve been stumbling through this project learning each lesson the hard way. My new parts should be here soon, and I’ll let you know what happens.

          1. I just thought I would let you know that I did get mine working. It was just waiting around for a while while I worked on some other stuff, but I finally got around to it. I ended up replacing the ancient 741s with some brand new one 741s. Thanks for all your help!

  7. Hey mike, this design seems very promising, infact,this is the best design for a homemade chronograph that I have found so far, that’s why I would like to make one of my own for my paintball gun. unfortunately I have very little knowledge in this type of stuff, I understand that this is probably alot to ask for but, I was wondering if you could show me how to build on of these in in-depth steps (including the programming of the board)or if you might have links to web sites (or other sources of information) that would be able to informe me on everything I need to know on building this. Thank you in advance for any info you might give me,

    1. Hi Bob,

      Sorry it took me so long to reply – been gone this weekend. So first off, what sort of equipment and experience do you have? There are a number of ways to accomplish what I’ve done here that might be better suited to you.

      To start with though, you need to find a couple of cheap laser pointers (either online or in a store). You could order just the laser diodes themselves, but I actually found that the same thing can be obtained more cheaply by cracking open one of these: http://www.amazon.com/gp/product/B000KCL3RW/ref=oss_product. It’s also possible to use IR transmitters as your source of illumination, but they’ll be more diffuse and may not give you as clean a signal.

      Next, you need a circuit to detect the laser pointer (and when it’s been blocked by a projectile). I’ve described that above, but feel free to ask for further clarification. I’d suggest visiting Digi-Key (http://www.digikey.com/) to order the amplifier, photodiodes, resistors, potentiometer, and voltage regulator (just follow my bill of materials above, if you’d like).

      Finally, you need something that will record the time between the pulses generated by the photodiode circuit. I’ve used an AVR microcontroller (MCU) to do this, but there are a variety of other options. What’s your experience with microcontrollers and programming? If you’ve never touched an MCU, they’re not terribly hard to figure out, it’ll just take a little time. There’s a lot of support online for the Arduino development board (e.g. http://www.ladyada.net/learn/arduino/ is a good source of tutorials), which uses, at its core, an AVR microcontroller. But it’s also possible to just use your computer to measure the pulses. Ideally you’d have some type of commercial digital data acquisition device, but if not, you could probably get your sound card to do this for you. Basically you’d hook up the two photodiode circuits to your left and right stereo inputs, then use a program like Audacity (http://audacity.sourceforge.net/) to record and then measure the time between pulses.

      Anyway, let me know what you think. Thanks for the comments!

      -Mike

  8. Hello again mike, I unfortunately have no experience or equipment, I know this will probably make things dramatically more difficult but I’m not ready to give up yet. I was also wondering if I could get the lasers instead from some old laser mice that I have laying around by simply taking them out? or would that not work. Thanks for your time mike and hope to hear from you soon.

    1. Indeed, that may make things more difficult, but certainly not impossible. I admire your determination! Well, you may be able to use the laser diode from a laser mouse, but quite often the light they produce is invisible because it’s infrared (IR). That’ll make alignment more difficult, but not impossible. On the plus side, most photodetectors are actually more sensitive to IR light. But just to clarify, all of the mice I’ve seen which glow red are actually using LEDs, not lasers. Now you could use red LEDs as well, but it may make your system less reliable since LEDs produce more diffuse or scattered light than do lasers.

      What I’d recommend is to get started with just building a simple detection circuit. You’re going to want to get a digital multimeter for this, if you don’t have one already. That way you can at least measure voltage. You should be able to find one fairly cheaply ($10-30) at a local hardware store. Even Wal-Mart might sell these now. You really don’t need anything fancy for this.

      Next, find yourself a light detector of some type. If you don’t want to order anything online, do you have an old VCR or TV? Something that came with a remote control? If you do, and don’t mind opening it up, you may be able to find the IR receiver. The only trouble is, it may be designed to detect modulated IR signals, and may also not be sensitive to ambient light (which is a problem if you want to use it with a red LED, for instance). I’d really recommend just ordering one online though, or going to RadioShack. Oh and if you do pop open an old TV, be very careful, as they often contain high voltage capacitors which can take weeks to discharge and may give you quite a shock.

      So once you’ve got your light detector (be it a photodiode, phototransistor, or photoresistor), you’ll then just need a resistor and a 9V battery. Let me know what sort of photodetector you find (part number, if possible) and I’ll see if I can help you figure out a good resistance value (but 1kOhm is usually a good starting place). We’ll worry about adding the comparator or w/e later on.

      Good luck!
      -Mike

  9. Hello Mike
    whether the sensor can be placed into a PVC tube? so that this instrument can be portable. other than that of PVC tube can be mounted directly on the barrel of a gun. How appropriate diameter for mounting the sensor. thank you

    1. Hi Bambang,

      Certainly, a large PVC pipe would be a good way to mount the sensors and lasers (or LEDs). The diameter of the tube can be mainly determined by your own preference. Smaller would be slightly better to avoid the adverse effects of direct sunlight. However, the sensors do not need to be at a specific distance from the lasers, they only need to be a specific distance from each other. And the sensor separation isn’t that important either, you just need to be able to measure it precisely. But if your microcontroller counter is running slowly, spacing the sensors farther apart will increase your resolution. Does that make sense?

      -Mike

  10. Hello Mike
    Thanks for the explanation, I will try to assemble the circuit, just unfortunately I was having trouble finding microcontroller AVR-128 in my town. how to calibrate the accuracy of this circuit.
    thank you

    1. Well initially all you need to do to calibrate is to precisely measure the distance between your two sensors. Then if you know the speed of your microcontroller’s counter, all you have to do is a little math. For instance, let’s say your sensors are two inches apart, and your counter is running at 100kHz. If your microcontroller registers a delay of 50 counts between sensors, that means the delay is (50)*(1/100000) = 0.0005s. Then you just divide the distance (2in = 0.1667ft) by the time, or 0.1667/0.0005 = 333fps (feet/second). Now to really fine-tune this calibration, you’ll probably need some more sophisticated hardware. The way I did this was to generate a pair of pulses using an DAQ device, measure it with a very accurate oscilloscope, and then check that against the measurement of my microcontroller. In my case, I didn’t need to make any adjustments to my microcontroller, it was pretty much dead-on to begin with. But you may need to compensate for software/electrical delays in certain cases. Now of course the real calibration would be to fire a projectile of known speed through your sensors. If you have that option, great! Just use that to apply an offset or gain to your measurements. But most of the time, if your measurements and math are right, you won’t need to worry about much calibration.

      1. Hello Mike
        you explain clearly and that was what I was looking for. Since I have not gotten Microcontroller like your scheme then I will try to use 89C2051 hopefully still included in the discussion on this topic.
        Thank you.

        1. Thanks, that microcontroller should still work fine. It’s just got less memory and fewer features, but it’ll count and give you serial data.

  11. Hello Mike
    I want to ask again hopefully you do not mind.
    Microcontroller Atmega I get only 16, if the program AVR 128 can be used also for ATMega 16. I have not experienced using a microcontroller.
    thank you

    1. Yes, you can use the ATMega16 microcontroller for this project. It will operate almost identially to the ATMega128, except it will not provide quite as much flash storage or as many features. Now if you’re asking about the programmer, yes, the same device you use to program the ATMega128 will program the ATMega16. You’ll likely either use the AVRISP or the AVRISP mkII to connect and program these chips. I’d recommend the mkII as it allows connection via USB, whereas the AVRISP has an RS232 serial connector.

  12. Hello Mike
    I want to ask again.
    I’ve made a chronometer as yours but it does not work for small-caliber bullets for air guns. whether there is something wrong in the photo diode, or other equipment??.

    1. Well it’s tough for me to say without seeing what you’ve made, but I suspect your small caliber bullets aren’t blocking enough light from the photodiodes. Does it work for larger projectiles? If so, then this is likely the case. You need to find a way to better focus your light source onto the photodiodes such that a small bullet can more completely block it. Or perhaps adjust the bias resistors attached to your photodiodes, or the comparator threshold voltage.

      1. Your right Mike, after the distance between the IR diode and photodioda minimized resulting in a good output (I use a small tube). unfortunately the result of calculation is too large. I’m using sismin ATMega 16 with XTAL 11.0592, whether in the calculation using the count clock is 11.0592 or atmega16 can be programmed to freq 8 MHz with XTAL 11.0592. thanks for your help

  13. Ah, well I suppose you can either space the two photodiodes closer together, thus reducing the time elapsed between detections. Or you could slow down your ATMega’s counter. Either with a divider in software or by reducing the crystal frequency.

    1. Hallo again
      After I tried several times to change the counter Devider I finally get a good result. as a comparison I use audacity as a reference. now I can measure some of my gun without a miss. Thank you Mike for a good project

  14. I have a suggestion to solve the small detection field issue. You might consider placing opposing mirrors on opposite sides of the box. By tilting the laser very slighlty you could cause the beam to reflect back and forth many times to create a light curtain. Really like the project. I was looking for something like this for a pinewood derby timer. Thanks again.

    1. Thanks Laurence,

      That’s a really awesome suggestion, I just might try that! Simple yet elegant; I like it.

        1. I would like to make use of your circuit if I may to time pinewood derby type cars. Is there a way to modify the circuit to get two independant outputs? Is there a way to modify the circuit to have a single detector?

          1. Hi Laurence,

            The answer is likely “yes”, but I’m not sure exactly what you mean by two independent outputs. Do you mean two separate displays of speed? I’m not too familiar with pinewood derby racing, but I’d imagine you’d want your detectors and lasers spaced a bit further apart. That should be no problem. The lasers could have a completely separate power supply. You’d just set them up on one side of the track, with a 9V battery or something, and point them at your detectors on the other side of the track. You could use two lasers and two detectors as I’ve done here. Then you just need to get the detector spacing right and aim the lasers accurately. You may need to put tubes around the detectors so they don’t get confused by changes in ambient light and see only the lasers.

            You could certainly just use one detector as well, but that requires more knowledge of what you’re detecting. If the object that will be passing by has a fixed length, then you might be able to time how long the laser is being blocked by the object, instead of the time between two detectors.

            Does this help?

  15. Hello Mike,

    Pinewood derby originated with Scouting. It is a gravity race between wooden cars in parallel lanes. The rules stippulate that cars must be ranked 1st, 2nd and 3rd to decide the winner. Timing the cars is not allowed because of inaccuracies between races. I thought that it would be fun to display a scale speed for the cars as they finished along with the 1st, 2nd and 3rd place result. Thus my interest in your design.

    A pinewood car is typically 5″ to 7″ long and have a speed of about 25 ft per second. I would like to keep the lasers closer to each other so the measurement equipment will not to obstruct the view of the cars as they cross the finish line. In this arrangement the car will block both lasers for part of the time as the car passes. If the two detector outputs where indepentant then the speed measurement could still be done by measuring the time between the leading edge of the pulse from each detector in sequence.

    Thanks,

    Laurence.

    1. Thanks Laurence, sounds like fun! Actually the circuit I have here does precisely what you want: it measures the time between the leading edges of the pulses from each detector (although my leading edges are inverted – pulses go from 5V down to 0V and back to 5V as an object passes):

      If the leading photodiode goes low (0V), an interrupt is triggered that starts an internal counter. The counter runs until the trailing photodiode goes low, at which point the counter is stopped, the projectile’s velocity is calculated based on the known separation between photodiodes, and the LCD display is updated.

      So I think you’re all set. The only challenge remaining would be to program the AVR such that it records multiple speeds in sequence. My code above simply displays the last measured speed. You would need to add some logic to store speeds and display them as, for instance, comma-separated values on your LCD display.

  16. I see now that I misinterpreted the circuit and your explination. I had thought that there was only a single input to your controller from ‘A’ and that your controller saw two consecutive pulses from that input.
    Yes your circuit will work for measuring the cars. Thanks very much for the help.
    Great article and I appreciate your willingness to discuss it. Thanks again.

  17. For a wider sensor area, try two parallel mirrors? That way, the beam can be broken at any point in the “net” of beams.

Leave a Reply

Your email address will not be published. Required fields are marked *