Projects / Music spectrum analyser on LED matrix

Music spectrum analyser on LED matrix

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP3218.0 mA

    Wire the matrix

    Add the capacitor and the data resistor first.

  2. ESP32

    Test the pixels

    Light a single pixel to check the layout and wiring order.

  3. ESP32

    Wire the microphone

    Connect the MAX9814 and print raw readings to the Serial Monitor.

  4. ESP32

    Add the FFT

    Upload the full sketch and play a tone from a phone.

  5. ESP32

    Tune the scale

    Change the 3.0 factor so normal music fills the bars.

  6. ESP3218.1 mA

    Mount

    Put a diffuser over the matrix and fit it in a box with the mic hole.

In short

How do you build a music spectrum analyser on LED matrix?

A microphone feeds an FFT on an ESP32, which draws 8 frequency bars on a WS2812 8 × 8 matrix. You need ESP32 DevKit V1, MAX9814 microphone with AGC, WS2812B 8x8 RGB LED matrix, 5 V 2 A USB adapter, Resistor 330 Ω, Electrolytic capacitor 1000 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
8

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
5 V USB adapter +Matrix 5V, ESP32 VIN and capacitor +Power
5 V USB adapter -Matrix GND, ESP32 GND, MAX9814 GND and capacitor -Common ground
1000 µF capacitorAcross the matrix 5V and GNDSmooths power
ESP32 GPIO4330 Ω resistor then matrix DINLED data
MAX9814 VDDESP32 3V3Power
MAX9814 OUTESP32 GPIO34Audio signal
MAX9814 GAINLeft open (60 dB)Gain

Code

Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module". Install "Adafruit NeoPixel" and "arduinoFFT" by Enrique Condes (version 2 or later). Many 8 × 8 matrices are wired in a zigzag, so if the bars look scrambled, change the pixel index calculation for odd rows. Brightness is held low so 64 LEDs stay within the 5 V adapter's rating. The MAX9814 output sits around half its supply voltage and the code removes that offset with dcRemoval.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Adafruit_NeoPixel.h>
#include <arduinoFFT.h>

const uint16_t N = 64;                    // samples per frame
const double FS = 10000;                  // 10 kHz sampling, so about 156 Hz per bin up to 5 kHz
double vReal[N], vImag[N];
ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, N, FS);
Adafruit_NeoPixel px(64, 4, NEO_GRB + NEO_KHZ800);
float peak[8] = { 0 };
float level[8] = { 0 };

void setup() {
  px.begin();
  px.setBrightness(25);                   // keeps the current low
  analogSetPinAttenuation(34, ADC_11db);
}

void loop() {
  unsigned long t = micros();
  for (uint16_t i = 0; i < N; i++) {
    while (micros() - t < i * (1000000UL / (unsigned long)FS)) {}
    vReal[i] = analogRead(34);
    vImag[i] = 0;
  }
  FFT.dcRemoval();
  FFT.windowing(FFTWindow::Hamming, FFTDirection::Forward);
  FFT.compute(FFTDirection::Forward);
  FFT.complexToMagnitude();

  px.clear();
  for (byte band = 0; band < 8; band++) {
    double sum = 0;
    for (byte k = 1 + band * 4; k < 5 + band * 4; k++) sum += vReal[k];     // bins 1 to 32 in groups of four
    float h = log10(1 + sum / 4.0) * 3.0;                                  // log scale, roughly 0 to 8
    h = constrain(h, 0, 8);
    level[band] = max(h, level[band] - 0.4f);                             // bars fall smoothly
    if (level[band] > peak[band]) peak[band] = level[band]; else peak[band] = max(0.0f, peak[band] - 0.1f);
    for (byte y = 0; y < (byte)level[band]; y++) px.setPixelColor(y * 8 + band, y < 5 ? px.Color(0, 255, 0) : (y < 7 ? px.Color(255, 160, 0) : px.Color(255, 0, 0)));
    px.setPixelColor((byte)peak[band] * 8 + band < 64 ? (byte)peak[band] * 8 + band : 63, px.Color(255, 255, 255));
  }
  px.show();
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
SilenceBars at the bottom
Low toneLeft bars rise
High toneRight bars rise
MusicBars dance with peak dots falling slowly

If it does not work

Bars scrambled

Zigzag wiring. Change the index calculation for odd rows.

All bars always full

Reduce the scale factor or the microphone gain.

Nothing moves

Check MAX9814 OUT on GPIO34 and its power.

Board resets

Lower the brightness and use a 2 A adapter.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the music spectrum analyser on LED matrix?

ESP32 DevKit V1, MAX9814 microphone with AGC, WS2812B 8x8 RGB LED matrix, 5 V 2 A USB adapter, Resistor 330 Ω, Electrolytic capacitor 1000 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the music spectrum analyser on LED matrix take to build?

About 150 minutes for a intermediate maker, in 6 steps.

How do I know the music spectrum analyser on LED matrix works?

Silence: Bars at the bottom. Low tone: Left bars rise. High tone: Right bars rise.

Bars scrambled: what should I check?

Zigzag wiring. Change the index calculation for odd rows.

All bars always full: what should I check?

Reduce the scale factor or the microphone gain.

Nothing moves: what should I check?

Check MAX9814 OUT on GPIO34 and its power.

Board resets: what should I check?

Lower the brightness and use a 2 A adapter.