กลับหน้าหลัก
views
How to Use ESP32 with MAX4466 Sound Sensor to Control LED
Last updated on

How to Use ESP32 with MAX4466 Sound Sensor to Control LED


How to Use ESP32 with MAX4466 Sound Sensor to Control LED

Required Components

  • ESP32 NodeMCU (ESP-WROOM-32)
  • MAX4466 Microphone Sensor (High-sensitivity)
  • Red LED 5mm
  • 220 Ohm Resistor
  • Breadboard and Jumper Wires
  • Micro USB Cable for ESP32

How MAX4466 Works

The MAX4466 is an audio amplifier IC that takes input from an Electret microphone and amplifies it into an Analog signal ready for reading by a microcontroller. The key feature is the adjustable gain potentiometer on the back of the module, which lets you set the sensitivity for your specific use case.

The Analog output voltage varies with sound loudness. Loud sounds produce higher voltage readings, while quiet environments produce lower readings.

Wiring ESP32, MAX4466, and LED

Breadboard wiring diagram showing ESP32 connected to MAX4466 microphone module and LED with resistor, labeled clearly
ComponentPinConnect To ESP32
MAX4466VCC3.3V
MAX4466GNDGND
MAX4466OUTGPIO34 (D34)
LEDAnode (long leg)GPIO2 (D4) via 220Ω resistor
LEDCathode (short leg)GND

Place the 220 Ohm resistor in series with the LED to limit current and prevent damage.

Arduino Code for Reading Sound and Controlling LED

// Pin definitions
const int MIC_OUT = 34;    // Analog input from MAX4466
const int LED_OUT = 2;     // LED control pin

// Sound threshold value
// Adjust this based on your environment
const int SOUND_THRESHOLD = 2000;

void setup() {
  Serial.begin(115200);
  pinMode(LED_OUT, OUTPUT);
  pinMode(MIC_OUT, INPUT);
  
  // Start with LED off
  digitalWrite(LED_OUT, LOW);
}

void loop() {
  // Read Analog value from MAX4466 (0-4095 on ESP32)
  int soundLevel = analogRead(MIC_OUT);
  
  // Send value to Serial Plotter
  Serial.println(soundLevel);
  
  // Turn LED on if sound exceeds threshold
  if (soundLevel > SOUND_THRESHOLD) {
    digitalWrite(LED_OUT, HIGH);
  } else {
    digitalWrite(LED_OUT, LOW);
  }
  
  delay(10);  // Small delay
}

Points to adjust: The SOUND_THRESHOLD value depends on your actual environment. If the microphone picks up too much sound, increase this value or turn down the gain potentiometer on the back of the MAX4466.

How to Upload and Monitor

  1. Open Arduino IDE, select Board as ESP32 Dev Module
  2. Choose the correct Port connected to your board
  3. Upload the code. When you see the Boot message, hold the BOOT button on the board
  4. After upload completes, open Serial Plotter (Tools → Serial Plotter) set to 115200 baud
Serial Plotter window displaying waveform graph from MAX4466 sound sensor readings

Testing the Circuit

  1. Observe the Serial Plotter - you will see a waveform that fluctuates with ambient sound
  2. Clap your hands or tap the table near the microphone
  3. If the sound is loud enough, the graph line will spike above the threshold and the LED will light up
  4. Stop making noise and the LED will turn off
Practical test setup showing ESP32 connected to MAX4466 and LED on a breadboard

Troubleshooting LED Not Working

  • Verify MAX4466 VCC receives 3.3V correctly
  • Open Serial Monitor to check raw values - if values change, the microphone is working
  • If values stay flat, double-check the OUT to GPIO34 connection
  • Try lowering SOUND_THRESHOLD if your environment is quieter than expected

Extension Ideas

Once the basic circuit works, you can extend it in several ways:

  • Change the threshold to detect specific loud sounds like clapping
  • Add multiple LEDs to build a simple VU meter showing sound level
  • Send data to cloud storage via Wi-Fi when sound is detected

Reference Video

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ความคิดเห็น