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?
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:
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 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:
(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:
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.
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