#include <SSD1306wire.h>
#include <MPU6050_tockn.h>
MPU6050 mpu6050(SSD1306wire);
#define PIR_PIN 2
void setup() {
Serial.begin(115200);
SSD1306wire.begin();
while (!mpu6050.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
mpu6050.setThreshold(3); // Set the threshold for motion detection
pinMode(PIR_PIN, INPUT);
}
void loop() {
Vector rawGyro = mpu6050.readRawGyro();
float gyroMagnitude = sqrt(pow(rawGyro.XAxis, 2) + pow(rawGyro.YAxis, 2) + pow(rawGyro.ZAxis, 2));
Serial.print("Gyro Magnitude: ");
Serial.println(gyroMagnitude);
int motionValue = digitalRead(PIR_PIN);
Serial.print("Motion: ");
Serial.println(motionValue == HIGH ? "Detected" : "Not detected");
delay(100);
}