So I have a code for fall detection
#include <Arduino_LSM6DS3.h>
#include <LiquidCrystal.h>
#include <ArduinoBLE.h>
void setup() {
Serial.begin(9600); // initialize serial bus (Serial Monitor)
while (!Serial); // wait for serial initialization
Serial.print("LSM6DS3 IMU initialization ");
lcd.begin(16, 2);
if (IMU.begin()) { // initialize IMU
Serial.println("completed successfully.");
} else {
Serial.println("FAILED.");
IMU.end();
while (1);
}
. */
Serial.println();
}
void loop() {
char buffer[8]; // string buffer for use with dtostrf() function
float ax, ay, az; // accelerometer values
float gx, gy, gz; // gyroscope values
boolean fall = false; //stores if a fall has occurred
boolean trigger1=false; //stores if first trigger (lower threshold) has occurred
boolean trigger2=false; //stores if second trigger (upper threshold) has occurred
boolean trigger3=false; //stores if third trigger (orientation change) has occurred
byte trigger1count=0; //stores the counts past since trigger 1 was set true
byte trigger2count=0; //stores the counts past since trigger 2 was set true
byte trigger3count=0; //stores the counts past since trigger 3 was set true
int angleChange=0;
float Raw_Amp = pow(pow(ax,2)+pow(ay,2)+pow(az,2),0.5);
int Amp = Raw_Amp * 10; // Mulitiplied by 10 bcz values are between 0 to 1
Serial.println(Amp);
if (Amp<=2 && trigger2==false){ //if AM breaks lower threshold (0.4g)
trigger1=true;
Serial.println("TRIGGER 1 ACTIVATED");
}
if (trigger1==true){
trigger1count++;
if (Amp>=12){ //if AM breaks upper threshold (3g)
trigger2=true;
Serial.println("TRIGGER 2 ACTIVATED");
trigger1=false; trigger1count=0;
}
}
if (trigger2==true){
trigger2count++;
angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5); Serial.println(angleChange);
if (angleChange>=30 && angleChange<=400){ //if orientation changes by between 80-100 degrees
trigger3=true; trigger2=false; trigger2count=0;
Serial.println(angleChange);
Serial.println("TRIGGER 3 ACTIVATED");
}
}
if (trigger3==true){
trigger3count++;
if (trigger3count>=10){
angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5);
//delay(10);
Serial.println(angleChange);
if ((angleChange>=0) && (angleChange<=10)){ //if orientation changes remains between 0-10 degrees
fall=true; trigger3=false; trigger3count=0;
Serial.println(angleChange);
}
else{ //user regained normal orientation
trigger3=false; trigger3count=0;
Serial.println("TRIGGER 3 DEACTIVATED");
}
}
}
if (fall==true){ //in event of a fall detection
Serial.print("FALL DETECTED");
fall=false;
return 1;
}
if (trigger2count>=6){ //allow 0.5s for orientation change
trigger2=false; trigger2count=0;
Serial.println("TRIGGER 2 DECACTIVATED");
}
if (trigger1count>=6){ //allow 0.5s for AM to break upper threshold
trigger1=false; trigger1count=0;
Serial.println("TRIGGER 1 DECACTIVATED");
}
// Retrieve and print IMU values
if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()
&& IMU.readAcceleration(ax, ay, az) && IMU.readGyroscope(gx, gy, gz)) {
Serial.print("ax = "); Serial.print(dtostrf(ax, 4, 1, buffer)); Serial.print(" g, ");
Serial.print("ay = "); Serial.print(dtostrf(ay, 4, 1, buffer)); Serial.print(" g, ");
Serial.print("az = "); Serial.print(dtostrf(az, 4, 1, buffer)); Serial.print(" g, ");
Serial.print("gx = "); Serial.print(dtostrf(gx, 7, 1, buffer)); Serial.print(" °/s, ");
Serial.print("gy = "); Serial.print(dtostrf(gy, 7, 1, buffer)); Serial.print(" °/s, ");
Serial.print("gz = "); Serial.print(dtostrf(gz, 7, 1, buffer)); Serial.println(" °/s");
}
delay(100); // wait one second between readings
}
but originally this code for mpu6050 but I use lsm6ds3, so the output values are not right, so maybe because I don’t do a calibration, because for mpu6050 they calibrated ax,ay,as,gx and so on, but I don’t know do we need do the same thing for LSM