Skip to content

Instantly share code, notes, and snippets.

@marabesi
Last active May 9, 2018 13:59
Show Gist options
  • Save marabesi/e9f2e2ba5d9c9b595591804d87a49e18 to your computer and use it in GitHub Desktop.
Save marabesi/e9f2e2ba5d9c9b595591804d87a49e18 to your computer and use it in GitHub Desktop.
/**
* http://tutorial45.com/mpu6050-arduino-project/
*/
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
void setup()
{
Serial.begin(9600);
setupAlarm();
pinMode(13, OUTPUT);
}
void loop()
{
Vector rawAccel = mpu.readRawAccel();
Activites act = mpu.readActivites();
if (act.isActivity) {
Serial.println("MOVE MOVE MOVE !!!");
digitalWrite(13, HIGH);
delay(50);
} else {
digitalWrite(13, LOW);
}
}
void setupAlarm() {
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_16G)) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
mpu.setAccelPowerOnDelay(MPU6050_DELAY_3MS);
mpu.setIntFreeFallEnabled(false);
mpu.setIntZeroMotionEnabled(false);
mpu.setIntMotionEnabled(false);
mpu.setDHPFMode(MPU6050_DHPF_5HZ);
mpu.setMotionDetectionThreshold(1);
mpu.setMotionDetectionDuration(5);
mpu.setZeroMotionDetectionThreshold(4);
mpu.setZeroMotionDetectionDuration(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment