Ammolytics

Project: Inexpensive Firearm Accelerometer

Measure recoil, flinching, and more for under $50

You may have already read about this little gizmo from my previous article, where I used it to measure the relationship between Recoil and Muzzle Velocity. Of all the feedback I received, the accelerometer definitely generated the most interest.

What you may not know is that it wasn’t the first experiment I had intended to use it on. My original plan was to correlate rifle movement to my 600 yard scores. I wanted to detect if I was flinching or jerking the trigger, resulting in a hit in the 9-ring (or worse).

In this article, I’ve provided more detail about how I built it, how it works, and how I’d like to improve it.

Update: I’ve written another article with an update on the incredible progress that’s been made to this project. Most notably, it’s nearly six times faster!

In a hurry? You can find the code and instructions to build your own over on GitHub.

My homebrew 3-Axis accelerometer attached to a Spuhr mount.
My homebrew 3-Axis accelerometer attached to a Spuhr mount.

Table of Contents

Existing Solutions

Before starting a project, it’s a good idea to look around at how others have solved the same problem. Don’t reinvent the wheel, as the saying goes. Admittedly, I only did a cursory glance at what was out there. Knowing that I would likely be frustrated by proprietary software that I couldn’t tweak to my own needs, and because it only cost $5, I ordered a 3-axis sensor without hesitation.

Regardless, here’s a brief overview of what you might find online:

Project Goals

The rough idea was to measure the precise movements of my rifle just before, during, and just after each shot. I wanted to detect lateral movement that you would expect from flinching or bad trigger pulls (jerking, overtravel, sneezing, etc).

Here are a few maxims I knew would be true of this project:

That said, you have to start somewhere. The first prototypes rarely resemble the finished product. To maintain focus, I set a few rules for myself:

First Attempt

The accelerometer sensor I used is capable of a 5kHz sample rate. This was both the fastest and most affordable accelerometer I could find. The sensor would send information with the I2C protocol to the Arduino. The Arduino would convert this raw data into a CSV-formatted stream over USB. The Raspberry Pi would read the stream and write it to disk with simple Unix pipes.

Components

Note: There are excellent guides available for this board from Adafruit and SparkFun which cover everything you need to know about hooking up the wires to programming. I highly recommend reading those if you plan on building your own.

Problems

While this first prototype was functional, this setup benefited from very simple software and suffered from complicated hardware.

Initial component connection and prototyping phase.
Initial component connection and prototyping phase.

The earliest prototype used an Arduino Uno, Raspberry Pi, and large USB battery.
The earliest prototype used an Arduino Uno, Raspberry Pi, and large USB battery.

The first attempts at mounting were crude, with heavy applications of hot glue.
The first attempts at mounting were crude, with heavy applications of hot glue.

On the first prototype, an Arduino Uno was left dangling from the rifle.
On the first prototype, an Arduino Uno was left dangling from the rifle.

Second Attempt

Two things had to change immediately:

  1. It had to be a single, compact unit
    Two devices and all of the wires turned into a real pain whenever I had to extract the data or make changes to the software. Not to mention the hassle of dealing with all of that stuff at the range. I switched to the Adafruit Feather M0 board – a compact Arduino supported by snap-on accessories (called shields). The Raspberry Pi was only used to write the data to disk. It was replaced by the Adalogger Featherwing, with RTC and micro-SD card.
  2. The mount had to be removable
    Peeling off hot glue every time I wanted to update the software or clean the rifle wasn’t going to cut it. I’m fortunate (and nerdy) enough to have a 3d-printer in my office. I took some dimensions of the components and the Spuhr mount, then used Fusion360 to design a frame. Some really tiny screws are used to retain the breadboards. A better design and higher resolution printer may allow for snap-assembly.

Components

Before the FeatherWing arrived, I went through a few designs of the 3D mount. I still had to use the Rasberry Pi, but at least I could easily remove the sensor from the rifle and didn’t have a huge Arduino hanging off by some jumper wires.

The first 3d-printed frame to hold the Adafruit Feather and accelerometer sensor.
The first 3d-printed frame to hold the Adafruit Feather and accelerometer sensor.

Data Processing and Results

Let’s take a closer look at the information this unit provides. The Recoil vs Muzzle Velocity experiment fired 25 rounds in 30 minutes and createad a 5.6MB CSV file, which is fairly large. It was recording a sample roughly every 6 milliseconds, or close to 140 samples per second. In addition to three axis of acceleration, it’s also storing timestamps and battery voltage.

The following table shows a small sample of raw data for one fired round. Those who are interested can download the complete dataset.

timestamp accel x accel y accel z accel unit sensor range millis micros voltage
1535375188 0.54 9.48 -0.29 m/s^2 4 445 446063 4.16
1535375188 0.63 9.39 -0.10 m/s^2 4 454 454394 4.14
1535375188 0.67 9.39 -0.40 m/s^2 4 460 460487 4.16
1535375188 0.36 9.60 -0.38 m/s^2 4 466 466572 4.16
1535375188 0.44 9.45 -0.33 m/s^2 4 472 472649 4.15
1535375188 0.54 9.39 -0.31 m/s^2 4 478 478727 4.15
1535375188 0.69 9.45 -0.36 m/s^2 4 484 484815 4.15
1535375188 0.63 9.41 -0.21 m/s^2 4 490 490910 4.15
1535375188 0.57 9.52 -0.21 m/s^2 4 525 525100 4.16
1535375188 0.71 9.41 -0.02 m/s^2 4 531 531155 4.15
1535375188 0.69 9.46 -0.27 m/s^2 4 537 537241 4.16
1535375188 0.57 9.37 -0.11 m/s^2 4 543 543330 4.16
1535375188 0.52 9.39 -0.13 m/s^2 4 549 549408 4.16
1535375188 0.56 9.43 -0.15 m/s^2 4 555 555486 4.16
1535375188 0.48 9.54 -0.25 m/s^2 4 561 561563 4.15
1535375188 0.54 9.43 -0.21 m/s^2 4 567 567650 4.16
1535375188 0.48 9.41 -0.06 m/s^2 4 576 576852 4.16
1535375188 0.50 9.45 -0.19 m/s^2 4 582 582931 4.16
1535375188 0.52 9.39 0.13 m/s^2 4 588 589011 4.15
1535375188 0.56 9.41 0.48 m/s^2 4 595 595087 4.16
1535375188 0.71 9.33 -0.04 m/s^2 4 610 610660 4.16
1535375188 0.65 9.45 -0.11 m/s^2 4 618 619010 4.15
1535375188 0.52 9.33 -0.46 m/s^2 4 625 625097 4.15
1535375188 0.48 9.46 0.00 m/s^2 4 630 631039 4.15
1535375188 0.52 9.43 -0.11 m/s^2 4 637 637126 4.15

Charts

Since tabluar data tends to be rather boring, let’s visualize the data to get a better understanding of what it’s trying to tell us. I used Pandas to analyze the data in the Python programming language and Plotly to generate the graphs.

Note: The sensor provides acceleration in metric (m/s²), but I converted to imperial units (ft/s²) for the charts below.

The following charts are from the same dataset and visualize all three axes. I opted for images instead of an interactive chart for two reasons:

  1. To walk you through and zoom in on one shot
  2. Interactive charts would be too slow on mobile devices

All three axes plotted. The Y-Axis is inline with Earth’s gravity, resulting in higher values.
All three axes plotted. The Y-Axis is inline with Earth’s gravity, resulting in higher values.

Zooming in on  single round – loaded, fired, and unloaded
Zooming in on single round – loaded, fired, and unloaded

Zooming in again when the round was fired.
Zooming in again when the round was fired.

Rewinding to my original goal, I wanted to see if I could detect any movement which might lead to inaccuracies on target, such as sloppy trigger pulls or flinching. Looking thorugh this dataset, I found at least one instance, as you can see below. Unfortunately, I was shooting at a steel target so I don’t have any evidence to show what effect this had downrange.

Did I flinch or jerk the trigger? Disruption on the Z-Axis (Left/Right) before breaking a shot.
Did I flinch or jerk the trigger? Disruption on the Z-Axis (Left/Right) before breaking a shot.

Lessons Learned

Here are a few takeaways from my experience working with this sensor and Arduino-based microprocessors.

Future Improvements

Projects like this are never really finished. Hopefully this inspires others to build their own and to contribute so that it can improve for everyone. Here are a few ideas that stand out in my mind:

Next Steps


Special thanks

Before you go…

Thanks for taking the time to read this article! I enjoyed writing it and learned a lot in this process and I hope that you did too. If you have any feedback, you can email me directly if you don’t prefer to use Reddit or other social media.

Tags: