Timothy ShoemakeAndrew Saville
Published

g-Force Helmet Measurement!

System of two photons that can be used to notify coaches when a football player has received a hit that places him at risk of injury.

BeginnerFull instructions provided1 hour1,579
g-Force Helmet Measurement!

Things used in this project

Hardware components

Photon
Particle Photon
×2
Adafruit ADXL377
×1
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

ADXL377 CIRCUIT

LED CIRCUIT

You could setup this circuit using any Digital Pin that you want with an external LED and Resistor.

Code

ADXL377 IMPACT PHOTON

Arduino
This powers the sensor and takes data to compare between each other to find specific values.
// Make sure these two variables are correct for your setup
int scale = 200; //200 (±200g) for ADXL377
boolean micro_is_5V = false; // Set to true if using a 5V microcontroller such as the Arduino Uno, false if using a 3.3V microcontroller, this affects the interpretation of the sensor data
float magnitude = 0; // defined variables
float xtermb,xterma;
float ytermb,yterma;
float ztermb,zterma;
float magxyzb,magxyza;
float magdiff,actualmagdiff;


#include "math.h" // to use special math functions

void setup()
{
  // Initialize serial communication at 115200 baud
  Serial.begin(115200);
}

// Read, scale, and print accelerometer data
void loop()
{
  // Get raw accelerometer data for each axis
  int rawXb = analogRead(A0);
  int rawYb = analogRead(A1);
  int rawZb = analogRead(A2);
  
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledXb, scaledYb, scaledZb,scaledmagnitudeb; // Scaled values for each axis
  
  delay(1);// Allows a reference data tobe obtained
  
  
  // Get raw accelerometer data for each axis after delay to compare data
  int rawXa = analogRead(A0);
  int rawYa = analogRead(A1);
  int rawZa = analogRead(A2);
  
  
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledXa, scaledYa, scaledZa,scaledmagnitudea; // Scaled values for each axis
  if (micro_is_5V) // Microcontroller runs off 5V
  {
    scaledXb = mapf(rawXb, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675
    scaledYb = mapf(rawYb, 0, 675, -scale, scale);
    scaledZb = mapf(rawZb, 0, 675, -scale, scale);
  }
  else // Microcontroller runs off 3.3V (For this particular experiment)
  {
    scaledXb = mapf(rawXb, 0, 4095, -scale, scale); // Before Hit Comparsion Data
    scaledYb = mapf(rawYb, 0, 4095, -scale, scale);
    scaledZb = mapf(rawZb, 0, 4095, -scale, scale);
    
    // This is to find magnitude Before Hit
    xtermb= (scaledXb*scaledXb); 
    ytermb= (scaledYb*scaledYb);
    ztermb= (scaledZb*scaledZb);
    magxyzb= (xtermb+ytermb+ztermb);
    scaledmagnitudeb= sqrt(magxyzb);
    
    
    scaledXa = mapf(rawXa, 0, 4095, -scale, scale); // After Hit Comparsion Data
    scaledYa = mapf(rawYa, 0, 4095, -scale, scale);
    scaledZa = mapf(rawZa, 0, 4095, -scale, scale);
    
    // This is to find magnitude After Hit
    xterma= (scaledXa*scaledXa);
    yterma= (scaledYa*scaledYa);
    zterma= (scaledZa*scaledZa);
    magxyza= (xterma+yterma+zterma);
    scaledmagnitudea= sqrt(magxyza);
    
  }
  
   // Print out scaled X,Y,Z accelerometer readings Before Hit
  Serial.print("X Vector Before: "); Serial.print(scaledXb); Serial.println(" g");
  Serial.print("Y Vector Before: "); Serial.print(scaledYb); Serial.println(" g");
  Serial.print("Z Vector Before: "); Serial.print(scaledZb); Serial.println(" g");
  Serial.println("*****************************");
  Serial.print("Magnitude Before: "); Serial.print(scaledmagnitudeb); Serial.println(" g"); // Calculate Before Magnitude
  Serial.println("*****************************");
  Serial.println("*****************************");
  
  
  // Print out scaled X,Y,Z accelerometer readings After Hit
  Serial.print("X Vector After: "); Serial.print(scaledXa); Serial.println(" g");
  Serial.print("Y Vector After: "); Serial.print(scaledYa); Serial.println(" g");
  Serial.print("Z Vector After: "); Serial.print(scaledZa); Serial.println(" g");
  Serial.println("*****************************");
  Serial.print("Magnitude After: "); Serial.print(scaledmagnitudea); Serial.println(" g"); // Calculated After Magnitude
  Serial.println("*****************************");
  Serial.println("*****************************");
  
  magdiff=(scaledmagnitudeb-scaledmagnitudea); // This takes difference in two readings
  actualmagdiff=abs(magdiff);
  if ( magdiff < 0 ) // Loop gives absolute of reading, this is final magnitude
{
  actualmagdiff = -magdiff;
}
else
{
  actualmagdiff = magdiff;
}
  
  // Prints out Final or Actual Mantiude difference
  Serial.print("Actual Magnitude: "); Serial.print(actualmagdiff,5 ); Serial.println(" g");//calculated magnitude
  Serial.println("*****************************");
  Serial.println("*****************************");
 
 
    if ( actualmagdiff > 98 ) // This sets G-Force Threshold to compare and publish
{   

  Particle.publish("516Shoemake318", String(actualmagdiff)); // Publishes data
  delay(1000); // Delays to prevent crash
}
else
{
  actualmagdiff = actualmagdiff; // Just a way to end loop
}
  
  delay(3); // Minimum delay before comparsion loop starts over
}

// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
{
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

LED PHOTON

Arduino
This Photon code is meant to alert coaches for injury by flashing a LED.
int led= D7; // Picks LED Pin

void setup() {
    
    pinMode(led, OUTPUT); // Pin starts out off
    digitalWrite(led, LOW);
    
    Particle.subscribe("516Shoemake318", impact); // Subscribe if event happens when threshold is met

}


void impact(const char *event, const char *data) // Tells LED to light up for 3 seconds and turn off
{
    digitalWrite(led, HIGH);
delay(3000);
digitalWrite(led, LOW);
}

Credits

Timothy Shoemake
1 project • 0 followers
Contact
Andrew Saville
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.