You can find a video about this project on my YouTube channel here.
Pretty lights, music, open source and computers: all of my favorite things.
For those that are not into PC gaming, you may not be aware that there is a large DIY PC community based around the idea that you should build your own PC to get the best price to performance for tasks like gaming, media creation and things like that. Attached to the performance benefits are also aesthetics. People spend a lot of time and money to make sure their PC looks the sleekest, whether it be a matching color theme for all of the components, cable management or one of the newer features: RGB LEDs. There's even software and special headers on the motherboards to support the RGB craze. The issue though is that different bits of software have different features or require different hardware to control the LED strips. There are also different voltages of LED strips (12V vs. 5V depending) depending on the brand, so you end up committing to one version of a platform depending on your brand choice and of course there's a premium for the options with the most features. The LED strips from these companies also tend to be on the shorter side, often requiring 3-4 to make it around the perimeter of your case and you're paying a premium for the compatibility with that company's software and/or hardware.Project Background
I wanted LEDs in my case but didn't want to go down the routes that were available from the various companies, especially when I saw a demo of the effects that the different software suites were capable of. I quickly realized that you could achieve the same effects with Adafruit's NeoPixels and an Arduino with nicer looking results, more control and a lot cheaper. This is a great sub-in solution for probably the PC community's best option at this time: an NZXT Hue+, which is basically a microcontroller in a box that mounts in a hard drive bay and controls your lights with a software suite. I actually entitle my videos for this project on YouTube with a reference to this product in an attempt to let the PC DIY community that DIY options are available.
One thing that I wanted to achieve with my iteration of the lights was to have them react to music. This was an effect that was really lacking in the commercial offerings and I was pretty sure I could do it with the MSGEQ7 IC from Sparkfun, which allows you to build audio spectrum analyzers by taking an audio input signal and splitting it out into 7 bands on the audio spectrum. I had used the MSGEQ7 in my very first Arduino project that wasn't just an example sketch. I had built a circuit with 14 LEDs (2 for each band on the audio spectrum) and had it react to music. At the time I was still in college so this was quite useful for parties. I basically wanted to port this concept over to the NeoPixels so that individual pixels on the strand would react to different bands on the audio spectrum.
I ended up using a code structure that uses arrays of pixels after seeing a great bit of example NeoPixel code on the Adafruit forums here written by adafruit_support_rick. If you're trying to do something a bit out of the ordinary with NeoPixels I definitely recommend searching the Adafruit forums. There are a lot of hidden gems of example code in there that are super helpful. I declared each pixel as an integer that could be popped into an array and then put in arrays of seven pixels utilizing integer pointers so that each pixel would hold the value of the spectrum bands later in the code (e.g. the first pixel is the lowest band 63Hz, the second is 160Hz all the way up to the seventh which is the highest 16kHz and then the cycle begins again with the next array of seven). Then I did the normal NeoPixel things and the default piece of example code for the MSGEQ7. To get the lights to react to the music I passed an argument for byte "hue" where I had its value tied to the PWMvalue being read by the MSGEQ7. I then used the "strip.setPixelColor" command from the NeoPixel library to assign a color to each array. I have the default as a pinkish/purple color that matches my color scheme and then I have the hue byte being added to the blue portion of the RGB color code. By doing this, it causes the "blue-ness" of each pixel to increase depending on how much volume is being read on its assigned spectrum band. I chose blue because the other color in my case is blue. If you want to take a deep dive into the code, I do have a video on it here.Circuit
The circuit is fairly simple. The NeoPixel strand is connected to 5V, GND & a data pin on the Arduino. The MSGEQ7 circuit can be found in the datasheet here, which allows the spectrum bands to be multiplexed. The audio signal is sent to pin 5 on the MSGEQ7 and traditionally a headphone jack or something similar is used, with left and right audio being hooked up to pin 5 and the GND pin on the jack connected to GND. I wanted this project to live completely inside my PC case though with no awkward wires or cables coming out of odd places. So I decided to use the HD Audio header, which is normally connected to the motherboard, to input audio via the mic input on the case. I use an mbox2 for my audio input and output on my computer, so I wasn't using the integrated audio making it possible to sacrifice it for this project. I found a pin out for the header here (page 20) and hooked up pins 1 and 3 (AUD_MIC & AUD_MIC_BIAS) to pin 5 on the MSGEQ7 and pin 2 on the header to GND. I then ran a 3.5mm audio cable from the headphone output on the mbox2 to the mic input on the front of my case, allowing for audio to get to the circuit. By adjusting the headphone volume I can affect the intensity of the light effect.First Install
I first worked on this project back in October 2016 and at the time I was honestly not very comfortable with soldering. I also hadn't explored other microcontroller boards besides the Arduino Uno. Because of all of this, the first installation of this project was a little bit clunky looking back. I got an Arduino Uno project enclosure to house an Arduino Uno along with the MSGEQ7 circuit on a breadboard. This allowed it to live in a hard drive tray in the bottom of the case. The NeoPixels and HD Audio header were connected with jumper wire and my favorite lazy workaround: electrical tape. I found a USB 2.0 motherboard header to female USB A to connect the Arduino for power to the circuit via a USB cable so that it was connected directly to the motherboard. It worked though and I was pretty happy with it. A build vlog for this iteration can be found here, but I must warn you it's a bit long winded. But within the last two months, the NeoPixels had stopped reacting to audio, so I knew something had come loose. I had also become a lot more confident in soldering and decided it was time to give this project a facelift. I also wanted my Arduino Uno R3 back into the rotation.Second Install
The main goal of this second attempt was to solder all of the connections so that everything would be more stable. I also wanted to swap in a smaller board that utilized the Atmega328 chip. I went with a Pro Trinket since it had the 328 chip, 5V power and a small form factor. After testing the existing breadboarded circuit with the Pro Trinket, I began migrating the project to protoboard.
I wanted the circuit board to live in the main part of my PC case this time instead of the basement so I found some black protoboard from DFRobot on Digikey so that it would blend nicely. I used Fritzing to lay everything out and those files are available below. For the HD Audio header, I soldered in male headers to match the pin out so that it could plug-in easily, mimicking the plug found on the motherboard.
This was my first time populating a protoboard that wasn't laid out like a breadboard, but it went pretty well. I laid out all the components and wires before soldering and then used poster tack to hold everything in place.
To connect the NeoPixels, I had some four-wire headers that I soldered to the NeoPixels and onto the board so that I could connect and disconnect the NeoPixels as needed. It also took some strain off of both the board and NeoPixel strand.
It admittedly felt a little weird bridging connections on purpose to connect components together but I tried to keep those sections at a maximum of three holes distance.
When I wired everything up to test, the lights turned on the correct color, but surprise! They weren't reacting to audio. After a bit of troubleshooting I realized that the culprit was the HD Audio connector. For some reason when it was fully plugged into the male headers I'd soldered in it wouldn't work. But, if I angled the header so that the front two pins (MIC and GND) were connected, then it worked. I stuck in two female headers over the male ones on the board to add some height and that allowed the HD Audio header to deliver an audio signal to the circuit. If I had to hazard a guess as to why this happened I think it has something to do with pin 6 on the HD Audio connector, which is a jack detection signal pin. Where the non-MIC and GND headers aren't connected to anything, I think that it may be causing it to short out. I plan to desolder the extra headers for the HD Audio connector. I wish I had tested this before because here is an excellent depiction of what they say about assumptions.
After that little hiccup though I was able to use two stand-offs to mount the circuit board onto the panel on the inside of my PC case. The NeoPixels are now back to their dancing selves.
Overall I'm very happy with the state of this project now. It's definitely a lot more stable in it's current form and more aesthetically pleasing. For next steps, because a project is never truly done, I do plan to desolder those pins that are shorting out the HD Audio connector and perhaps in the future I'll mark this project to be my first PCB adventure. Since I'm so comfortable with the MSGEQ7 circuit at this point I think it would be a good candidate and those OSH Park purple PCBs would match my color scheme perfectly...Other possible iterations
If you dig this project but aren't into obnoxious computers, it could easily be modified to run with a stereo system, a TV or anything like that. Another cool use would be for a band's live show if you got a feed from the mixer board. Basically where ever there is audio output this project could find a happy, flashy home.