Last active
May 9, 2018 13:59
-
-
Save marabesi/e9f2e2ba5d9c9b595591804d87a49e18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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