Arduino Audio Visualizer

by Shawn5123 in Circuits > Arduino

64 Views, 1 Favorites, 0 Comments

Arduino Audio Visualizer

Screen Shot 2025-01-22 at 7.10.35 AM.png

How to Build a Sound-Reactive LED System Using Arduino and a Sound Sensor/Microphone


This device takes the surrounding sound input and provides the raw analog value of the sound signal to the Arduino. On the Arduino, you can assign specific colors to different signal ranges. When it runs, you'll see a real-time audio visualizer come to life right in front of you!

This project uses a sound sensor or microphone to capture sound from the surroundings and sends the raw analog signal to the Arduino. On the Arduino, you can define specific colors for different ranges of sound signal values. When the system runs, it transforms the sound into a vibrant, real-time music visualizer right before your eyes.

Supplies

Screen Shot 2025-01-22 at 7.17.44 AM.png

Circuit Diagram

Screen Shot 2025-01-22 at 7.14.21 AM.png

(A diagram for the circuit I am about to show)

Step by Step Building Guide

Connecting the Arduino to the Sound Sensor:

  1. Connect the A0 pin on the sound sensor to the A0 pin on the Arduino.
  2. Connect the GND pin on the sound sensor to any GND pin on the Arduino.
  3. Connect the 5V pin on the sound sensor to the 5V pin on the Arduino.

Connecting the LED Strip to the Arduino:

  1. Attach the LED strip's DIN (Data In) pin to a resistor (optional), then connect it to Digital Pin 5 on the Arduino.
  2. Connect the 5V pin of the LED strip to either the 5V pin on the Arduino or an external power source.
  3. Connect the GND pin of the LED strip to either the GND pin on the Arduino or the ground of the external power source.

Setting Up the Code:

  1. Download and install the Arduino IDE from the official website (Arduino IDE Software). Upload the project code to your Arduino UNO or NANO using the IDE.

Powering Up:

  1. Power on the Arduino to bring your sound-reactive LED system to life!


Code

(A Link To The Code Used)

Downloads

Code Explanation

Screen Shot 2025-01-22 at 9.26.11 PM.png
Screen Shot 2025-01-22 at 9.26.30 PM.png

Code Explanation of loop():

1. Read Sound Input

  1. The code reads sound intensity from the sensor connected to analog pin A0:
  2. s = analogRead(A0);
  3. The sound value (s) is used to determine if a new wave should be triggered.

2. Check Sound Threshold

  1. A new wave is triggered if the sound value exceeds the threshold (SOUND_THRESHOLD = 200) and at least 100ms has passed since the last wave:
  2. if (s > SOUND_THRESHOLD && millis() - lastSoundTime > 100) {
  3. createNewWave();
  4. lastSoundTime = millis();
  5. }

3. Update Wave Animation

  1. The animation of active waves is updated periodically based on the WAVE_SPEED_DELAY (50ms):
  2. if (millis() - lastWaveUpdate > WAVE_SPEED_DELAY) {
  3. updateWaves();
  4. lastWaveUpdate = millis();
  5. }

4. Refresh LED Display

  1. The LED strip is refreshed to display the updated wave patterns:
  2. FastLED.show();

Helper Functions:

createNewWave()

  1. Activates a new wave if there’s an available slot:
  2. Finds the first inactive slot in the wavePositions array.
  3. Assigns a random starting position and a color from the waveColors[] array.

updateWaves()

  1. Moves active waves along the LED strip:
  2. Increments each wave’s position stored in the waveProgress[] array.
  3. Deactivates waves that move past the LED strip boundary.


Customizable Options

Screen Shot 2025-01-22 at 9.35.41 PM.png
Screen Shot 2025-01-22 at 9.39.11 PM.png
Screen Shot 2025-01-22 at 9.40.09 PM.png

Customizable Options for the Arduino Audio Visualizer

  1. Wave Length Adjustment
  2. Modify the code to increase or decrease the number of LEDs lit up per wave for more dramatic or subtle visual effects.
  3. Color Mapping
  4. Customize the colors assigned to different sound levels or frequencies. For example, you can change the base colors to match specific moods, themes, or events.
  5. Sensitivity Settings
  6. Adjust the microphone sensitivity to make the visualizer react to soft or loud sounds more effectively.
  7. Number of Waves
  8. Change the maximum number of active waves to suit different strip lengths or visual preferences.
  9. Wave Speed
  10. Control how fast the waves move by adjusting the delay between updates, creating either rapid or smooth motion effects.
  11. Sound Threshold
  12. Set different thresholds to trigger LED effects only for specific sound intensities, filtering out background noise.

Applications

Screen Shot 2025-01-22 at 9.57.23 AM.png

Applications of a Sound-Reactive LED:


  1. Photo Frames: Enhance photo displays with sound-reactive lighting that syncs with music or ambient sounds, creating a dynamic and personalized effect.
  2. Home Decor: Use it to light up shelves, mirrors, or walls, adding a modern and interactive element to your space.
  3. Party Lighting: Perfect for parties or events, where the LEDs can match the rhythm of music and energize the atmosphere.
  4. Music Visualization: Pair it with a speaker system to create a real-time mini visualizer that reacts to songs.
  5. DIY Art Projects: Combine the LEDs with custom shapes, designs, or sculptures to create unique sound-reactive art installations.
  6. Ambient Lighting: Use it for subtle mood lighting that changes dynamically based on the sounds in your environment.