Introduction: Music Reactive Desk Lamp

Hi! In this instructable we'll be building a good looking light that dances to all sounds and music, using simple components and some basic Arduino programming. It makes an awesome effect while standing on the desk when gaming, playing music, and anything else that makes sound really. Let's get going!

Step 1: Main Supplies

First things first: what kind of supplies do we need and what do they cost? Well, they are largely optional, and can be made with much improvisation. Even so, some key items are needed if you want to follow this guide:

Depending on the look you want, you might want to arrange the strips differently or diffuse the light in another way. This is where you can be creative. If you like my approach, I used the following items:

  • The tallest IKEA Droppar jar (IKEA Link)
  • A small length of PVC pipe.

All things considered I spent around 30$, where the LED strips were by far the most expensive part.

Step 2: Powering the Components

The star of the show is the sound detector module. This will provide an analog signal to the Arduino, which we can use to (hopefully) cleverly light the RGB lights. To be able to do this, we need to power both devices. Luckily they both require a 5 volt input. I am using a step down module to step down from 12 volts to 5 volts, but it would be easier to use a 5 volt power source directly. Wire the VIN on the Arduino and on the sound detector board to the positive input. Then wire the GND on the Arduino and the detector to the negative. Look at the black and the red wires on the attached schematic. We also need to hook the positive and negative input on the LED-strip to the power source.

Step 3: Detector & Strips

After having connected all three parts to the power, we need to connect them to eachother.

The sound detector module will communicate with the Arduino over the analog input pins. I will be using pin number 0, but which one does not matter.

The LED strips need a digital pulse to be able to understand which LED we want to address. Hence we need to connect a digital output pin to the Arduino nano. I will using pin number 6.

Awesome, now we are mostly done with the electronics!

Step 4: Uploading the Code

The most important part of this build will arguably be the code. It can change this build from pretty cool to insanely awesome. You can find the code i used here (github link). The main principle is to map the analog value we get from the sensor, to an amount of LEDs to show.

We can do this using the map function. This will let us display a certain amount of LEDs given an input, but nothing more than that. Doing only this might give you a jittery and flickering light. I decided to operate on the average of the llast X amount of readings to create a more sane and smooth transition. I also did some more advanced tracking of the song/sound intensity based on averages, to let the light change colors when the song enters a peak.

I will answer questions about the code if you have any, it's far from done, and contributions are welcome!

Step 5: Did Anyone Say Stuffing?

With all the code and the components done, it is assembly time. The PVC is obviously hollow, and we will take advantage of that by stuffing the electronics on the inside. We'll cut a slit in the PVC pipe to let us slide the strip out without obstructing the flush surface of the PVC hole. After that, we can glue the LED-strip to the PVC pipe. Some have asked me why I used hot glue, and not only the adhesive on the back of the strip. It's simply because my experience with it is that it will hold fine on really clean and straight surfaces, but on a curvature like this it will most likely let go in a matter of days. Hence: hot glue!

Step 6: The Container Itself

First I thought the lid was made out of acrylic, so I tried to drill a hole in it. Turns out it was made out of glass, and it broke. Clever! So, that's why I'm cutting out a sphere of acrylics with the same diameter as the lid, with a hole equal to the size of the PVC pipe in the middle. It turned out pretty cool, and I love the shine of new acrylic. Before putting on the frosted IKEA jar, we have to glue the stick of LEDs to the lid.

Step 7: Finishing Up!

We can see by the hole, and the placement of the electronic components, we can reach both the Arduino USB interface and the power input from underneath. I took a little shortcut on the legs, and used some potentiometer knobs I had lying around. Ideally you want some nice wood or maybe some turned aluminum?

Step 8: Done!

This was a great project, and I love it especially because it is so customizable and updatable in the future. I encourage you to look at the video in the top for the actual results. If you don't want the instructions, you can skip to the end to see the action.

Thanks for reading through, hope it was worth your time.

Hansi

Comments

author
Alan-brito made it! (author)2017-05-10

Hello, I have a question. I would like to do this but I dont have the "Individually Addressable LED strips"

Can I do that whit an RGB Led Strip?

author
EdwardF2005 made it! (author)EdwardF20052017-07-17

RGB strips with R G B and GND input wouldn't work. In the tech world these are called 'dumb' led strips. the WS281B LEDS that they were using are induvidually addressable and called smart LEDs

author
xilense made it! (author)xilense2017-05-10

hi alan, i think it would not work with RGB Led Strip

author
nacbooth made it! (author)2017-06-02

Great fun to make. I used a different casing, but loved the idea of a spiral wound core for the LED strip which I've put into this this Chinese lamp box which has a great diffused screen. Thanks for the code and ideas.

IMG_20170602_221525.jpg
author
Natural Nerd made it! (author)Natural Nerd2017-06-02

That is fantastic!

author
AaronM255 made it! (author)2017-05-18

Hello I have done what they said for the blinking, the problem is that it does not change my color, you are only in blue. What can I do?
Thank you and sorry for my bad english

author
igordon18 made it! (author)2017-05-03

Hey! A friend and I are building this together and everything seems to be working pretty well, however, the LEDs are not changing color. We have made a few edits to the code in the MIC_LOW and MIC_HIGH areas as suggested in the comments and have adjusted the low and max values, and nothing has worked. Any ideas?

author
JONATHANW177 made it! (author)2017-05-01

I keep on getting the error of error: 'leds' was not declared in this scope

is there any way to fix it, I tired a couple of things but nothing is working

author
marks789 made it! (author)2017-04-12

Hi im a newbe at code, i keep getting errors,like CRGB does not name a type.thats just one of the many error,is there any chance you could send me the finished code plz

author
17berhey made it! (author)2017-04-10

Anyone use an alternative jar? It wont let me order the Ikea jar suggested.

author
RobertB26 made it! (author)2017-04-09

Hi!
How many meters LED did you use?

author
igordon18 made it! (author)2017-04-03

I'm really struggling with building this, the video is a little vague and some things aren't explained and it looks to be like quite a bit of things that are in the video weren't described in the supply list. Where do I start? In desperate need of help, any and all is appreciated!

author
MarcelR23 made it! (author)2017-03-31

Hard work but after giving the led strip (150) an externsl power source all worked ...the nano powers only the sound sensor

VID_66510303_040122_391.mp4
author
gabriele99 made it! (author)2017-03-22

Hello. I have a question. Could I use a smartphone as a power supply?

author
X-Pilot made it! (author)X-Pilot2017-03-31

Most likely no.

1) Led strips draw a lot of power - around 1.8A (120 led, full white). Your battery capacity (depending on your phone) is around 2.5A to 3A. So while the numbers look ok, it will drain your battery fast - not to mention that your phone will get very hot.

2) Now comes the second fun part. The USB on your phone needs to be USB OTG (on the go). To test this, plug in a usb memory stick. If it boots, you're good to go.

3) Current limiting by host - it's most likely a safety feature is added in these blasted devices, so if you exceed 1A power drawn it will cut the power to your strip.

Now if all conditions are met, it's theoretically possible. I managed to power my system with this little guy :)

http://www.mi.com/en/pb10000/

Benchmarked it, lasted around 4 hours until it went out

author
X-Pilot made it! (author)2017-03-11

Hello,

This project was awesome! I've had my go at it and completed most of it. I didn't need a step down converter, I have a 5v power supply. However when I ran your code, I hit a snag, hopefully you can help me out.

I've wired everything together, led strip works in the setup function, however, it does not work with my current audio sensor. Only 3-4 leds blink... I presume this is because of the values I get from the analog read. I tuned it with the screw (potentiometer), got the sensor led to blink as expected. The serial out values are between 670 and 705, which goes up to 900 when I clap next to it.

Can you give me some info on this? It's my first arduino build btw, I've done some raspberries and tried my hand on Arduino.

20170311_222225.jpg20170311_222231.jpg20170311_222234.jpg
author
mizark made it! (author)mizark2017-03-23

Did you ever sort your problem out? I have the same issue and the same module as yours...only the first 3 or 4 lights blink

author
X-Pilot made it! (author)X-Pilot2017-03-31

Yes I did. The problem is, the microphone has quite a poor sampling range. Here are some brief steps how I fix it:

1) Your microphone should have 2 leds on it. One for power the other one for noise. If both leds are on you need to twist the screw on the potentiometer (the blue thing) until one of the leds switches off. Now fine tune it (be in a quiet room and twist the screw while talking until it blinks with your voice) - This will be your sweet spot. In order to do this effectively, please continue reading :)

1a) To see the values coming in from your sensor (as you twist the screw), you need to modify Hansi's code a bit. I've already mentioned this in my previous comments, I'll paste a copy here:

-------------------------------------
To get the values out of your sensor all you need is an extra line of code. To the existing code, locate this part:

void visualize_music() {

int sensor_value, mapped, avg, longavg;

//Actual sensor value

sensor_value = analogRead(ANALOG_READ);

Add this line after the sensor_value:

Serial.println(sensor_value, DEC);

After you've done that, upload the code to the board. Once everything is ok, in your Arduino IDE, go to Tools menu -> Serial Monitor / Serial Plotter. Serial monitor will open a window where you will be able to see the 10bit values from your sensor. Values will be in the range from (0 to 1023). Now depending on your sensor, you may have to adjust it using the potentiometer (yellow screw) using a small flathead screwdriver. Adjust until you get a decent result.

-------------------------------------

1b) For me the values that are decent are between 595 and 630 - this is quite a short interval so don't expect much blink of your lamp. Look at the values or plotted chard (if you use Serial Plotter). Turn on some music and talk around your sensor, you will see the changes.

2) Once you are happy with your values, you need to change the code further more. Please locate this variables in your code:

//The amount of LEDs in the setup
#define NUM_LEDS 150 --- make sure you have the correct number of leds here

//Confirmed microphone low value, and max value
#define MIC_LOW 0.0 --- change this to the lowest value you got from the serial out / plot chart - in my case I set to 595
#define MIC_HIGH 737.0 -- change this to the highest value you got from serial out / plot chart - in my case I set to 630

Now your lamp should behave decent :) I recommend getting a proper mic, like the one Hansi has. In any case, if you have any further questions, don't be a stranger.

Hope this helps.

Cheers,
Radu

author
X-Pilot made it! (author)X-Pilot2017-03-31

Result can be view here:

https://goo.gl/photos/RUbk1qUiwDiniarB6

author
MarcelR23 made it! (author)MarcelR232017-03-11

Same problem with audio sensor

author
X-Pilot made it! (author)X-Pilot2017-03-31

Solution mentioned below. Read for user @mizark > X-Pilot. This should help you

author
X-Pilot made it! (author)X-Pilot2017-03-12

Cheap chinese sensors. I will try a preamp-ed version of the sensor, hopefully i'll have more values from serial. My current range is from 590 to 630. Lots of noise, not really reliable for music.

author
Natural Nerd made it! (author)Natural Nerd2017-03-16

Found the one I used, might be better: https://goo.gl/14q2pB

author
Natural Nerd made it! (author)Natural Nerd2017-03-11

Hello!

I committed a change to the code, so grab the new one. See the new macros that I defined? MIC_LOW and MIC_HIGH. Try to set low to the one you get from the analog read, when it is absolutely silent. High should be the highest value you can get out of it when you scream to it, or put on some really loud music right next to it - or something like that. Get back to me and tell me if that worked :)

author
Dragon940C made it! (author)Dragon940C2017-03-14

How do I measure the analog read? A multimeter on the line? What pins do I measure between?

author
X-Pilot made it! (author)X-Pilot2017-03-15

Hello Dragon 940C,

A multimeter won't work. Since the changes are very rapid, your multimeter will likely fail to get the correct values (since most multimeters have a delay in response to fast voltage changes).

For my initial development I used my DSO 203 pocket oscilloscope - this was purely done to check if the sensor was working without uploading the code. I recommend you get one (yes they are quite expensive, but in the long run you'll be able to debug a lot more electronics components and see binary data being sent as square waves.

Here's a link to my oscilloscope:

http://www.ebay.com/itm/ARM-DSO203-Nano-V2-Quad-Po...

I know it's expensive. Alternatively, you can build one yourself :)

https://www.amazon.com/JYE-DSO-138-Open-Source/dp/...

Now, if you want just to get the values out of your sensor, you don't need all that. All you need is an extra line of code. To the existing code, locate this part:

void visualize_music() {

int sensor_value, mapped, avg, longavg;

//Actual sensor value

sensor_value = analogRead(ANALOG_READ);

Add this line after the sensor_value:

Serial.println(sensor_value, DEC);

After you've done that, upload the code to the board. Once everything is ok, in your Arduino IDE, go to Tools menu -> Serial Monitor / Serial Plotter. Serial monitor will open a window where you will be able to see the 10bit values from your sensor. Values will be in the range from (0 to 1023). Now depending on your sensor, you may have to adjust it using the potentiometer (yellow screw) using a small flathead screwdriver. Adjust until you get a decent result.

Hope this helps :)

author
Dragon940C made it! (author)Dragon940C2017-03-15

@X-Pilot -Thanks for the info it gave me what I needed


@Natural Nerd

-The new code is much better, much more control.




author
X-Pilot made it! (author)X-Pilot2017-03-12

Hello,

Thank you for uploading the code in such a short period of time. I appreciate it. I ran your code and I get better results. Not as cool as the one you got in your video but still, satisfactory for the first build. I believe this is because of the audio sensor. I couldn't find a part number or any data sheet on it :/ It was cheap, in any case, about 3$. I tuned it with the potentiometer to the sweet zone: values between 590 and 630. This seem to work best. The problem is I get little sample rate with this interval. Probably because of the sensor. I am thinking of upgrading to a preamp-ed sensor and see what results I get.

In other troubleshooting and electronic gnomes, I find that the lamp only works when the nano is connected to the USB... When I unplug the usb cable out of the Nano, the lamp freezes. Turning it on / off without a USB connection seems to break it. To describe this bug even further, it seems that Setup code runs ok, then the loop stops... I apologise for the newb question, but I don't know how to solve this. I've looked on google for an answer, but I couldn't find anything relevant. Hope you can help me with that as well.

Thank you.

author
Natural Nerd made it! (author)Natural Nerd2017-03-12

You have powered the USB through VIN and GND with a 5 volt power source, when it is not connected to the USB? Else the Nano is off, and no code is running. Then the led strips usually just hold the state that it had when previously ran.

As for the sensor, that sucks! I couldnt find the one I used it my build, so I linked to another one, too bad it seems to be a really bad one. I had 0-737, not as much as what I hoped for, but it produces a decent result at least.

author
X-Pilot made it! (author)X-Pilot2017-03-13

I have power on the VIN and GND pins on the Nano board. The wiring is common for the strip, audio sensor and Nano board. To be more specific:

Case 1: Nano board gets only external power

1) The system powers up as usual

2) The lamp turns blue in color (setup() function is called correctly)

3) Nothing else happens as if Nano does not enter loop() function

4) If at anytime I plug the USB from the Nano to a computer (I haven't tried an alternative power source) the lamp enters loop() function and works as normal

5) I pull out the USB connection from Nano. Leds freeze, nothing else happens. Led on the mic board still blinks as it still receives data from analog pin. All components are still powered by the external source.

---------------------------

Case 2: Nano board is connected to USB and external power. Led strip GND is disconnected not to overload the Nano board (since PWR and GND are all tied in parallel).

1) As soon as I plug in the led strip to ground, everything works as expected.

2) I pull out the USB connection from Nano. Leds freeze, nothing else happens. Led on the mic board still blinks as it still receives data from analog pin. All components are still powered by the external source.

3) Plug USB back into Nano. Lamp resumes normal operation. If I repeat step 2, same result.

I've attached some images. Of the build and pins.

Wiring:

Red - positive 5V

Black - GND

Green - Connects Nano (D6) to led strip

Blue - Connects microphone AOUT to Nano (A0)

Thank you for your help

20170311_222253.jpg20170311_222225.jpg
author
Natural Nerd made it! (author)Natural Nerd2017-03-13

That sounds really strange to me. Never had that kind of problem before. Please update if you figure out what's wrong

author
X-Pilot made it! (author)X-Pilot2017-03-14

Hello,

I've figured out what is happening with the Nano - never buy cheap chinese hardware. So I dug around and I found that the Nano cannot work with just the pin external power supply. For some reason the loop() does not execute if there's no power supply on the usb bus line. To solve this, I will move the Nano power supply via a mini usb jack. I need just the positive 5V on the USB line, rest seems to work like a charm, even with the ground on the external pin.

I've added two video links below, describing the problem and solution :)

1st video - setup with only external power:

https://goo.gl/photos/jHKDCg17kFWMiqhv6

2nd video - connect an external power source (in this case just your daily USB power transformer - only power no data) to the Nano. Note that the VIN pin is disconnected. Only common ground is present.

https://goo.gl/photos/P3fysPKU1RrUCj9C9

Thank you for your support. This was an awesome build and a lovely thing to debug.

author
X-Pilot made it! (author)X-Pilot2017-03-12

Also, since you are using a stepper down, I presume it includes a capacitor on the output (on the board). I am telling you this because, I've noticed . a voltage drop when the led strip is peaking, not too much, about 0.3 of a volt but enough to cause the resistor value to change on the mic sensor. I am planning to add a 100 uF capacitor, see if I can get more stable voltages.

author
RaymondL56 made it! (author)2017-03-31

Cool lamp idea and thanks for sharing. I was also wondering if there was a way to use the sounds from my p.c. (inline) I almost aways have my headset on as not to disturb my wife.

P.S. Thanks for sharing.

author
bbland18 made it! (author)2017-03-28

Hey! What wires do you use? For the analog pins, can I replace them with just normal wires? Could I use normal wires for the whole project? Also, are there any more items I need to purchase besides the ones listed already? You used many different wires that you did not list.

author
Dragon940C made it! (author)2017-03-16

That's the sound module I used and it worked fine. The potentiameter didn't effect sound too well but I played with his code and changed the two lines to this:

//Confirmed microphone low value, and max value
#define MIC_LOW 200.0
#define MIC_HIGH 700.0

Once I did that I got pretty good results.

author
Jie SuY made it! (author)2017-03-15

Hello Hansi,

It seems like many people who tried this project got stuck at the same problem: the microphone sensor doesn't function as well as it should. I bought 4 of the same kind "KY-038 Microphone sound sensor module", which is the same thing as the one you suggested. I tried with all 4 but came up with same results. No matter how I control the potentiometer, the sensor module produce analogue signal ranging between 560 and 572(when I set the potentiometer at the threshold, and used serial.println to see the analogue value on serial monitor) and the variance does not even exactly correspond with the volume of the sound around the microphone. I'm not saying something is wrong with your project, It is awesome project and I thank you for sharing your work. I just hope you can suggest us other cheap priced options for the good microphone modules. Maybe the one that you used in the video!

Thank you.

Jiesu

author
Natural Nerd made it! (author)Natural Nerd2017-03-16

Ok, found the one I used! Project link updated: https://goo.gl/14q2pB

author
Natural Nerd made it! (author)Natural Nerd2017-03-16

Hello! Yes, I have seen that as well. It seems to be an issue with the microphone. I would have used the one I had, but I couldn't find it anywhere. I will take a second look to see if I can update it.

author
IlirD2 made it! (author)2017-03-14

Hello,

I have a 12v led strip...

Will it work?

Nice project and thanks

author
illera made it! (author)2017-03-07

Hi! Congratulations for this project.

I'm trying to do it connecting directly the arduino to the power module. It's 5v, 1A. Should it work?

I can see that arduino is getting power but led strips aren't reacting.

Should I try with a power adapter with more Amperes?

If Anyone could help I would be very thankful.

author
Dragon940C made it! (author)Dragon940C2017-03-07

With the way he programmed this you will need about 12ma (.012 amps) per LED. So 80 LEDs will need about 1 amp, 160 = 2 amps, etc.
This is the minimum power I would suggest using.

The reason this uses so little amps per LED is because the LEDs are never used to their full brightness.

author
illera made it! (author)illera2017-03-08

thanks Dragon940C! i'll try this way!

author
igordon18 made it! (author)2017-03-02

How many of these LED strips that you linked would you recommend buying to make this?

author
Dragon940C made it! (author)Dragon940C2017-03-06

It takes about 2 1/2 meters... so you can make 2 with a 5 meter strip.

author
JolienJ1 made it! (author)2017-02-28

About 30 LEDs stay permantly on, it doesn't matter if I put my music louder or not, they always stay on. Does anyone know how to solve this? I did try to adjus the pot on the sound module, but this didn't do much. Thanks!

author
JolienJ1 made it! (author)JolienJ12017-02-28

I do have to add that I have a different LED strip, but the LEDs are adressable!

author
Dragon940C made it! (author)Dragon940C2017-02-28


datasiphon wrote a few days ago that the sound module has to be powered off before adjusting pot. I had to power off my module to get it to accept adjustment.

author
JolienJ1 made it! (author)JolienJ12017-03-02

I actually did do that! And it did make a little difference but still 30-40 LEDs were constantly on

author
MarcelR23 made it! (author)MarcelR232017-03-01

the same here ! maybe the range is to short....i use 90 leds .and adjusting the Sound module Switches the starting led ..Need help

About This Instructable

38,041views

660favorites

License:

Bio: We are a couple that loves creative projects, and retro gaming. We will be posting anything that we make related to it, with DIY videos ... More »
More by Natural Nerd:Iron Throne Phone ChargerComic Book LED SignUSB Headphone Stand With RGB LED Lighting
Add instructable to: