#include #include MPU6050 mpu; const int ledPin = D1; const int buzzerPin = D2; float ax, ay, az; float pitch; const float badPostureThreshold = 15.0; void setup() { Serial.begin(115200); Wire.begin(); pinMode(ledPin, OUTPUT); pinMode(buzzerPin, OUTPUT); mpu.initialize(); if (!mpu.testConnection()) { Serial.println("MPU6050 no conectado"); while (1); } Serial.println("MPU6050 listo"); } void loop() { int16_t ax_raw, ay_raw, az_raw; mpu.getAcceleration(&ax_raw, &ay_raw, &az_raw); ax = ax_raw / 16384.0; ay = ay_raw / 16384.0; az = az_raw / 16384.0; pitch = atan2(ax, sqrt(ay * ay + az * az)) * 180 / PI; Serial.print("Pitch: "); Serial.println(pitch); if (abs(pitch) > badPostureThreshold) { digitalWrite(ledPin, HIGH); tone(buzzerPin, 1200); // 🔔 sonido } else { digitalWrite(ledPin, LOW); noTone(buzzerPin); // 🔕 silencio } delay(100); }