The Bullet Counter

So I had a chance to test my bullet counter this weekend!

I met up with two redditors this past Sunday and they let me borrow their guns for testing.  I wish I could tell you that all went well, but I had some pretty interesting problems…

The Story So Far… (skip if you’ve been following my work on Reddit)

For those of you just joining in, over the past 12 months, I have been developing a device than can be attached to a firearm and let the user know how many rounds remain in his/her magazine.

It all started over a Thanksgiving conversation with my Uncle.  Something about that conversation got me thinking that I should make him something neat for Christmas.  He’s something of a “gun nut”, so I thought I’d make him a gadget for his guns.  Somehow over the next month amidst problem sets and final exams, I managed to produce this.  It didn’t exactly work on the first try, but after a little tweaking of the firmware, it worked very very well.

As you can see, that video has over 150,000 views.  The whole thing exploded over the internet and everyone was telling me that I should start making them to sell.

I quickly set to work developing a new and improved version with tons of cool features.  I got a chance to meet up with my uncle again over Spring Break to test it, and it completely failed.  I was doing the power circuit all wrong, and it would randomly start counting on its own or shut down all together.

At this point, I realized that I was spending too much time on it and needed to focus on my school work.  I literally put the project and all of its parts in a box labeled “Bullet Counter” and hid it in my closet.  After graduating and getting a job, I opened that box again and continued development.  That’s where you get that video above.

I recently created this blog to catalog all of my projects through their successes and failures.  I decided to do the same with this Bullet Counter project, so here we are.  If you’d like to follow me on development, take a look at the categories over in the side panel of the main page and select “Bullet Counter” to filter out the irrelevant posts.

Speaking of failures, what exactly happened on Sunday?

Problems:

There were two problems that I found while at the firing range.  The first is a pretty easy one to fix.  When a gun is fired, there are all kinds of crazy vibrations that last for some time after the bullet leaves the chamber.  An accelerometer mounted on the gun can pick up these vibrations and a micro-controller might think that they are actual gunshots in themselves.  To prevent this from happening, I integrated a short time-out after every shot during which the accelerometer data is ignored.

As it turns out, the accelerometer I’m using on the new bullet counter is a little more “ringy” than the original.  I saw that the counter was counting a shot as two shots.  Because of this, I had to increase my time delay.  I actually had to increase it ten-fold which seems like a lot.  There might be something else going on that’s related to problem #2 which warrants further investigation.

Problem Number Two

So, as I’m getting ready to drive out to Plymouth to fire some guns, I made a stop at CVS for batteries.  At any given moment, I have a handful of AAA batteries on my desk that range from brand new to completely dead.  For testing purposes, I figured I’d go ahead and shell out for a fresh pack.  I usually buy CVS brand batteries, but this time I thought I’d really splurge and go for the name brand: Duracell.

So I got to the firing range, slapped the new batteries in, and was ready to start testing.  After solving all of the power issues in the previous rev, I was pretty confident that I wouldn’t have any issues.  I had spent the last month slamming these things against the ground trying to simulate gunshots and they always seemed to work just fine.

Well, as soon as I was ready to start testing, I noticed the display cut off.  This was something completely new.  Even the previous rev didn’t have a problem quite like this.  The display would sometimes cut off for just a second or two, but other times it would stay off and even toggling power wouldn’t bring the circuit back to life.  Sometimes it would seem to be working great until the gun was fired once and it would die again.

This is about when I started to freak.  I was trying to think of what could be going wrong.  Could it be the temperature?  It’s possible that the capacitance on the boost converter is negatively affected by low temperatures (electrolytic caps are like that).  Other than that, I couldn’t think of anything else that had changed.

Luckily, I brought my voltmeter and set to work probing the circuit.  I noticed that in some cases, the batteries were getting disconnected from their terminals.  Looking at the batteries visually, I saw that the spring contact terminal was getting partially tucked under the battery and figured that it was losing contact with the metal part on the end.

I returned to my car to try to find something metallic that I could shove into the battery compartment to help maintain contact: tin-foil, a gum wrapper, anything.  I didn’t find anything metallic, but I did happen to find an entirely un-opened pack of 16 Energizer AAA batteries which I must have purchased some time ago and completely forgotten about.  Figuring that it was worth a shot, I brought the batteries back to the range, and tried them out.

They worked great!  Of course, this was about an hour into testing, so the instant relief was hardly enough to quell my nerves.  I still wanted to understand why they were working so much better than the Duracell brand (if you’re an Energizer marketing rep, don’t call).

Upon closer investigation, I noticed this:

 

The little nubby thing is longer!

More specifically, the negative terminal of the Durcell brand battery sticks out a little farther.  I figured that this extrusion was somehow helping to guide the spring contact down under the battery and causing it to lose contact.

Satisfied enough for the moment, I finished up the testing and took the video you see above.  When I got home, I decided to investigate further.

Not All Batteries Are Created Equal

As it turns out, the difference in the Energizer batteries and Duracell batteries was even more subtle than I thought, and it had nothing to do with the negative terminal but rather with the positive one.

Take a look at this picture.  Does anything look odd to you?

What if I zoom in like this?

Well there’s my problem!

As it turns out, the little nub on the positive battery terminal is .01″ shorter on Duracell brand than Energizer brand.  Also, the nubs are shaped differently:

So why does this matter?  I didn’t design the battery housing, I ordered the enclosure from an enclosure company.  Shouldn’t they design their enclosure with all batteries in mind?

Well, the battery terminals of these enclosures are inserted by the user (me).  They are configurable so you can have your power terminals in the front of the case or in the back.  To hold the battery contacts in, they are outfitted with little harpoon tabs that are supposed to dig into the plastic and prevent them from falling out.  The funny part is that those tabs aren’t necessary because I’m soldering them into my circuit anyway.  The really funny part is that the tabs are actually pushing the plastic housing against the battery and preventing it from touching the lead.  You can sort of see this happening in the above photo.

Here’s a close up of the tabs doing their thing:

So, I’m pretty sure bending those tabs flat before installing the contacts can alleviate the problems I’ve been having.

So what was causing the intermittence of the problem I was having was the fact that there was some uncertain probability every time the case was jostled that the batteries would disconnect and not fall back into place.

More Slightly-Unnecessary Investigation


This raised another question: how much disconnection can my circuit handle?  I always figured this would be a problem ever since I moved the batteries to be in-line with recoil.  Knowing that the batteries would be bouncing around in the case, I implemented a pretty large bypass capacitor to help smooth out the voltage waveform.

The above video gave me a pretty good idea of exactly how much I was dealing with.  If you stop the frame just right, you can see the display shut off right as the gun is fired:

This might be startling, but it’s worth noting that the LEDs are powered from a different circuit that has little bypass capacitance (especially when compared to the current draw of the LEDs), and their shutting off says nothing about the status of the “brains” of the circuit.

When stepping through the video, I noticed the screen die for about two frames at a time which works out to about 30ms (60fps video).  I was curious to find out exactly what was going on during this time.  I especially wanted to know how much current my device is drawing so I can possibly reduce this current draw during gunshots to prevent putting too much stress on the intermittent battery connection.

I hooked an oscilloscope probe up to my power rail and smacked the counter against my desk producing this:

As you can see, the voltage drops pretty linearly and then picks up again every time the battery bounces against the contacts.  The reason it drops linearly is because all of my components act as constant current loads.  If you take the equation Q=CV and differentiate over time, you get I = C dV/dt.  If I is constant, so is dV/dt and thus the slope.

So what is the slope?  I took another reading closer up while simply removing a battery entirely:

As you can see, the voltage drops 1.39V (VP) in 7.37ms (TP).  I’m using a 100uF bypass capacitor, so this would work out to:

(100E-6 Farads * 1.39 Volts)/7.37E-3 seconds = 18.8 miliAmperes

I inserted my ammeter in series with my circuit just to be sure, and measured this:

BOOM!

What’s cooler about this is that if you zoom out more, you can see the exact moment when the micro-controller shuts down:

At under 2V there is no longer enough voltage to keep the micro running, so it shuts off, greatly reducing the current draw.  The bad news is that this shut-down occurs after just 15 or so milliseconds.  Assuming the batteries are staying disconnected for the entirety of those two frames of video (which is probably not the case), I’ve still got a problem.

So what can be done about this problem then?  I have a few ideas.  Firstly, I can make some mechanical changes to the battery housing to keep the batteries from bouncing around too much.  Secondly, it’s actually possible to force the micro-controller to go to sleep for the 30 or so milliseconds after each shot.  When asleep, the current draw of the micro controller will drop about 5mA.  Lastly, I could just add more bypass capacitance.  This might end up being the best solution and is better than option two because it would also help prevent the accelerometer from giving erratic readings.

Conclusion

At the end of testing yesterday, I was really unsure about the future of the project.  I’ve sunk a lot of time and quite a bit of money into this thing, and I was upset that it wasn’t working.  After looking back, I’m really glad I stuck with it because these new problems are really interesting ones that I look forward to solving.

Hopefully, I’ll have a chance to make these changes soon so I can get back to testing!


Project files can be found here: Bullet Counter v1.1.1


35 thoughts on “The Bullet Counter

  1. Really cool project. Since the testing was done with a gas operated semi-auto, I wonder if the accelerometer isn’t registering the chambering of subsequent rounds as a “shot”. The gun fires, the bolt slams back, then the recoil spring brings the bolt back forward, chambering and locking the next round. That sequence takes a while and might explain why you had to increase the time delay so significantly in order to eliminate double counting. It would be interesting to go back to the original time delay and test with a bolt action to see what’s what.

    Thanks for the describing your battery frustrations. I’ll inspect mine much more closely in the future as a result.

    • Well, the last gun I tried it on was a fully automatic MP5, so I don’t think that’s the issue. I’m still not certain, but I’m hoping that it has something to do with the uneven voltage coming off the batteries so I can fix it all at once.

  2. Why use an accelerometer, wouldn’t a simple mic be easier and require less computation? If you put the mic on the inside against the rifle itself you could easily isolate shots from that rifle (useful at a range), but it may require a few “calibration shots” when mounting to different weapons.

    • Have you ever tried something like this? I’ve heard a few people suggest it.

      My thought is that any major jostling of the gun (like moving the action and chambering a round) would probably clip the audio signal on most cheap microphones. As is, I need to use a “heavy” accelerometer (50g), so I would probably need a heavier mic to be able to detect a difference.

      Also, with the current accelerometer configuration, there is zero “computation” needed. I literally have an analog comparator comparing the output of the accelerometer to a voltage threshold. I did this on purpose because it prevents me from stepping on any patents when I finally enter production with these things.

      • Just some thoughts, I’m only an aspiring engineer and even still have far to go in that respect. With that in mind, here are my 2 cents. Using a mic, I gather you could easily use some type of sound deadening material to filter out almost all of the sound, bringing the (just guessing here) 150dB or so noise to ~80dB – something that even a cheap microphone could handle.

        And the other thought I had, what about piezoelectrics? If the bullet counter is mounted quite stably, and you mounted a piezo device quite stably in the direction of the recoil, couldn’t you pick up a quite reliable signal of a bullet being fired? This would be a lot cheaper than an accelerometer, and it seems to me you wouldn’t have to deal with the wobble. As it stands, ignoring the accelerometer for a small amount of time could have huge impact when trying it on a firearm with a much higher rate of fire.

        • You know, it’s funny how you get set down one design path and never consider other options.

          For all I know, both of your methods could work great. The only downer is that I don’t actually own a gun on which to test them!

          My only concern with the microphone is that it would be hard to prevent bumping of the mic from registering as shots. It’s pretty easy to clip a microphone by tapping it, and even with some sort of padding, physical shocks would travel very easily to the microphone diaphragm. Still though, I could probably just use a very insensitive microphone.

          I’ve never actually worked with piezo elements before, but I could give that a try.

          In the meantime, I’m probably going to develop a paintball version soon with a beam-break sensor on the barrel. This would be the most reliable solution if only I could build it in a way that prevents the hot gasses leaving the barrel from melting the device!

          Thanks for the comments. The Bullet Counter has been my back-burner project for over a year now, and I’m always looking for a way to improve it.

          • I’m interested in the paintball version if the size can be trimmed down some.

            I’m looking into getting something setup on a project right now, and while your beam break idea certainly works as a universal, I’m not sure it’s the right direction as the ends of barrels get pretty messed up with broken paint, dirt and what have you.

            For my model I’m trying to actually link into the trigger as it’s an electronic marker, or into the break beam eyes already on the marker. My problem is I’m not an electrical engineer, and don’t know a thing about building a countdown.

            So I’ll keep my eyes on you for sure.

  3. Fair points, and as far as a beam break goes (on a metal-and-gunpowder firearm) I’m sure 99% of gun owners aren’t willing to get holes machined into their barrels so you would have to work off some type of end-of-barrel attachment.

    But something tells me this thing would be *huge* with the paintball community.

    At any rate, great site. Saw a couple reddit submissions and started reading the rest of your articles, I like reading about other peoples projects. I need to get back to my shelved projects myself, I have a box full of half amplifiers in the crawlspace.

    By the way, the Plymouth you mentioned.. you’re not from MI are you?

    • Don’t know how that comment got out of the thread.. oh well.

      Also, I see you’re from MIT. So that answers the Plymouth question.

      • I think wordpress caps you at five comments deep.

        To answer your question, I’m actually living in RI right now. I just graduated from MIT last June and moved an hour south.

        I wasn’t implying that I’d want people to drill holes in their guns. That might not even be legal… I was suggesting more something to clip on to the end. Maybe something that fits into a suppressor screw mount.

        Thanks for the comments!

  4. Awesome site! While reading about your battery enclosure woes, I couldn’t help but think about the MagLite aluminum flashlights. Maybe you could use something like that to improve reliability… machined aluminum tube with O-ringed screw-on end. Drop the batteries in and go. Gun lovers appreciate well-crafted stuff.

  5. Considering the device is already mounted so close to the barrel, couldn’t you use the effect of the bullet on a magnetic field? I’m quite rusty on my physics, but wouldn’t the speed of the bullet create a pretty decent effect on the current in a coil? That would eliminate the need for any delay after each shot, and could actually simplify your circuit, no? Calibration would be pretty easy for a new weapon too.

    As I said, the last time I did this stuff was in high school, but there’s a valid idea in there somewhere I think. Or I’m dumb, one of the two. Thoughts?

    • Something like that might be possible. You could build a magnetic oscillator similar to how a conventional metal detector works where the oscillator frequency would have to be ridiculously high. It’s probably possible.

      The biggest issue for me is that I don’t have access to any guns for testing, so I kind of have to stick with what I know.

  6. Fantastic project, thank you for taking the time to share it with us (and documenting it so well).

    Unfortunately the same technology can’t be applied to the AEG Airsoft rifles that I use (sadly the UK has much less accommodating gun laws) – but it has given me a few ideas for a potentially similar device using alternative sensor hardware.

    Certainly, such a device would be useful when combined with a 2300 round C-Mag. It could automatically wind the feeding mechanism inside the mag every X rounds, which is currently initiated manually (albeit electrically powered).

    With regards to the battery terminal issues you’ve been having – I’m curious if you’ve considered using a permanently or semi-permanently connected rechargeable cell (NIMH/NICAD/LIPO) to completely bypass the issue altogether?

    I understand that there is a convenience factor attached to being able to drop in store-bought cells whenever required, but a rechargeable cell connected directly to the board (optionally via a snap-fit connector for easy long-term replacement) wouldn’t have the same problems with terminal disconnection and long-term wear.

    Alternatively, commonly available 9v batteries use a pop-fit that also would not be affected by the recoil.

    • If you ever tried to market this to the tactical community and/or military and law enforcement, switching to CR123A lithium batteries might be a good idea. They’re already used extensively for laser sights and weapon-mounted flashlights, and a lot of stocks and grips include storage compartments for extra 123’s. I don’t know if 123’s would be any different in terms of the problems you had with the Duracell batteries, but if shooters could use the same type of battery in your counter as with their lights and lasers it might increase the marketability.

  7. paintball gasses are actually cold. CO2 for obvious reasons, and compressed air is heated up when condensed but cooled when released.

    You can also monitor other things besides the paintball leaving the barrel. Most guns have an exposed bolt or charging handle that you could sense, but since most paintball guns are already electronic you could tap into their circuits.

    • Not sure what you were getting at with the “hot gasses” part. I was only concerned with the hot gasses from a real firearm. Beam-break would be perfect for paintball.

      My only concern with other forms of monitoring is making a universal device that can be used on a broad variety of paintball guns. A beam break sensor could be easily mounted on the muzzle of a number of different rifles.

  8. Pingback: QR Clock | ch00ftech Industries

    • I haven’t really touched it since this blog post. I might come back to it later, but for the time being, it’s on hold indefinitely. I’ll keep you in mind if I ever start producing them.

  9. I’d still be interested. There’s a different version now being marketed by a company called Radetec (http://radetec.com/), but they use a magnet inside the magazine follower to track the position of the last cartridge. I think that your idea would be better, because a lot of folks already use aftermarket followers in their magazines from companies like Magpul, and it would be a pain to have to buy replacement followers for all magazines. Radetec’s version would also interfere with AR15 users who use magazine well grips, since their display bolts to the magazine well, while your version is more conveniently placed forward. Yours would also be more universal since it mounts to any accessory rail, while Radetec is currently only available for a handful of specific firearms. If you were able to patent this, you might well be able to market the idea to a competing manufacturer (maybe even Magpul?) and get a contract for production?

  10. Pingback: CNC machine, Christmas gifts, and I’m a dope | ch00ftech Industries

  11. Pingback: CNC machine, Christmas gifts, and I’m a dope » Geko Geek

  12. Pingback: Electrical Hell and the apocalypse survival external phone battery | ch00ftech Industries

  13. Another reason to use a magazine based system versus a recoil based is the abhorrent fact that not every round will go off. Jams must be cleared, duds must be extracted manually, etc. All of these expend cartridges without recoil and would not be displayed on the counter. Also if it could be made more compact, it would be amazing!

  14. I’m another one who would be very interested in a finished product. I see the system using magazines but don’t like them either. a previous poster was correct in that it interferes with the various pieces of gear people have. A simple attachment to a rail would be the best.

    I don’t know much about electronics unfortunately. Is there a way to have a “setup” mode? Fire 5 rounds in set up mode and the counter would then know exactly what a shot “feels” like. It could be placed on any firearm and be reprogrammed for different calibers.

    Also how about a counter that counts up? A shooter should know the size of their magazine. 10 rds, 30 rds etc. Counting up could accommodate the various misfires.

    This is an incredible idea. I believe it would be very profitable. I urge you to continue!

    Cheers

Leave a Reply

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