Introduction: Arduino PWM Music LED Light

Picture of Arduino PWM Music LED Light

On my 2 week vacation between summer classes and school of my 5th year I decided to have some fun with my 1W led's that i've never used even though I've had them forever.  
This was used to deck out my house so we had something different than generic black lights or no light.... in case we ever have a party

So here goes with my project I hope you like it (Out of sight project so it isn't too pretty but your not supposed to see it)
Materials:
Arduino (30$)
Adafruit 9V battery pack (4$)
http://adafruit.com/products/67
1W led's with star heatsinks (10$?)
2 poor mans buck drivers (https://www.instructables.com/id/Poormans-Buck/ 30$)
1 Laptop charger (3$)
Electrical Tape
Wire
4 Banana plugs (1.50$)
Stereo Y adaptor (can use mono but you cant get left right audio changing) (7$)
2 Sided tape
Switch
10K resistor.
Glue
Basic prototyping and building tools

Step 1: Proof of Concept

Picture of Proof of Concept

Had to start here by proving to myself that I could use the headphone jack on the arduino to do an analog read and see the serial output for the values



int Musicread=0;

void setup()
{
Serial.begin(9600);
}
void loop()
{
Musicvals = analogRead(Musicread);
Serial.println(Musicvals);
delay(10);
}

That's the code just the analog serial reading, so It did work 

Next was to use the analog values and put it into PWM pins to adjust brightness according to music values, different from making them blink on and off but they change brightness instead!


int Music = 0;
int Musicpin = 0;
int PWMpin=9;

void setup()
{
}
void loop()
{
  Music=analogRead(Musicpin);
  Music=map(Music, 0, 123, 0, 255);
analogWrite(PWMpin, Music);
 delay(5);


I think the mapping part is wrong though I couldn't get a very readable value for the analog and couldnt figure out how to export the values as a CSV file or to plot them :\ .
Play around with the values, find a setting you like for the mapping.

Step 2: LED Driver With PWM Input / Power

Picture of LED Driver With PWM Input / Power

To get the fade effect the driver needs PWM input I used the
https://www.instructables.com/id/Poormans-Buck/
Easy to build and use, got 2 of them for 30$ and they have a wide operating range.

I used them along with my computer charger to power the LED's

The switch turns the arduino board on and off.
I need to add another switch to turn the entire system on or off but for now pluging in and unpluging works


I used 2 of the drivers because the power was choosing the path of least resistance and the Red led's required 2.7v while the blue required 3.7 so only the reds would turn on for some reason, it happens gave me 2 PWM inputs that way so it worked out amazingly

Step 3: Setting Up the Lighting Fixture

Picture of Setting Up the Lighting Fixture

I'm not sure what to call the light rail I used put 15 LED's in it (I only had 15 star bases (^_^) )

8 blue and 7 red's 

each running around 350mA 
Unfortunatly not all the LED's turned on at the same brightness :( it was too late to fix it but it still woked well


Its pretty messy because its not meant to be seen and this was a spur of the moment Idea. If i could do it again I would make it less messy 

Tell you the truth looking at it now and doing some calculations on the power supply I think it might pull too much power, but I tested it by turning it on and feeling the power supply It didnt seem to get too hot, more life testing was done to see If I need another.
  It didn't seem to need one after a few hours of testing.

All the LED's were glued down.  
On the test nothing got hot

Step 4: Final Assembly/Arduino Incorporation

Picture of Final Assembly/Arduino Incorporation

Hook the LED's up to the power supply and turn them on to see if they work, if they do congratulations you didn't mess up!
I messed up several times

once it works get the arduino code working with PWM and analog reading to adjust the brightness of the LED's depending on the volume, you could also make it go with different colors or brightnesses with Left and Right audio.  Depends on how you want to hook it up.  Now that i'm thinking about it I might return my Y adaptor and just hook the PWM up to the speakers.  Though the voltages may be too high for the board to handle i'll have to try it

Also be sure to adjust the current on each driver to the correct amount around 350mA for each.
Adjust from there so one color doesnt drown out the other

Here's my code
Best part is it is easy to adjust and change.  You can add a left and right analog read if you have a stereo audio cable adjust the brightnesses and so forth.

int Music = 0;
int Musicpin = 0;
int REDpin=9;
int BLUEpin=10;
void setup()
{
}
void loop()
{
  Music=analogRead(Musicpin);
  Music=map(Music, 0, 150, 0, 255);

  if (Music == 0)
  {
    analogWrite(REDpin,0);
       analogWrite(BLUEpin,0);
       delay(25);
  }
   if (Music >= 51)
     if (Music <= 105)
     {
  {
    analogWrite(REDpin,Music);
     analogWrite(BLUEpin,0);
     delay(5);
  }
     }
     if (Music <= 50)
      if (Music >= 1)
      {
     {
      analogWrite(BLUEpin,Music);
      analogWrite(REDpin,0);
      delay(5);
     }
      }
        if (Music >= 106)
  {
    analogWrite(REDpin,255);
       analogWrite(BLUEpin,255);
       delay(5);
  }
}


Power switch to come at a later date when I have money for a protoshield

Step 5: After Thoughts

Tell you the truth looking at it now and doing some calculations on the power supply I think it might pull too much power, but I tested it by turning it on and feeling the power supply It didnt seem to get too hot, I'm going to test it more on life test to see If I need another thats an easy fix.

If i could do it again i'd make it prettier and more elegant with the power supply and the driversI probabbly still could by making some

I'd also make the arduino connections on a prototyping shield so It could be more secure than what I have but i'm happy with the results I mean its not supposed to be moved or seen that often, It also does what I want it to, plus it'll only be in operation until December 2012 then i'll remake it.
Hope you liked it
Leave me some comments or Ideas for improvements

What a way to spend a vacation 
Here's a video of it with some techno music.
iPhone camera couldn't keep up

Thanks for reading.

Comments

Istarian (author)2015-10-09

For anyone trying to build this or a similar device using an arduino, the following webpages may be helpful:

https://tushev.org/articles/arduino/9/measuring-frequency-with-arduino
https://www.arduino.cc/en/Reference/PulseIn

ralf_k (author)2015-04-09

any ideas on how to map only for peak amplitude? depending on volume, peak amplitude corresponds to musicpin=50 (low volume) or musicpin=100 (high volume). If I map so that music >45 enables LEDs, then they are on most of the time at full volume, which is not ideal but look great at low volume. Alternatively, if they are enabled when music > 90, it looks great at full volume, but they are never enabled at low volume. Any ideas?

mysterion (author)ralf_k2015-04-09

combine the two examples you have and use a goto label to map for the high frequencies and low frequencies, what do you have right now I may be able to help a bit with more information on what you are trying to acomplish

amandaghassaei (author)2012-08-28

looks great! I like the way you used the different colors for different amplitudes. have you ever experimented with mapping color to frequency?

mysterion (author)amandaghassaei2012-08-28

No, I haven't experimented with the color to frequency. I actually never even thought of it!
Good idea though i'll have to do some more research to try to figure out if its possible.

amandaghassaei (author)mysterion2012-08-28

this looks like a good place to start:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1275615544

jthunder2 (author)amandaghassaei2013-11-30

One of the best led products I've seen. Another guy made something that fit behind a tv and would essentially enhance what you were watching my casting light coordinating with what was on screen on to the wall. It was pretty epic, but I think he stopped making them.

mysterion (author)amandaghassaei2012-08-28

Thanks, somehow I didnt find that forum.
And thanks for reading!

edgypyro (author)2013-03-25

you should draw up some diagrams

jthunder2 (author)edgypyro2013-11-30

I second this.

iamdarkyoshi (author)2013-06-17

i found a simpler method (dont work as good, but harder to blow up and costs about 10 cents, just use an npn transistor, 2 AA batteries, and led, and put the audio right into the (RESISTOR PROTECTED!!!) transistor. if the audio does do too high, the transistor could care less, as the output voltage is clipped at 3v. if this is done, the transistor will keep the arduino (or just a direct led) safe.

zyh12398 (author)2013-04-02

Nice

About This Instructable

29,067views

74favorites

License:

Bio: When the world drives you crazy, go to instructables.com and learn something new instead
More by mysterion:3W led screw-in light bulbStep By Step hack a trickle solar chargerHack a trickle solar vehicle charger
Add instructable to: