How much impact can the human body handle? Whether it’s football, rock climbing, or a bicycle accident, knowing when to seek immediate medical attention after a collision is incredibly important, especially if there are no obvious signs of trauma. This tutorial will teach you how to build your very own impact force monitor!
Read Time: ~15 min
Build Time: ~60-90 min
This open-source project uses a Raspberry Pi Zero W and an LIS331 accelerometer to monitor and alert the user of potentially dangerous G-forces. Of course, feel free to modify and adapt the system to suit your various citizen science needs.
Note: Build fun stuff with the Impact Force Monitor! However, please don't use it as a substitute for professional medical advice and diagnosis. If you feel that you have taken a serious fall, please visit a qualified and licensed professional for proper treatment.
Step 1: Suggested Reading
To keep this tutorial short n' sweet (er, well, as much as possible), I’m assuming you’re starting with a functional Pi Zero W. Need some help? No problem! Here's a full setup tutorial.
We'll also be connecting to the Pi remotely (aka wirelessly). For a more thorough overview on this process check out this tutorial.
**Stuck or want to learn more? Here are some handy resources:**
Step 2: Materials
- Raspberry Pi Zero W Basic Kit
- This kit includes the following: SD Card w/ NOOBS Operating System; USB OTG cable (microUSB to USB female); Mini HDMI to HDMI; MicroUSB power supply (~ 5V)
- Also recommended: USB hub
6" Heat shrink tube or electrical tape
Header pins for accelerometer (4 - 8) and LED (2)
- Soldering Iron & accessories
- Epoxy (or other permanent, non-conductive liquid adhesive)
- Probably also scissors :)
Step 3: But Wait! What Is Impact Force?
Fortunately the term "impact force" is pretty straightforward: the amount of force in an impact. Like most things though, measuring it requires a more precise definition. The equation for impact force is:
F = KE/d
where F is the impact force, KE is the kinetic energy (energy of motion), and d is the impact distance, or how much the object crunches. There are two key takeaways from this equation:
1. Impact force is directly proportional to the kinetic energy, meaning that the impact force increases if the kinetic energy increases.
2. Impact force is inversely proportional to impact distance, meaning that the impact force decreases if the impact distance increases. (This is why we have airbags: to increase the distance of our impact.)
Force is typically measured in Newtons (N), but impact force may be discussed in terms of a "G-Force", a number expressed as a multiple of g, or earth's gravitational acceleration (9.8 m/s^2). When we use units of G-force, we are measuring an objects acceleration relative to free fall towards the earth.
Technically speaking, g is an acceleration, not a force, but it is useful when talking about collisions because acceleration* is what damages the human body.
For this project, we'll use G-force units to determine if an impact is potentially dangerous and deserving of medical attention. Research has found that g-forces above 9G can be fatal to most humans (without special training), and 4-6G can be dangerous if sustained for more than a few seconds.
Knowing this, we can program our impact force monitor to alert us if our accelerometer measures a G-force above either of these thresholds. Hooray, science!
Acceleration is a change in speed and/or direction.
Step 4: Configure the Pi Zero W
Gather your Raspberry Pi Zero and peripherals to configure the Pi to be headless!
- Connect the Pi to a monitor and associated peripherals (keyboard, mouse), plug in the power supply, and log in.
- Update software to keep your Pi speedy & secure. Open the terminal window and type these commands:
- Type and enter:
sudo apt-get update
- Type and enter:
sudo apt-get upgrade
sudo shutdown -r now
Step 5: Enable WiFi & I2C
- Click the WiFi icon on the upper right corner of the desktop and connect to your WiFi network.
- In the terminal type this command to bring up the Pi’s Software Configuration Tool:
- Select “Interfacing Options”, then “SSH”, and choose “Yes” at the bottom to enable.
- Go back to “Interfacing Options”, then “I2C”, and select “Yes” to enable.
- In the terminal, install remote desktop connection software:
sudo apt-get install xrdp <br>
- Type ‘Y’ (yes) on your keyboard to both prompts.
- Find the Pi’s IP address by hovering over the WiFi connection (you might also want to write it down).
- Change the Pi’s password with the passwd command.
Step 6: Restart the Pi and Log in Remotely
We can now ditch the HDMI and peripherals, woohoo!
- Setup a remote desktop connection.
- On a PC, open Remote Desktop Connection (or PuTTY if you’re comfy with that).
- For Mac/Linux, you can install this program or use a VNC program.
Step 7: Build It: Electronics!
The two photos above show the electrical schematic for this project and the Pi Zero Pinout. We'll need both to tackle the hardware connections.
Note: The LIS331 breakout board in the schematic is an older version -- use the pin labels for guidance
Step 8: Connect the Accelerometer to the Pi's GPIO
- Solder and carefully remove any flux residue on the accelerometer and Pi GPIO’s header pins.
- Then connect jumper wires between the LIS331 breakout board and Pi between the following pins:
LIS331 Breakout Board Raspberry Pi GPIO Pin
GND GPIO 9 (GND)
VCC GPIO 1 (3.3V)
SDA GPIO 3 (SDA)
SCL GPIO 5 (SCL)
- To make it easier to connect the sensor to the Pi Zero, a custom adapter was made by using a female header and jumper wires. Heat shrink was added after testing the connections.
Step 9: Add an Alert LED!
- Solder a current limiting resistor to the negative LED leg (shorter leg) and add shrink wrap (or electrical tape) for insulation.
- Use two jumper cables or header pins to connect the positive LED leg to GPIO26 and the resistor to GND (header positions 37 and 39, respectively).
Connect the battery pack to the Pi’s input power to complete the setup!
Step 10: Program It!
The Python code for this project is open-source! Here’s a link to the GitHub repository.
For Folks New to Programming:
- Read through the program code and comments. Things that are easy to modify are in the “User Parameters” section at the top.
For Folks More Comfortable w/ the Technical ‘Deets:
- This program initializes the LIS331 accelerometer with default settings, including normal power mode and 50Hz data rate. Read through the LIS331 datasheet and modify initialization settings as desired.
- The maximum acceleration scale used in this project is 24G, because impact force gets big real quick!
- It is recommended to comment out the acceleration print statements in the main function when you are ready for full deployment.
Before you run the program, double check that the accelerometer address is 0x19. Open the terminal window and install some helpful tools with this command:
sudo apt-get install -y i2c-tools
Then run the i2cdetect program:
i2cdetect -y 1
You’ll see a table of I2C addresses displayed as shown in the image above. Assuming this is the only I2C device connected, the number you see (in this case: 19) is the accelerometer address! If you see a different number, take note and change in the program (variable addr).
Step 11: Quick Overview of Program
The program reads the x, y, and z acceleration, calculates a g-force, and then saves the data in two files (in the same folder as the program code) as appropriate:
- AllSensorData.txt – gives a timestamp followed by the g-force in the x, y, and z axes.
- AlertData.txt – same as above but only for readings that are above our safety thresholds (absolute threshold of 9G or 4G for more than 3 seconds).
G-forces above our safety thresholds will also turn on our alert LED and keep it on until we restart the program. Stop the program by typing “CTRL+c” (keyboard interrupt) in the command terminal.
The photo above shows both data files created during testing.
Step 12: Test the System!
Open the terminal window, navigate to the folder where you saved the program code using the cd command.
Run the program using root privileges:
sudo python NameOfFile.py
Check that the acceleration values in the x, y, and z-direction are printing to the terminal window, are reasonable, and turn on the LED light if the g-force is above our thresholds.
- To test, rotate the accelerometer so that the each axes point towards the earth and check that the measured values are either 1 or -1 (corresponds to acceleration due to gravity).
- Shake the accelerometer to make sure the readings increase (sign indicates direction of axis, we’re most interested in the magnitude of the reading).
Step 13: Secure Electrical Connections & Install It!
Once everything is working correctly, let’s make sure the impact force monitor can actually withstand impact!
- Use heat shrink tube and/or coat the electrical connections for the accelerometer and LED in epoxy.
- For super durable, permanent installations, consider coating the whole shebang in epoxy: the Pi Zero, the LED, and the accelerometer (but NOT the Pi cable connectors or the SD card).
- Warning! You can still access the Pi and do all the computer stuff, but a full coat of epoxy will prevent the use of the GPIO pins for future projects. Alternatively, you can make or purchase a custom case for the Pi Zero, although check for durability.
Secure to a helmet, your person, or a mode of transportation like your skateboard, bicycle, or cat*!
Fully test that the Pi is securely fastened or the GPIO pins may become loose causing the program to crash.
*Note: I originally meant to type "car", but figured an impact force monitor for a cat might also yield some interesting data (with kitty's consent, of course).
Step 14: Embedding the Circuit in a Helmet
Theres a few methods of embedding the circuit into a helmet. Here’s my approach to a helmet installation:
- If you have not already, connect battery to Pi (with battery off). Secure the accelerometer to the back of the Pi with nonconductive insulation in between (like bubble wrap or thin packing foam).
- Measure the dimensions of the Pi Zero, accelerometer, LED, and battery connector combination. Add 10% on either side.
- Draw a cutout for the project on one side of the helmet, with the battery connector facing towards the top of the helmet. Cut out the padding in the helmet leaving a few millimeters (~ 1/8 in.).
- Place the sensor, Pi, and LED in the cutout. Cut pieces of the excess helmet padding or use packaging foam to insulate, protect, and hold the electronics in place.
- Measure the battery’s dimensions, add 10%, and follow the same cutout for the battery. Insert the battery into the pocket.
- Repeat the insulation technique for the battery on the other side of the helmet.
- Hold the helmet padding in place with tape (your head will keep ‘em in place when you are wearing it).
Step 15: Deploy!
Power up the battery pack!
Now you can remotely log into the Pi through SSH or remote desktop and run the program via the terminal. Once the program is running, it starts recording data.
When you disconnect from your home WiFi, the SSH connection will break, but the program should still log data. Consider connecting the Pi to your smartphone hotspot WiFi, or just log back in and grab the data when you get home.
To access the data, remotely log into the Pi and read the text files. The current program will always append data to the existing files – if you want to delete data (like from testing), delete the text file (via the desktop or use the rm command in the terminal) or create a new file name in the program code (in User Parameters).
If the LED is on, restarting the program will turn it off.
Now go forth, have fun in life, and check on the data every so often if you happen to bump into something. Hopefully, it’s a small bump but at least you’ll know!
Step 16: Adding More Features
Looking for improvements to the impact force monitor? It is outside the scope of the tutorial but try looking at the list below for ideas!
Do some analysis on your g-force data in Python!
The Pi Zero has Bluetooth and WiFi capabilities – write an App to send the accelerometer data to your smartphone! To get you started, here’s a tutorial for a Pi Twitter Monitor.
*Note: To hear the whooshing sounds associated with your acceleration! :D