hi who can help me. I need a code allowing fall detection with MPU 6050 and gsm module
I need next weeks lottery numbers.
Post your code first!
That could be a very useful internet search phrase! Try it, adding the keyword "arduino".
Hello beugfallou221
Keep it simple and stupid.
Run some tutorials for the hardware selected.
If you are happy with the results of the tutorials you can merge these to your project.
Have a nice day and enjoy coding in C++.
Hi!
this is a forum to help people with coding, not doing their job.
Your MPU should have an accelerometer on 3 axis. You need to export the data (if possible with high frequency, close to "real time") to your arduino board and then make calculation on it.
Here is scientific hint, related to acceleration, no coding:
- on earth, you have a constant force directed to the ground (center of the earth) and with a value of +1 g (gravity unit: 9,81m/s²).
therefore, at rest, your MPU should give you a constant value of 1 (not considering the actual scale of the MPU) directed to the ground.. When in motion on an horizontal plane, you should see positive value of acceleration in the direction of the move, Zero acceleration on the opposite axis (must be at 90° of the motion direction) and +1 pointed to the ground (I hope you see it is a really good reference point).
A free fall is a particular motion where (thanks to Newton) the only force applied to it is it own weight. Consequently, the value of the axis pointed to the ground will tend to zero.
Export the data form the MPU to the arduino board. Check the values. Trigger alarm or warning if at least axis pointed to ground goes down 0.1g
#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 ");
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++;
Serial.print("Amp "); Serial.println(Amp);
if (Amp>=1){ //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);
fall=true; trigger3=false; trigger3count=0;
Serial.println("TRIGGER 3 ACTIVATED");
}
else{ //user regained normal orientation
trigger3=false; trigger3count=0;
Serial.println("TRIGGER 3 DEACTIVATED");
}
}
if (fall==true){ //in event of a fall detection
Serial.println("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)) {
dtostrf(ax, 4, 1, buffer);
dtostrf(ay, 4, 1, buffer);
dtostrf(az, 4, 1, buffer);
dtostrf(gx, 7, 1, buffer);
dtostrf(gy, 7, 1, buffer);
dtostrf(gz, 7, 1, buffer);
}
delay(100); // wait one second between readings
}
I ran this code but when the drop detection is true the looping output you can see on an image output, and instead I have to issue a message about the drop and start monitoring again
thks
by the way i have a MPU 6050 (accelerometer and gyroscope) and a gsm module
So is your question, "how do I send an SMS message"? Did you research sketches that use the GSM module?
But the code you posted in reply #7 is for the LSM6DS3, a completely different sensor, and will not work with the MPU-6050.
Use a simple ball & pin tilt sensor. It stays closed while vertical but opens horizontally. One input pin as all you need. Use six in a cube and you can figure out which side is up. No code, just read input state.
KISS!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.