Raspberry Pi Impact Force Monitor

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.

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:**

1. Excellent “Getting Started” guide for the Pi.

2. Full hookup guide for the LIS331 accelerometer breakout board.

3. More about accelerometers!

4. Overview of the Raspberry Pi GPIO pins.

5. Using the SPI and I2C Serial buses on the Pi.

6. LIS331 Datasheet

Materials

 

Tools

  • Soldering Iron & accessories
  • Epoxy (or other permanent, non-conductive liquid adhesive)
  • Probably also scissors 🙂

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!

For more information, read about impact force and g-force on Wikipedia!

Acceleration is a change in speed and/or direction.

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
  • Reset:
sudo shutdown -r now

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:
sudo raspi-config
  • 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

  • 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.

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.
  • Enter the IP for the Pi and click “Connect” (Ignore warnings about unknown device).
  • Log in to the Pi using your credentials and away we go!

Build It! Electronics

Here’s the electrical schematic for this project:

Note: The LIS331 breakout board in the schematic is an older version — use the pin labels for guidance

And here’s the pinout for the Pi Zero:

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.

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).

Completed Electronics Setup

Connect the battery pack to the Pi’s input power to complete the setup!

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.

All:

  • 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).

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.

Here’s what both data files look like:

Test the System!

Open the terminal window, navigate to the folder where you saved the program code using the cd command.

cd path/to/folder

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).

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).

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 it all in place when you are wearing it).

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!

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.

Add in other sensors, like a temperature sensor or a microphone*!

Happy Building!

*Note: To hear the whooshing sounds associated with your acceleration! 😀

Anti-Facial Recognition Wearable No. 1

Every time we leave our homes, we are photographed and videotaped in public and private spaces. Facial recognition software identifies our unique facial features and can be used to tag us in photos that are taken with or without our consent. This tutorial is about exerting our right to control our personal privacy. It is our choice and our right to decide if we want to be identified by cameras that photograph us in public and private spaces.

There are many approaches to anti-facial recognition makeup/wearables. This is my first approach based on some background research, chatting with fashion-minded friends, and my own personal artistic and electronic interests.

The purpose of this project is to make it more normal (& fun!) to wear privacy enhancing fashion so that if/when it is needed, folks who are using it for legitimate protection are not targets.

Follow along or use this as inspiration for your own anti-facial recognition wearables! If you design your own, pleasepleaseplease share it in the comments so other folks can learn from and be inspired by you!

Difficulty: Easy

Build Time: 1 – 2 hours (+2 hours for glove controller)

Cost: < $15

Quick Overview of Facial Recognition Software

Computer Vision, or “CV” for short, is a software method that breaks down images into a series of black and white pixels, and then attempts to extract meaning from patterns in the pixels. Since human faces have the same characteristics (two eyes, nose, mouth, & chin), these characteristics can be broken down into patterns that a software program can look for.

For example, pupillary distance, or the distance between the pupils of each eye, varies from about 54 to 68 mm for adults – a CV program would look for black pixels separated by that distance range and log those as one layer. There are tons of patterns that a CV program can search for and locate, then go back and analyze the layers together to ensure they match up. All of these values are stored as variables that can be used for comparison with other images.

The more images a CV program analyzes, the better it gets. By comparing CV-found patterns to patterns in existing photos tagged on social media, CV programs may also tag an individual regardless of where that photo was obtained. CV programs are incredibly accurate, can select a face from multiple angles and backgrounds, and can identify a person’s emotions.

Check out CV Dazzle to learn more about anti-facial recognition makeup and other styles!

 

Materials & Tools

Materials

Optional glove controller:

Tools

  • Liquid Latex
  • Scissors
  • Wire Strippers
  • Soldering Iron (recommended for glove controller)
  • Hot glue gun (or other fabric-safe glue)

 

Step 1: Attaching the Flowers

Use the flowers to cover up distinguishing facial features. Eyes, eyebrows, and nose bridge are three primary regions of the face that are used by facial recognition software to identify and tag a face.

1. Cut flower stems off (unless you want ’em on for aesthetic purposes).

2. Pour a small amount of liquid latex into a container.

3. Figure out where you want to put the flower, then dab the base of the flower into the liquid latex. Let it dry for a few seconds, until it feels sticky and less liquid.

Be sparring with this stuff, it can be kinda painful to peel off, especially after 30 flowers.

4. Attach the flower to your skin. BUT FOR REAL THOUGH avoid your hair!! It is a huuuge pain (literally) to get out.

5. Repeat 2 & 3 until your face is adequately covered.

You can check your progress using a Snapchat or Instagram filter: If the filter can’t find your face or looks wonky (like sunglasses on your forehead instead of your eyes) then you’re all set!

 

Step 2: Adding LEDs!

To add freestanding LEDs, grab a coin cell, and push the two LED legs over the coin cell battery sides (longer LED leg on the positive battery side). Dip one side in the liquid latex, let dry for a few seconds, and then smoosh onto your skin just like with the flowers (again, avoiding precious and sensitive hair).

If you’re using the glove controller (see next step), run the LED wires up your arm to behind your ear, holding them in place with rubber bands or hair bands. Arrange how you want the LEDs to point, then pin the wires in place with bobby pins. That should be sufficient to hold them, if not add some liquid latex to the ends of the LEDs.

The LED + coin cell combo should last ~ 12 hrs.

 

Step 3 (Optional): Make a Glove Controller

This is a good option if you want to save battery life or to be able to turn on/off the LEDs. The thumb is the battery case, with conductive thread on the top as the positive connection. The fingers are the positive connections for the LEDs.

This takes ~ 2 – 3 hours to build.

1. Attach wires to the LED(s).

Measure out two (2) wires per LED to span from your head, down your neck, and to your wrist. Add 3″ to this measurement to allow for movement. Cut wires and strip both ends.

Mark the positive side of the LED with a pen, then twist one end of each wire around the LED leads. Solder the LED leads to the wire. Use a red wire, or mark the positive wire with a pen.

If available, use heat shrink tube to make a poke-less connection. Or just coat it in epoxy or hot glue or some other liquid adhesive.

Repeat for each LED you want to add to the glove.

2. Using conductive thread, make the negative side of the circuit: a negative connection for the coin cell and a “ground bar” for the LEDs.

Put on the glove, and mark where the center of the battery will go. Sew about 10 layers of conductive thread over your mark — this is the ground connection for the coin cell battery.

With the thread still attached, sew down to the base of the glove and stitch back and forth until there are a few layers of conductive thread in a line — this is the negative connection for the LED connections.

3. Make a coin cell battery case on the thumb of the glove.

Cut out 1 square of regular fabric, and 1 square of conductive fabric.

Cut a small hole in the regular fabric and then stitch the conductive fabric square over the hole (with regular thread). Run over this a few times since the conductive fabric tends to fray.

Using normal thread, sew 3 of the 4 sides of the regular fabric over the negative connection for the battery, so that it makes a lil’ pouch for the coin cell. (You might want to sew down the 4th side a bit to hold in the battery, or use a safety pin).

4. Attach the positive side of one LED to a glove finger and make a conductive pad.

Sew the positive LED wire onto the glove (regular thread)

Still using regular thread, sew a square of conductive fabric over the stripped end of the wire.

5. Attach the negative side of the LED to the glove ground pad.

Wrap the stripped end of the wire to the conductive thread ground pad and/or use conductive thread to secure it.

6. Repeat 4 & 5 for all LEDs.. or until you run out of fingers.

7. Epoxy or use fabric glue to adhere all of the connections.

 

Step 5: Test & Deploy!

Test your privacy enhancing getup by opening Snapchat or another filter app and check that it can’t identify that there is a face in the image. At the very least, if it does identify a face, be sure that the filter it adds is hilariously broken.

If you want to get real serious, you can download the OpenCV library and test it against your wearable — this is my long-term goal, but for now I’m happy with sticking flowers and LEDs on my face for V1.0.

Stay tuned for more of these anti-facial recognition wearables and please share your awesome creations!

Simple LED Earrings

FR22YMRI0HYSAV7.MEDIUM

Wearables are an awesome, relatively new extension of circuits. Conductive threads & fabrics make it easy to attach components like LEDs and sensors to clothing/accessories. Plus, they are a super fun introduction to electronics!

These LED earrings were designed b/c I wanted a wearable that was simple, unique, and could be built by-hand w/ available materials. Purchasing all materials adds up to less than $10, and these can be built in ~ 1 hour (although it does take some patience).

For this tutorial I’m assuming you are an electronics beginner. Regardless of your background, I hope this project inspires you to design your own wearable technology or take the basic concepts to the next level 🙂

FU57BPWI0HYS3BP.LARGE
———————————————————————————–

Step 1: Materials

F7Q64DXI0HYS16T.MEDIUM

— 2 LEDs
Fun fact: LEDs on the higher end of the rainbow (red, orange, & yellow) use less power than colors on the lower end (purple, blue, & green).

— 2 Lithium coin cell batteries, 3 V
Mine are non-rechargeable and will probably last for ~20 hours. If you want to make them to last longer, use rechargeable batteries (super expensive but worth it if you want to wear the earrings long-term).

— Thread— Conductive Thread
Used to attach the LED to the battery. Alternatively, you can use wire or anything else that conducts.. like magnets!Also, since conductive thread loops tend to come undone, I hot glued all the knots to hold them together.

— 2 earring backs
— 2 clasps
These act as a switch so the LED can be turned off when not in use. I had some necklace clasps on hand which worked perfectly, but there are tons of options for switches.. all you need is a way to interrupt the flow of electricity.
–Tape
I used conductive tape, but honestly regular tape works just as well.
———————————————————————————–

Step 2: Tools

F1NKAR4I0HYS176.MEDIUM

— Hot glue gun
— Scissors
— Needle
Recommended to get a needle w/ a wide eye b/c the conductive thread has a tendency to fray.
— Optional: wire cutters
Helps w/ cutting the ends of the LEDs.
———————————————————————————–

Step 3: Build it! Pt 1: Wrap the battery.

Screen shot 2014-11-26 at 2.11.34 PM

Wrap the battery w/ 1.5 – 2 feet of (normal) thread. To make it easier, tape the beginning end of the thread to the back of the battery. Leave at least 6 inches of thread at the end.

When finished wrapping, loop the end of the thread under the band and pull tight. Repeat this a few times, then make a knot. Tape the end/thread band down.
———————————————————————————–

Step 4: Build it! Pt. 2: Attach earring back.

F4NL2IGI0HYS16O.MEDIUM

FHGKMR1I0HYS14N.MEDIUM

Loop the 6 in. tail of the the thread band through the hole in the earring back. Use the needle to loop the thread under the band & pull tight, kind of like sewing a button. Repeat at least ten times, or until the thread runs out, then tie a knot.
———————————————————————————–

Step 5: Build it! Pt. 3: Attach the Positive LED Leg.

F0Y3T3CI0HYS17J.MEDIUM

Tie 6 inches of conductive thread to the positive (longer) leg of the LED. Loop the conductive thread through the bottom of the battery thread band and pull through, leaving the LED ~ 1/2 inche (in.) below the battery. Pull the conductive thread down, so it is only touching the front cover (positive side) of the battery.

Loop the conductive thread around the battery thread band at least five times, then tie a knot. Hot glue the conductive thread knots w/ the littlest amount of glue to help hold it in place.
———————————————————————————–

Step 6: Build it! Pt. 4: Attach Clasp.

Screen shot 2014-11-26 at 2.17.42 PM

Attach the clasp (aka switch) to the back of the battery w/ ~ 6 in. conductive threadin the same way the earring back was attached: thread the end of the earring back through the thread band on the battery, above the tape, and pull it tight. Repeat at least five times. Tie a knot and hot glue the thread to hold it in place.
———————————————————————————-

Step 7: Build it! Pt. 5: Attach Negative LED Leg.

Screen shot 2014-11-26 at 2.20.26 PM

Tie the other end of the clasp/switch to 6 in. conductive thread. Tie the end of the conductive thread to the negative, shorter leg of the LED, leaving ~ 1/2 in. from the bottom of the battery. Hot glue the knots.

Connecting the two ends of the clasps helps w/ finding the right length.. or you could use a ruler 🙂

Be sure that the LED legs and the respective thread/wires do not touch; otherwise the battery is shorted and the LED won’t turn on.
———————————————————————————–

Step 8: Done! Woo!

F974PMGI0HYS1H5.MEDIUM

That’s it! Clean up the mess that is hot glue, snip the ends of the conductive thread and, if you’re not going to put them on right away or take photos, unscrew the clasps.

And have fun dazzling your friends and all that good stuff 🙂
Note: The reason the green one isn’t as bright is probably because the battery was quite bit older.