Maker.io main logo

How to Use Adafruit.io to Wirelessly Monitor Impact Forces

2020-07-20 | By Grace Hill

License: General Public License Wearables Wireless Arduino

OverView

In the past few decades, through conversations and research, what we've learned about concussions has grown a considerable amount, but we still have plenty to learn. In everyday activities, we are constantly experiencing the forces around us. This project was created to explore the forces that impact our heads, especially in high contact areas such as sports.

Materials

Wiring

Soldering 

If you purchased the boards pre-soldered, skip this part.

Before assembling the device the two boards, Huzzah 32 and Temperature + Motion Wing, you need to solder on the headers and connectors. For a guide on soldering, watch Digi-Key's Another Teaching Moment on How to Solder Through-Hole.

When both boards have their headers and connectors soldered on, simply slide the Temperature + Motion Wing into the slots of the Huzzah 32. They should match up pin for pin.

wiring

wiring2

Adafrui.io

Adafruit.io is a cloud service without the management (Adafruit takes care of that for you). It provides the ability to store data and interact with the microcontroller, all over Wi-Fi. This allows you to check on your device wherever you have an internet connection. This is all free! It's up to you how you will use it.

Get started by logging into or creating an account for Adafruit.io. Once into your account, click on feeds in the upper left-hand corner.

From here you will be able to manage different feeds but for now, you only need one. Click the drop bar named Actions and choose Create a New Feed.

Create Feed

Name the new feed gforce or whatever you see fit.

Name Feed

When you have the feed ready to go, select Dashboards from the upper left next to Feeds. 

Dashboard

Click the actions drop bar and you will find the Create a New Dashboard.

Create Dashboard

Name the dashboard (Helmet Motion Detector in this example). 

Name Dashboard

In the top right corner of your dashboard, there is a blue plus sign that creates a block. The blocks allow you to monitor or interact with the incoming data. Click the blue plus sign and a variety of widgets will pop up. Choose the graph and set the feed to gforce. This will allow you to monitor the gforce over a period of time.

Name the graph G-Forces and add it to your dashboard.

Dash

Triggers

There are many features besides monitoring your dashboard that Adafruit.io can do. One of these features includes the Triggers page. On this page, you can have Adafruit.io read your feeds and message you under certain conditions. In your case, you may want to add a trigger that emails or messages you when a certain threshold has been crossed. 

Trigger dashboard

Add trigger

Add a trigger and set it so it is reactive.

Reactive Trigger

Set the first feed to gforce and the condition to greater than. It's recommended to set the threshold to 30 as this is the amount of G's that can cause minor brain injury in a car accident.

Conditions

Arduino IDE

With your dashboard and feeds set up, you can go to the next step in the process which is the coding. For this project, the Arduino IDE will be used. If you do not have the Arduino IDE you can download it at their website Arduino.cc. Once downloaded, open the IDE and a new file will be made.

Libraries

Under the Sketch tab, you will find Include Library, go onto Manage Libraries. Once at the search bar, install the following libraries: Adafruit IO Arduino, and ADT7410.

Manage Libraries

Add library

Boards

Click Tools, Board, then Manage Boards. Here you will need to install the ESP 32 file to be able to run on the Huzzah 32 FeatherWing. Once completed, go back to the Tool handlebar, go to Board and find the Adafruit ESP32 Feather.

Board Manager

Board installation

Once all the libraries and boards have been installed, copy and paste the code below.

 

Copy Code
#define IO_USERNAME "USERNAME"
#define IO_KEY "KEYCODE"

#define WIFI_SSID "WIFI_NAME"
#define WIFI_PASS "WIFI_PASSWORD"

#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);


/************************ Example Starts Here *******************************/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL343.h>

float accelX, accelY, accelZ, gforce,filter;


// Create the ADXL343 accelerometer sensor object
Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);

// set up the 'gforce' feed
AdafruitIO_Feed *huzzah_g_force = io.feed("gforce");

float gforceMax=0;
void setup()
{

// start the serial connection
Serial.begin(9600);

// wait for serial monitor to open
while (!Serial)
;

Serial.println("Adafruit IO - ADX343");

/* Initialise the ADXL343 */
if(!accel.begin())
{
/* There was a problem detecting the ADXL343 ... check your connections */
Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
while(1);
}

/* Set the range to whatever is appropriate for your project */
accel.setRange(ADXL343_RANGE_16_G);


// sensor takes 250 ms to get first readings
delay(250);

// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();

// wait for a connection
while (io.status() < AIO_CONNECTED)
{
Serial.print(".");
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());
}

void loop()
{ gforceMax = 0;
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
for(int u = 0; u<20; u++){
io.run();

/* Get a new accel. sensor event */
sensors_event_t event;
accel.getEvent(&event);

for(int i= 0; i<20; i++){
accelX = event.acceleration.x;
accelY = event.acceleration.y;
accelZ = event.acceleration.z;
gforce = sqrt(((accelX*accelX)+(accelY*accelY)+(accelZ*accelZ)))/9.8;
if(gforce>gforceMax){
gforceMax = gforce;
}
}
}

Serial.println(gforceMax);
huzzah_g_force->save(gforceMax);
}

 

To compile, click the checkmark in the top left corner.

Compiler

When your board is hooked up and ready to go, click the upload button. It is the button with the arrow next to the compile button in the top left corner.

Upload

If you have trouble uploading to the board make sure to check that the board is set to Adafruit ESP32 Feather and that the port is also set to the right output.

Once uploaded, you can hook your device to a 3.7 volt JST 400 mAh battery and connect to any helmet. It's recommended that the device is within the helmet so that when you make any sort of impact it won't break. 

Log into your Adafruit.io account and play your sport within an area that has Wi-Fi and watch your data flow in.

Testing

There are countless ways to use your device. With the device being able to read G’s anything that experiences an acceleration could be tested. It is important to note that there are certain limits to the components. Too high of an impact could damage your 32 Huzzah Feather’s crystal oscillator or battery. It is especially dangerous if you damage a lithium or regular battery, so make sure if you are using any batteries while the device is on a wearable that it is in a protective shell and that you can get the battery out of the wearable easily. Suggestions include: inside a helmet, on top of a shoe, or a homemade apparatus. 

For this example, we will use the helmet suggestion, specifically, an ice hockey helmet. Make sure the Li-Poly battery is attached then, using string or tape, fasten the device to the inside of the helmet or cage (if put in the cage put a small piece of foam in between the bars and the sensors). Once secure, power on the device and open up Adafruit.io. From here you can drop, throw, or shake the helmet and watch the readings come in. 

As a fun game with your friends, see who can shake the helmet to get the highest G's. 

To learn more about Adafruit.io, go to the educational webpage regarding all the major components: https://learn.adafruit.com/welcome-to-adafruit-io.

 

制造商零件编号 4147
ADXL343 + ADT7410 SENSOR FEATHER
Adafruit Industries LLC
¥97.27
Details
制造商零件编号 3619
HUZZAH32 ESP32 FEATHER STACK HDR
Adafruit Industries LLC
¥178.67
Details
制造商零件编号 1304
MICRO USB LIION/LIPOLY CHARGER
Adafruit Industries LLC
¥48.43
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum