I'm using an ADXL335 Accelerometer as a sensor on a fall tracker I'm building. I'm having a little trouble programming it to be able to recognize a fall accurately. I'm currently calculating the magnitudes of the vectors the sensor is tracking but it doesn't seem like a good way to track a fall. Any advice on building a better accelerometer? I'm using an nRF24L01+ radio to communicate with a receiver wirelessly as well. My code is as following and thank you for any help:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
RF24 radio(8,9);
RF24Network network(radio);
byte ID=2;
double val1=0;
double val2=0;
double val3=0;
double sum=0;
const uint16_t home_node = 00;
const uint16_t accel_node = 02;
const long interval = 1333;
unsigned long previousMillis = 0;
struct payload_t {
byte ID;
double val1;
double val2;
double val3;
};
void setup(void)
{
Serial.begin(115200); // sets the serial port to 9600
//Serial.println("A C C E L E R O M E T E R");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 92, /*node address*/ accel_node);
}
void loop()
{
network.update(); // Check the network regularly
unsigned long currentMillis = millis(); // If it's time to send a message, send it!
if ( currentMillis - previousMillis >= interval )
{
previousMillis = currentMillis;
val1 = analogRead(0); // read analog input pin 0
val2 = analogRead(1); // read analog input pin 1
val3 = analogRead(2); // read analog input pin 2
//Serial.print("accelerations are x, y, z: ");
//Serial.print(val1); // print the acceleration in the X axis
//Serial.print(" "); // prints a space between the numbers
//Serial.print(val2); // print the acceleration in the Y axis
//Serial.print(" "); // prints a space between the numbers
//Serial.println(val3); // print the acceleration in the Z axis
double rootSumSquared = sqrt(val1*val1 + val2*val2 + val3*val3);
double rootSum= sqrt(rootSumSquared);
Serial.println(rootSum);
sum = rootSum;
if (val1>31)
{
payload_t payload = {ID,sum};
RF24NetworkHeader header(/*to node*/ home_node);
bool ok = network.write(header,&payload,sizeof(payload));
if (ok)
Serial.println("ok.");
else
Serial.println("failed.");
}
}
}