#include #include #define SERVO_PIN 2 // GPIO2 para el servo #define LED_PIN 5 // GPIO5 para los NeoPixels #define SOUND_SENSOR_PIN 2 // GPIO2 (D2) conectado a la salida analógica del KY-038 #define NUM_LEDS 30 #define SOUND_THRESHOLD 800 // Ajusta este valor después de probar el llanto real Servo myServo; Adafruit_NeoPixel pixels(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { Serial.begin(115200); myServo.attach(SERVO_PIN); myServo.write(0); // Posición inicial del servo pixels.begin(); pixels.clear(); pixels.show(); Serial.println("Sistema listo. Escuchando sonidos (llanto de bebé)."); } void loop() { int soundLevel = analogRead(SOUND_SENSOR_PIN); Serial.print("Nivel de sonido: "); Serial.println(soundLevel); // Observa estos valores para calibrar if (soundLevel > SOUND_THRESHOLD) { // Llanto detectado myServo.write(10); for (int i = 0; i < NUM_LEDS; i++) { int r = random(100, 256); int g = random(0, 150); int b = random(100, 256); pixels.setPixelColor(i, pixels.Color(r, g, b)); } pixels.show(); } else { // Silencio o ruido débil myServo.write(0); pixels.clear(); pixels.show(); } delay(100); }