ujjval rathod
Published

Grove IMU sensor with fall & motion detection capabilities

Invensense MPU6050 is a sensor with inbuilt Accelerometer and Gyroscope sensor along with motion and fall detection capabilities.

AdvancedWork in progress2 hours606
Grove IMU sensor with fall & motion detection capabilities

Things used in this project

Hardware components

panasonic Pan9520
×1
Invensense MPU6050 sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE
gitlab library

Hand tools and fabrication machines

Seeed Studio Fusion PCB/PCBA
Seeed Studio Fusion PCB/PCBA
Seeed's fusion service for PCB and PCBA services
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic Grove MPU6050

A schematic for MPU6050 sensor

Code

Simple_Accel_Gyro_example.ino

Arduino
Arduino code.
#include <MPU6050reg.h>
#include <Wire.h>
#include "MPU6050IMU.h"

MPU6050IMU imu;

void setup() {
  // put your setup code here, to run once:
  Wire.begin(8,7);
  Serial.begin(9600);  
  imu.begin();
  delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:

  float temp[3];
  int range = 8;
  
  Serial.println("New measurement");
  Serial.println();

  imu.readaccelerometer(temp, 8);
  
  Serial.print("ax ");
  Serial.println((temp[0]));

  Serial.print("ay ");
  Serial.println((temp[1]));

  Serial.print("az ");
  Serial.println((temp[2]));
  
  delay(100);

  float gyro[3];

  imu.readgyroscope(gyro, 2000);

  Serial.print("gx ");
  Serial.println((gyro[0]));

  Serial.print("gy ");
  Serial.println((gyro[1]));

  Serial.print("gz ");
  Serial.println((gyro[2]));
  Serial.println();
  delay(1000); 
  
}

Fall-detection

Arduino
Detect the fall with threshold set between 0x00 and 0xFF being low to high sensitive to fall respectively. That will create and interrupt on the INT pin of the sensor which can trigger the ISR in arduino.
/***************************************************************************
 * 
 * This is an example for the sensor Grove MPU6050. MPU6050 is a six axis
 * Gyroscope and Accelerometer sensor will fall and motion detection algorimthms
 * integrated with it.
 * https://gitlab.com/UJUR007/mpu6050_ind
 * 
 * This is an example code to trigger a hardware interuppt if the fall is detected
 * on the MPU6050 sensoe beyond given thresold.
 * 
 * The example is specifically designed to work on Arduino Uno development board.
 * For other development boards or microcontroller architecture one may need to
 * modify the following code.
 * 
 *************************************************************************/

#include <MPU6050reg.h>
#include <Wire.h>
#include "MPU6050IMU.h"

#define INTRUPPT_PIN 3
#define LED_PIN 13


MPU6050IMU imu;
volatile bool falldetection = false;

int count = 0;

void interrupt_service_routine()
{
  Serial.println("Fall..");
  falldetection = true;  
  digitalWrite(LED_PIN, HIGH);
}

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  attachInterrupt(digitalPinToInterrupt(3), interrupt_service_routine, CHANGE);  
  Serial.begin(9600);
  imu.begin();
  imu.enablefreefall(0xF0, 0xFF);  
  pinMode(INTRUPPT_PIN, INPUT);
  digitalWrite(INTRUPPT_PIN, LOW);

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  
  delay(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(500);
  
  if(falldetection == true)
  {
    count += 1;
    if(count==10)
    {
      digitalWrite(LED_PIN, LOW);
      falldetection = false;   
      imu.readbyte(INT_STATUS);
      count=0;
    }
    Serial.println("Fall detected....");   
    delay(100); 
  }
  Serial.print("Count ");
  Serial.println(count);
    
}

Credits

ujjval rathod

ujjval rathod

10 projects • 19 followers

Comments