Docsity

IOT Practical 10 code TE AIDS SPPU 2024 Pattern, Study Guides, Projects, Research of Internet and Information Access

Toggle sidebar
bg1
#include <Wire.h>
#include <MPU6050.h>
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);
}
OUTPUT:
pf2

Partial preview of the text

Download IOT Practical 10 code TE AIDS SPPU 2024 Pattern and more Study Guides, Projects, Research Internet and Information Access in PDF only on Docsity!

#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); }

OUTPUT: