Project 04 · The Build Log

Your First Python Project: An LED Strip That Reacts to Music

Intermediate ~2 hours ~$58 in parts, est.

First Python Project: An LED Strip That Reacts to Music

Disclosure: As an Amazon Associate I earn from qualifying purchases.

Every previous project in this series ran software somebody else wrote. This one is yours: a microphone listens to the room, a short Python program does the math, and a five-meter strip of lights dances to whatever’s playing. It’s the project that makes “I can code” stop being a sentence and start being a thing on your wall.

Get the full kit → jumps to the parts list. Any Pi from your starter kit runs this — including the Zero 2 W, though a Pi 4/5 makes the audio processing lazier.

What You’ll Need

One of these parts is a power supply, and it matters more than the lights — read its line twice. Prices are estimates checked in October 2026.

Total: ~$58 est. — and the strip, supply, and mic all get reused by later projects in this series.

Step 1 — Wire It Like You Mean It (30 Minutes)

Four connections, done in this order, with everything unplugged:

  1. Strip power: the strip’s red and black wires go to the 5V supply’s + and − terminals. Not the Pi. (Once more, with feeling.)
  2. Common ground: a wire from the strip’s ground to a Pi ground pin. Two devices, one ground reference — skip this and the data signal is gibberish.
  3. Data: Pi GPIO 18 → level shifter input; shifter output → the strip’s data-in wire. Mind the strip’s arrow direction: data flows with the arrows.
  4. Mic: USB, any port. Then power the strip supply first, the Pi second, and run the strip library’s test pattern (the rpi-ws281x strand test) to prove the chain before writing a line of your own code.

One sizing note the internet argues about: a 300-LED strip at full white could theoretically draw 18A. You will cap brightness in code (Step 3) and music mode never lights everything at full white anyway — the 10A supply plus the brightness cap is the standard, sane combination. If your strip is longer than 5 m, inject power at both ends and size up.

Step 2 — Hear the Room (30 Minutes)

Install the pieces: sudo apt install python3-pyaudio (or pip’s sounddevice — either gives Python ears), plus numpy, the math library every audio project on Earth stands on. Then the concept, which is simpler than it sounds: your program grabs a tiny slice of sound — about 1/20th of a second — and runs an FFT, a standard transform that answers “how much bass, how much midrange, how much treble is in this slice?” Numbers in hand, the program decides colors: bass drives the reds and the brightness pulse, treble sprinkles the far end of the strip. Slice, transform, paint, repeat — twenty times a second, that loop is the visualizer, and everything else is decoration you’ll add because you can.

Step 3 — The Program (45 Minutes, the Good Part)

In outline — the full script is the kind of thing you’ll type, break, and fix, which is the point:

  1. Setup block: strip length, brightness cap (start at 40% — your eyes and the power supply will both agree), GPIO pin, mic sample rate. Constants at the top, because future-you tunes from here.
  2. Listen: open the mic stream; read one chunk of samples into a numpy array.
  3. Measure: FFT the chunk; average the low band (bass), mid band, and high band into three numbers; smooth each against its previous value so the lights glide instead of strobing.
  4. Paint: map bass → pulse brightness from the strip’s start, mids → a moving color wash, highs → sparkle at random positions. Push the frame to the strip.
  5. Loop: forever, until Ctrl-C turns the strip politely off (trap the exit — a strip left mid-frame stays lit, which is a fun bug exactly once).

It’s roughly 30 lines of your code standing on two libraries. When it works — and the moment a kick drum first thumps the whole strip in time is a genuine core memory — start making it yours: new color palettes, a “chill mode” that breathes instead of bouncing, a rainbow that travels on snare hits. Every improvement is another small program you now know how to write.

Troubleshooting the Classics

What NOT to Buy

The Total, Honestly

Build It This Weekend

Strip + its own supply + USB mic + wiring kit. Wire carefully, prove the test pattern, then write thirty lines and put on a song with a good drummer.

Next in the series: we point the Pi’s brain at the natural world — Project 11, the AI bird camera, uses the AI HAT to name every bird at your feeder. More Python, bigger magic.