Introduction: Audio Visualizer Using RGB LEDs
I have always wanted an audio visualizer for my stereo setup. I have searched Amazon and Aliexpress for an off-the-shelf product that I can use, but couldn't find one that satisfies all my requirements. My requirements were very specific to my cases:
a) I wanted to visualize different spectrums of audio. Most off-the-shelf products use a microphone. But, microphones cannot separate bass and treble, for example. Also, the microphone will pick up any sound from the ambient environment.
b) I wanted to connect the product directly to my system, and not playing music from my phone. Most off-the-shelf products had the option to play music from a phone and send data to the LED strip, by means of either Bluetooth or WiFi.
So, a custom solution was inevitable. Which actually turned out to be a great decision. I added custom animations, static backlight, and motion detection too. Here are the things that were considered for this project:
1) The setup will be physically connected to a stereo system.
2) It will separate different spectrum of the audio.
3) Addressable LEDs, for showing multiple spectrums on the same LED strip simultaneously and maybe for complex animations.
4) An android app to control different modes e.g. currently I have Music Mode, Backlight Mode, and a Rainbow Mode.
Let's get started.
Step 1: Electronics: Schematic
The BoM is available on GitHub repo.
The Brain:
The base of the schematic is the Adafruit Feather nRF52832, which will support the BLE functionalities.
Dissecting the Audio:
MSGEQ7 is the seven-band graphic equalizer IC that separates the spectrums of audio signals.
Other Sensors:
I also added a connector for PIR and an LDR to extend the capabilities of the hardware. For example, if the room is dark and someone comes in, the LEDs will lit up.
Audio Input:
Two audio jacks are added so that I can keep using the actual stereo system.
Note: If you are wondering why I used two 10k ohm resistors in series (R1-R5 and R2-R6) instead of one 20k ohm resistor, that is to reduce the number of unique components I need. I was using 10k for the LDR and it is a pretty common resistor that is used for various other things. If you use PCBA service from any PCB manufacturer, this will help you keep costs at bay.
LED Strip:
There are two connectors for the LED Strip. The longer an LED strip is, the more resistance it has. The more resistance, the more voltage drops along its length. So if the voltage drops too far, the far end LEDs can be affected. Although the data moves through the LEDs in one direction, they don't care what end they receive the power from. So the 2nd connector was added if you want to supply the power from the other end of the LED strip too. If the LED strip length is within 1 meter, you can skip it.
Aliexpress has the cheapest addresable LED strips.
Level Shifter:
The LEDs require 5V whereas nRF52832's I/O level is 3.3V. You can run the LEDs with 3.3V power, but you won't get the full brightness.
So you will need a level shifter. There has been some talk about the level shifter for these LEDs. There are time constraints to control these LEDs. Others have faced issues using various level shifters. So I used a level shifter recommended by others, and never had a problem.
The Eagle files are available here.
Step 2: Electronics: PCB
A PCB wasn't absolutely necessary, but then again I dread using protoboards. PCB manufacturer like JLCPCB doesn't cost much, so I figured why not.
I didn't plan for any enclosure though and instead planned to use an off-the-shelf enclosure. Which turned out to be not very good-looking, because I had to make holes. Lesson learned! If you are serious about enclosure I would suggest making a 3D printed box.
The PCB was designed to fit in this enclosure.
Step 3: Software: Arduino
I used the Arduino framework for the nRF52832. The GitHub repo has two examples, one is without the audio visualizer but with the sensors (LDR and PIR). The code is pretty self-explanatory. Here are the basics:
- All the BLE related stuff are in separate files, "ble.cpp" and "ble.h". The code is copied from one of the Adafruit Feather nRF52932 examples.
- Change the DEVICE_NAME to whatever you want and call BLE_init(). BLE_process_msg() was called in the loop() continuously to see if there is any message from a BLE client.
- Once the message is parsed it was compared with the expected modes: POWER_ON, POWER_OFF, MUSIC, RAINBOW, BACKLIGHT.
- Then the app executed the appropriate function.
In the sensor code, along with all the above,
- the application also continuously checks if the room is dark (LDR) AND if there is some movement (PIR) AND if the LED strip is already OFF.
- If everything checks out, turn ON the LEDs and keep it ON as long as there is movement. Once there is no movement keep the LEDs ON for 30 seconds and then turn it OFF.
Step 4: Software: Android App
The Android App was written using MIT App Inventor. I was really glad to find it. If I had to learn Android Studio this project would have never seen the light. Check out the video to see how to use the app.
The first time you run the app you will have to scan for a device to connect to. But from then on, it will memorize the device and will connect to it as soon as you open the app.
If you have multiple devices, it will only memorize the last device address it was connected to.
The code (*.aia) and the apk files are available in the GitHub repo.
Step 5: Conclusion
This project was a lot of fun for me, considering I had to build an Android App, starting without any knowledge about it. I will suggest though to check out the products from Aliexpress/Amazon first. Sometimes whatever they are offering is good enough for you.
Have fun!