All projects
🎵🟡 Intermediate 1 hr

LED Music Visualizer

LEDs that dance up and down with the beat of your favourite song.

What You'll Build

This project turns sound into light. A microphone module listens to the room, and a row of LEDs lights up higher when the music gets louder. Play a quiet song and only two or three LEDs glow; drop the bass and the whole bar jumps to the top.

What You Need

  • Arduino Uno
  • Sound sensor / electret module
  • 8 × LED or LED bar
  • 8 × 220Ω resistor

How It Works

Sound is vibrating air, and the microphone turns those vibrations into a wobbling voltage. Rather than reading one instant, the code samples the microphone many times over a short window and measures the difference between the loudest and quietest points. That gap — the amplitude — is what you map onto the LED bar.

Wiring

  1. 1Sound module VCC → 5V, GND → GND, analog OUT → A0.
  2. 2Eight LEDs on pins 2 to 9, each with its own 220Ω resistor to ground.

Step-by-Step Instructions

  1. 1

    Line up the LEDs

    Place the eight LEDs in a straight row on the breadboard. A ready-made LED bargraph works too and saves a lot of wiring.

  2. 2

    Test the microphone

    Print the raw analog value and clap. If the number barely moves, turn the small trimmer on the module to increase gain.

  3. 3

    Sample a window

    Instead of one reading, take fifty readings in a row and keep the highest and lowest. The difference is the loudness.

  4. 4

    Map to LEDs

    Convert the loudness into a number from 0 to 8 and light that many LEDs, so the bar rises and falls with the music.

  5. 5

    Calibrate for your room

    Adjust the top of the mapping range until quiet music uses the bottom LEDs and loud music reaches the top without pinning.

Arduino Code

led-music-visualizer.ino
const int MIC = A0;
const int LEDS[8] = {2, 3, 4, 5, 6, 7, 8, 9};

void setup() {
  for (int i = 0; i < 8; i++) pinMode(LEDS[i], OUTPUT);
  Serial.begin(9600);
}

int loudness() {
  int high = 0, low = 1023;
  for (int i = 0; i < 50; i++) {
    int v = analogRead(MIC);
    if (v > high) high = v;
    if (v < low)  low = v;
  }
  return high - low;
}

void loop() {
  int level = map(loudness(), 0, 300, 0, 8);
  level = constrain(level, 0, 8);

  for (int i = 0; i < 8; i++) {
    digitalWrite(LEDS[i], i < level ? HIGH : LOW);
  }
  delay(20);
}

Understanding the Code

const int LEDS[8] = {...}

An array — one variable holding eight pin numbers so you can loop over them.

high - low

The peak-to-peak swing of the sound wave. Bigger swing means louder music.

constrain(level, 0, 8)

Clamps the value so a very loud noise cannot ask for LED number twelve.

i < level ? HIGH : LOW

A compact if/else. Light this LED only if its position is below the current level.

Challenges & Upgrades

Make the bar fall back down smoothly instead of instantly.
Add a peak dot that hangs at the highest recent level.
Swap in an addressable LED strip and add colours.

Troubleshooting

😖 All LEDs stay on

Fix: Your mapping range is too small. Increase the 300 until quiet rooms give a level of zero.

😖 No reaction at all

Fix: Make sure you are using the module's analog output, not its digital one.

Up next

🎲 Electronic Dice

Build This