Analog LED Audio Visualizer (for Car)
by PEACEiiiii in Circuits > Arduino
45 Views, 0 Favorites, 0 Comments
Analog LED Audio Visualizer (for Car)
This project is an audio visualizer I made for my car. Most modern led strips use digital LEDs over analog ones.
Digital LED strips are "smart" in that each LED on the strip is individually addressable through a data signal line. These strips have driver ICs paired with each individual LED. This allows for a MCU (like an Arduino) to control the whole strip with just one digital pin.
I was curious about reproducing this functionality with analog LED strips. These LED strips are "dumb" in that they have no digital signal line preventing each individual LED from being a different colour than any of the others: they all "act together". A multicolour LED strip has a red, green and blue power rail to power the red, green and blue LEDs on the strip. One can use Pulse-Width Modulation using an MCU to vary the brightness and colour.
Inspired by Xiaomi's electric cars, the goal of this project was to use analog LEDs as an "audio visualizer", meaning that the LEDs would pulse to the beat of the music that I play through the car speakers. I initially thought the best way to do this would be to calculate the BPM of the music and pulse the music at this BPM. This proved unsuccessful as the pulses looked unnatural and did not mimic the music. Instead I used a spectrum analyzer chip (MSGEQ7) to capture the low frequencies of the music and pulse using this data.
Supplies
Everything for this project was purchased from Amazon or Digikey.
- LED strip: I used a VERY cheap 5V analog led strip from Amazon. I did not use the remote/controller that came with the LEDs. (https://www.amazon.ca/dp/B09BG32K21?ref=ppx_yo2ov_dt_b_fed_asin_title)
- Arduino Uno (for testing) and Nano (embedded in circuit)
- Lots of 3.5 mm (aux) cable, including splitter.
- Prototype Board
- TN0702N3-G-ND. This is the NMOS I used for PWM switching.
- I chose it as it has a high drain to source voltage of 20V. This means it can withstand a 20V difference from drain to source when off. This is well above the 5V required.
- It has a minimum Rds On at 5V. This means that it conducts the best at 5V drain to source, which is exactly our operating voltage. Therefore this is a "logic level" NMOS.
- It has a current rating of 0.5A continuous and 1A pulsed. We will have one MOSFET for each colour channel, and each channel was determined to draw about 0.3A at 5V. Since we will not be using the whole strip, this current rating should be more than enough.
- MSGEQ7 chip
- This is the brains of the operation. It is a spectrum analyzer that essentially uses a series of seven cascaded bandpass filters to output seven frequency bands signal strength to its ANALOG OUTPUT pin. The output is multiplexed, and the RESET and STROBE pins control which frequency band is output.
- I used only the lowest frequency band (63 Hz BP) allowing the music to pulse to the bass in the music.
- Potentiometer, resistors and capacitors.
- Soldering equipment
- DMM for circuit testing
PWM Circuit Design
First things first, let's create a PWM circuit using an NMOS so that we can modulate the brightness of each colour channel and achieve different colours. As tempting as it would be to tie the arduino digital pin straight to the LED strip, an arduino cannot be used as a power supply due to its limited current handling capabilities. Therefore, the circuit above allows us to power the LED strip with an external power supply with a higher current rating.
Here are some key characteristics of the circuit:
- The NMOS source is grounded
- Uses a 10kΩ pull down resistor on the gate. This ensures that pulls the gate voltage to ground when the PWM signal is inactive.
- The arduino ground is tied to the circuit ground.
Audio Processing Circuit
I decided to use wired audio connections for this project as they simplify things significantly. This circuit takes Audio in from an 3.5mm aux cable and outputs an analog signal that will represent strength of the music's bass frequencies at any instant in time. This circuit comes essentially from the MSGEQ7 data sheet. A few important notes about this circuit:
- The MSGEQ7 opperates at 5V Vcc which makes it compatible with the rest of our circuit.
- The STROBE and RESET pins are digital inputs (0V or 5V) and are for selecting the correct frequency band
- The GND pin is (confusingly) not 0V but instead a cirtual ground of 2.5V which explains the voltage divider.
Final Schematic
The final circuit uses an arduino nano as an MCU, though any MCU will work. A pontetionmeter on the circuit board is used to select the colour of the LEDs (using a colour wheel mapping). Each channel (R, G and B) is controlled by its own PWM circuit. The power supply is 5V coming from the cars 12V socket and a voltage regulator device (car charger) as shown in the image. This supplies a high quality 5V supply to the circuit.
The first schematic shows how the Nano is wired, which is fairly simple. The second image shows how the audio connections were made from the phone to the circuit and speakers using 3.5mm cables.
Now that the hardware is fucntional, we can dive into the code.
Important note: the arduino ground, circuit ground and audio source ground must all be tied together.
Arduino Code
The analog output of the MSGEQ7 must be processed to properly modulate the analog LEDs. The code in the file above is not perfect, as I not great at coding. This is another reason I chose a hardware spectrum analyzer instead of going with FFT which would require significant signal processing.
The main function of the code (attached) is to select the correct frequency band in the MSGEQ7 by using the STROBE and RESET pins. The strobe timing diagram (attached) shows the digital output required to select different frequency bands, and my code simply pulses the STROBE and RESET pins once to acquire the correct analog output. The next steps are as follows:
- A noise threshold was applied to ignore low-level fluctuations in the MSGEQ7 output. The chip had significant signal noise, likely caused by audio interference or electromagnetic coupling from the nearby PWM switching circuits.
- Smoothing is key to the punchy look of the LEDs. I used a simple exponential moving average in which the smoothing factor changes depending on whether the signal is rising (faster response so larger factor) or falling (slower response so smaller factor).
- Automatic gain control is essentially an envelope tracker that should set an upper bound on the smoothed signal so that a weaker signal maps to the same strength as a stronger signal (allowing for the user to change the volume without affecting the LED brightness). More testing is required on this and I would love feedback.
- The processed signal is mapped to three 8-bit values depending on the colour selected by the potentiometer value. The arduino analogWrite function uses these values for pulse-width modulation.
Downloads
Assembly
Now it's time to acquire the hardware and assemble everything. I used a cheap soldering iron from Canadian Tire and two different prototype boards. I would highly recommend a "breadboard" style prototype board as the traces are connected allowing for easy organization and less soldering. The final circuit board has three NMOS's (one for R, G and B of the analog LEDs), an Arduino Nano running on the external 5V from the car, and a potentiometer for colour selection.
In the image you can see I installed the LEDs under the dash of my car using zip ties and tape, but there are definitely better ways of doing this, and this is something I will likely change in the future. Also for cabling I would recommend using 22AWG multi-core cable which helps prevent loose or broken wiring.
Some improvements:
- Improved signal processing. Currently its fairly bare bones, and music that has lower bass levels can cause jitter and noise in the LEDs which looks pretty bad. Perhaps a peak detector can be implemented.
- More LEDs. I would like to install more LEDs above the dash in my car, but it is a hassle soldering the wires to the cheap LEDs, so I will leave it for now.
- Incorporating the LEDs into a protective enclosure/structure to prevent damage and improve aesthetics would be a future option.
- I would love to work on a 2D instead of 1D audio visualizer in the future. There are so many more possibilities.
This project is currently in a "minimum viable product/prototype" form. But I hope to have time to create a second prototype in the future. After working with analog LEDs I finally understand why digital LEDs are so practical and prevalent.
Check out the demo video! Thanks for reading.
Demo