Creating a sound-reactive WS2812B LED strip using a Raspberry Pi Pico can be a fun project! Here’s a basic guide to get you started:
Get the Required Hardware:
- Raspberry Pi Pico
- WS2812B LED strip
- Power supply for the LED strip
- Microphone module or an audio source
Wire up the WS2812B LED Strip:
- Connect the data pin of the WS2812B LED strip to a GPIO pin on the Raspberry Pi Pico.
- Connect the ground and power pins of the LED strip to the corresponding pins on the Pico.
- Connect the microphone or audio source to the Pico.
Install Thonny (Python IDE) and Adafruit CircuitPython:
- Install Thonny on your computer.
- Download the latest CircuitPython UF2 file from the official CircuitPython website and flash it onto your Raspberry Pi Pico.
Install Required Libraries:
- Open Thonny and install the required CircuitPython libraries. You’ll need the adafruit_pixelbuf, adafruit_pypixelbuf, and adafruit_ws2812
Write the Python Script:
- Write a Python script to read the audio input, analyze the sound, and control the WS2812B LEDs
Code-
import array
import math
import audiobusio
import board
import neopixel
# Configuration:
LED_COUNT = 30 # Adjust based on the number of LEDs in your strip
MIC_PIN = board.A0 # Adjust based on the GPIO pin connected to the microphone
BRIGHTNESS = 0.2 # Adjust the LED brightness
pixels = neopixel.NeoPixel(board.GP0, LED_COUNT, auto_write=False)
mic = audiobusio.PDMIn(MIC_PIN, sample_rate=16000, bit_depth=16)
def normalize(values, target_rms):
current_rms = math.sqrt(sum(i ** 2 for i in values) / len(values))
scale = target_rms / current_rms
return array.array(“H”, int(i * scale) for i in values)
while True:
samples = array.array(“H”, mic.record(samples))
normalized_samples = normalize(samples, 32767)
for i in range(LED_COUNT):
intensity = normalized_samples[i] / 65535.0
pixels[i] = (int(intensity * 255), 0, 0)
pixels.show()
Upload and Run the Script:
- Save the Python script to your Raspberry Pi Pico.
- Run the script, and the LED strip should react to the sound picked up by the microphone.
Remember, this is a basic example, and you can customize the script based on your preferences. Adjustments can be made to the LED arrangement, color patterns, and sensitivity to create a more dynamic sound-reactive LED display. Have fun experimenting!
Â
Leave a Reply
You must be logged in to post a comment.