Introduction: Musical Neopixels (WS2812B)
I've recently discovered Neopixels. I soldered a couple, connected them to my Arduino and made them do various light patterns. This was already pretty enjoyable to make and watch, but Neopixels have so much more potential!
First of all, they are very small, so you can embed them in a lot of things. They are also pretty easy to control and only take up 1 pin on your Arduino.
Therefore I felt like I had to do something cooler with my Neopixels. I decided to make a sound reactive string of LEDs that I could potentially hang in my room or in the christmas tree.
In this Instructable I will explain how I made my Neopixels respond to music or sounds!
This is what you'll need:
If your LEDs are not pre-soldered you also need 0.10 uF capacitors (marking: 104)
- Electrec microphone
- 10K Resistor
- Some sort of cap to put over your LEDs (can be 3d printed, paper, etc)
I highly recommend pre-soldered WS2812B's since the LEDs are not very easy to solder. Buying the pre-soldered ones will save you a lot of frustration.
Step 1: Soldering the LEDs
We're going to start with soldering wires to our WS2812B LEDs.
If your WS2812B's are not pre-soldered, make sure to solder a 104 capacitor on each LED between the VSS and VDD pin. If your LEDs are pre-soldered you don't have to worry about this, since it probably already has one built in.
The next step is to solder all the wires (see image). All the VSS pins have to be connected. The VDD pins also all need to be connected. Make sure to solder two extra wires on the first LED of your series. One from VSS to GND (Arduino) and one from VDD to 5V (Arduino).
Next you'll need to connect DOUT (data out) from the first LED with DIN (data in) on the second LED. Then you'll connect DOUT from the second LED with DIN on the third LED, etc.
Connect DIN of the first LED with pin 6 on your Arduino.
Test your LEDs to see if everything is working correctly. You can do this for example by using the strandtest sketch of the Adafruit Neopixels library. I didn't test my LEDs while building and ended up finding out at the end that green is broken in the third LED of my string. I'll now have to desolder everything and add a new LED. It saves you a lot of trouble if you test early!
Step 2: Connect the Microphone
Next up is the microphone. Solder wires to your microphone.
Connect the negative leg to GND on your Arduino. Connect the positive leg to a 10k resistor and to pin A0 on your Arduino. Connect the other side of the resistor to 5v on your Arduino (see image).
My microphone came with a plug so as you can see on the picture I connected it via a socket from another protoboard. The rest of my setup is the same as the image though.
Step 3: The Code
Now that everything is soldered, it's time for the code. I found this Trinket project that turns Neopixels (WS2182B) into sound reactive LEDs, but the code also works on Arduino.
We'll need to edit a few things in the code.
I used 4 WS2812B LEDs for this example. If you used more or less than 4, you'll need to change that in the code. On line 6 you'll see the following code: #define N_PIXELS 4 - Change that 4 to the number of LEDs you're using.
Next we'll have to define the noise level on line 9. This is a bit of trial and error. You'll just have to run the code and see if the microphone is too sensitive or not sensitive enough. If the microphone is not sensitive enough you'll need to lower the number on line 9.For example: change #define noiseLevel 2 to #define noiseLevel 1.
If your microphone is too sensitive. You'll want to raise the number. For example: change #define noiseLevel 2 to #define noiseLevel 6.
You also might want to change the fade delay on line 8. If your LEDs are blinking too fast, you'll want to raise the number. For example: change #define fadeDelay 10 to #define fadeDelay 50. If the LEDs are not blinking fast enough, you'll want to lower the number.
Step 4: Test Your Musical LEDs
Now that everything is soldered and the code is set up correctly, it's time to try your LEDs.
Connect the wires to your Arduino, plug it into your PC and upload the code.
Now put on some music and see if the LEDs are changing!
If they're not really changing color or not turning on at all, there is a couple of things you can do. Same goes for when your LEDs are changing too much.
- Change the noise level in the code. See previous step on how to change it. Change it until you're satisfied.
- Try and turn up the volume of your music (or lower the volume if they're changing too much)
- Try to put your microphone closer to your music source (or further away when changing too much)
- Change your 10k resistor to for example 1k or 100k. For my microphone 10k was working best, but your microphone might need an other resistor.
Step 5: Make the LEDs Pretty!
Next are the caps for the LEDs. The LEDs are fun by itself, but they're even more fun with a nice cap. You can use a 3D printer to print a cap, you can fold one with paper, or even build your LEDs into a christmas ball or ornament!
I made my own caps with paper. The folding instructions are attached to this Instructable.
If you unfold one corner (after you folded the whole thing) it gives you just enough space to slide a LED in (see images).
Make a cap for each LED.
Step 6: You're Done!
Now that your caps are done, there's only one thing left to do... Hang them in your christmas tree and watch them dance to your christmas music!
Please let me know what kind of cool stuff you made using this Instructable :)
And Merry Christmas in advance!
artrjc made it!