(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:
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):
The two photodiodes are wired in reverse-bias as shown in the following 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:
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).
Next 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:
So 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…?