

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include #include MPU6050 mpu; void setup() { Serial.begin(9600); Wire.begin(); Serial.println("Initializing MPU6050..."); mpu.initialize(); if (mpu.testConnection()) Serial.println("MPU6050 Connected ✔"); else Serial.println("Connection Failed "); } void loop() { float ax = mpu.getAccelerationX() / 16384.0; float ay = mpu.getAccelerationY() / 16384.0; float az = mpu.getAccelerationZ() / 16384.0; // convert to simple magnitude float accel = sqrt(ax * ax + ay * ay + az * az); Serial.print("Acceleration: "); Serial.println(accel); // -------- ML CLASSIFICATION -------- if (accel < 1.0) { Serial.println("DEVICE STATE: IDLE"); Serial.println("ACTIVITY: None"); } else if (accel < 1.6) { Serial.println("DEVICE STATE: ACTIVE"); Serial.println("ACTIVITY: Walking"); } else { Serial.println("DEVICE STATE: HIGH ACTIVITY"); Serial.println("ACTIVITY: Running"); } // -------- ANOMALY DETECTION -------- if (accel > 2.5) { Serial.println("ALERT: Anomaly / Fault Detected!"); } Serial.println("------------------------"); delay(1000); }