Music spectrum analyser on LED matrix
Build it step by step
0 of 6 doneWire the matrix
Add the capacitor and the data resistor first.
Test the pixels
Light a single pixel to check the layout and wiring order.
Wire the microphone
Connect the MAX9814 and print raw readings to the Serial Monitor.
Add the FFT
Upload the full sketch and play a tone from a phone.
Tune the scale
Change the 3.0 factor so normal music fills the bars.
Mount
Put a diffuser over the matrix and fit it in a box with the mic hole.
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
- Development BoardsBuyESP32 DevKit V1 × 1
- AudioBuy
- DisplaysBuy
- PowerBuy
- PassivesBuyResistor 330 Ω × 1
- PassivesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| 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 capacitor | Across the matrix 5V and GND | Smooths power |
| ESP32 GPIO4 | 330 Ω resistor then matrix DIN | LED data |
| MAX9814 VDD | ESP32 3V3 | Power |
| MAX9814 OUT | ESP32 GPIO34 | Audio signal |
| MAX9814 GAIN | Left 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.
| Check | Expected |
|---|---|
| Silence | Bars at the bottom |
| Low tone | Left bars rise |
| High tone | Right bars rise |
| Music | Bars 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 →
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.
