Arduino Lesson 6: The Sound Reactive LED – Make Your Light Dance to Music!

In this lesson, we’ll learn how to use a microphone to make our LED react to sound! The louder the sound, the brighter the LED will glow. Get ready to create a light show that dances to music!

Objective: Learn how to use a microphone to detect sound and control the brightness of an LED.

Materials:

  • Arduino Uno board
  • Breadboard
  • LED (any color)
  • 220-ohm resistor
  • Electret microphone
  • Jumper wires

Steps:

  1. Review: Recap previous lessons and components, including sensors and analog input.
  2. Meet the Microphone: Introduce the electret microphone and explain how it converts sound waves to electrical signals.
  3. Building the Circuit: Connect the microphone, LED, resistor, and Arduino board to the breadboard. The microphone should be connected to an analog input pin on the Arduino.
  4. Programming the Sound Response: Copy and paste the code below

Step 1: Connecting the Microphone

  1. Find the three legs of the electret microphone: One is positive (+), one is negative (-), and one is for the signal (often marked with a dot or a different color).
  2. Connect the positive leg of the microphone to a 5V power rail on the breadboard:
  3. Connect the negative leg of the microphone to a ground rail on the breadboard:
  4. Connect the signal leg of the microphone to an analog input pin on the Arduino: We’ll use pin A0 in this lesson.

Step 2: Connecting the LED and Resistor (Review)

  1. Connect the LED and resistor as you did in Lesson 1: Make sure the LED’s longer leg is connected to a power rail and the resistor’s other leg is connected to the same row as the LED’s shorter leg.

Step 3: Connecting the Arduino (Review)

  1. Connect the LED’s longer leg to digital pin 13 on the Arduino: This is the output pin for the LED.

Step 4: Programming the Arduino

  1. Open the Arduino IDE.
  2. Copy and paste the following code:
const int ledPin = 13;   // LED connected to pin 13
const int micPin = A0;  // Microphone connected to analog pin A0

void setup() {
  pinMode(ledPin, OUTPUT); // Set LED pin as output
}

void loop() {
  int micValue = analogRead(micPin); // Read microphone value

  // Map microphone value to LED brightness (0-255)
  int brightness = map(micValue, 0, 1023, 0, 255); 

  analogWrite(ledPin, brightness); // Control LED brightness
}

content_copyUse code with caution.Arduino

  1. Upload the code to the Arduino board.

Step 5: Test the Sound Reactive LED

  1. Make a sound near the microphone: You should see the LED glow brighter as the sound gets louder.
  2. Try different sounds: Experiment with different noises, music, or even your voice to see how the LED reacts.

Congratulations! You’ve created a sound reactive LED circuit!

Let’s Experiment:

  • Adjust the brightness: Change the numbers in the map(micValue, 0, 1023, 0, 255) line to adjust the LED’s brightness range.
  • Add a delay: Try adding a delay in the loop() function to make the LED react more slowly to sound changes.

Keep experimenting with sound and have fun with Arduino!