#include #include MPU6050 mpu; const int LED_DOWN = 8; // LED for downward tilt const int LED_UP = 44; // LED for upward tilt void setup() { Serial.begin(115200); Wire.begin(); pinMode(LED_DOWN, OUTPUT); pinMode(LED_UP, OUTPUT); mpu.initialize(); if (!mpu.testConnection()) { Serial.println("MPU6050 NOT detected!"); while (1); } Serial.println("MPU6050 Ready"); } void loop() { int16_t ax, ay, az, gx, gy, gz; mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); Serial.print("AX: "); Serial.print(ax); Serial.print("\tAY: "); Serial.print(ay); Serial.print("\tAZ: "); Serial.println(az); // Tilt thresholds — adjust if needed int threshold = 8000; // Tilt UP (sensor facing upward, Z positive) if (az > threshold) { digitalWrite(LED_UP, HIGH); digitalWrite(LED_DOWN, LOW); delay(150); digitalWrite(LED_UP, LOW); } // Tilt DOWN (sensor upside-down, Z negative) else if (az < -threshold) { digitalWrite(LED_DOWN, HIGH); digitalWrite(LED_UP, LOW); delay(150); digitalWrite(LED_DOWN, LOW); } else { // No strong tilt → both LEDs off digitalWrite(LED_UP, LOW); digitalWrite(LED_DOWN, LOW); } delay(100); }