loading

Ever seen those cool displays using little rows of LEDs that bounce up and down in time to the music? Or those bars that do the same? Ever wanted to make one? Now you can! I had this idea recently, and realized that I could make it quite easily. It's a simple and fun project, with a cool result.

Featured!! Wow!! Thanks everyone!

Step 1: Parts Needed:

Here's a list of parts that you need. Happily, there's not too many!

You'll need:

  • An Arduino UNO or compatible
  • Breadboard and wires
  • 6 red (Or other color) LEDs
  • 6 220 ohm resitors
  • 2 breadboard audio jacks (Or some other way to connect audio in/out to your arduino)

That's all! Let's get building!

Step 2: Wire It All Up:

Time to build it! You can either follow the Fritzing drawing, or my instructions.

  • Wire your Arduino's power to your breadboard's power strip. (Don't forget ground!)
  • Plug the audio jacks in next to each other, and wire the audio out pins to each other. Wire both ground pins to ground.
  • Connect the Analog pin A0 to the audio out on the jacks.
  • Place the 6 LEDs in a row on the breadboard, connect the ground sides to ground through the 220 ohm resistors.
  • Wire the Arduino's digital pins 8-13 to the 6 LEDs on the breadboard.

You're done!

Step 3: The Code:

Time to program the Arduino! Luckily, the program is a simple as the wiring. Feel free to fiddle around with the code!

There are two different programs, with slightly different code, that achieve different looks. The first one looks less bouncy and flickers/fades the LEDs more. The second is bouncier and doesn't fade the LEDs as much. You can either download them via the .zip files, or copy/past from here.

Here's the code for the first version, AudioVisualDisplay:

 /*
 * AudioVisualDisplay, a program by Jacob Field, written for the arduino 
 * UNO. This program uses 6 LEDs connected to pins 8, 9, 10, 11, 12, 
 * and 13 as a visual volume display for audio. The audio to be displayed 
 * is fed into the Arduino via the analog pin A0. I recommend using a 
 * second audio jack so you can hear the audio being played. ;) Feel free 
 * to use this code, or any part of it, in your own personal projects, 
 * or distribute it freely as you see fit, just give credit where credit 
 * is due.
 */

byte ledValue;
int signalIn;

void setup() {

  //Set all the LED pins as outputs
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  
  signalIn = analogRead(A0); //Read the analog value and store it
  
  ledValue = map(signalIn, 0, 100, 0, 6); //Convert the 10 bit value down to only 7 different values

  switch(ledValue){
    
    case 0:
      //If the value is 0, set all the LEDs low
      digitalWrite(8, LOW);
      digitalWrite(9, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 1:
      //If the value is 1, set the first LED high
      digitalWrite(8, HIGH);
      digitalWrite(9, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 2:
      //If the value is 2, set the first 2 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 3:
      //If the value is 3, set the first 3 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 4:
      //If the value is 4, set the first 4 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 5:
      //If the value is 5, set the first 5 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
      break;
      
      case 6:
      //If the value is 6, set all the LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
  }
  
} 

Here's the code for the second version, AudioVisualDisplayRev2:

/*
 * AudioVisualDisplay, Revision 2, a program by Jacob Field, written for the 
 * arduino UNO. This version uses a different algorithm to analyze the 
 * signal, creating a diffrent look This program uses 6 LEDs connected to pins 
 * 8, 9, 10, 11, 12, and 13 as a visual volume display for audio. The 
 * audio to be displayed is fed into the Arduino via the analog pin A0. 
 * I recommend using a second audio jack so you can hear the audio being 
 * played. ;) Feel free to use this code, or any part of it, in your own 
 * personal projects, or distribute it freely as you see fit, just give 
 * credit where credit is due.
 */

byte ledValue;
int valueHigh;
int signalIn;

void setup() {

  //Set all the LED pins as outputs
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {

  signalIn = analogRead(A0); //Read the analog value and store it

  valueHigh = valueHigh - 5; //Subtract 5 from valueHigh so that it goes down over time

  if(signalIn >= valueHigh){ //If the value coming from the audio jack is higher than the previous value of valueHigh:
    valueHigh = signalIn; //Set valueHigh to thge value coming in from the audio jack
  }
  
  ledValue = map(valueHigh, 0, 100, 0, 6); //Convert the 10 bit value down to only 7 different values

  switch(ledValue){
    
    case 0:
      //If the value is 0, set all the LEDs low
      digitalWrite(8, LOW);
      digitalWrite(9, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 1:
      //If the value is 1, set the first LED high
      digitalWrite(8, HIGH);
      digitalWrite(9, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 2:
      //If the value is 2, set the first 2 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 3:
      //If the value is 3, set the first 3 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 4:
      //If the value is 4, set the first 4 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, LOW);
      digitalWrite(13, LOW);
      break;
      
      case 5:
      //If the value is 5, set the first 5 LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, LOW);
      break;
      
      case 6:
      //If the value is 6, set all the LEDs high
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
      digitalWrite(13, HIGH);
      break;
      
  }
  
}

Step 4: Finished!

You're finished! Now you can test it out!

The code isn't perfect, some improvements could be made, but for now it gets the job done. You can fiddle with some of the values to suite it more to your liking. Hopefully this was a fun little project for you! Feel free to suggest improvements in the comments!

Here's one suggested improvement by lucanletter

"I also changed something that I can highly recommend: I wanted to have both audio-channels (left and right) visualized but I also wanted to have the stereo sound on my jukebox so I added a 1N4148 diode to one pin of the audiojack and tadaa it works just fine."

The diode makes sure that the audio input from one channel doesn't interfere with the audio from the other channel, as seen in the schematic he drew (Last picture).

<p>At first I want to say 'Thank you!' for this Instructable, I will build a big panel, which can be mounted on my wall, that visualizes the Music.</p><p>But I also changed something that I can highly recommend:<br>I wanted to have both audio-channels (left and right) visualized but I also wanted to have the stereo sound on my jukebox so I added a 1N418 diode to one pin of the audiojack and tadaa it works just fine. You can see my version of the sketch in the picture:</p>
<p>I finally completed it - I just love it ^^<br>Thank you again for this simple Code (it gives so many options for changes)!<br>Here some photos of the finished panel and also my final sketch (I had to change one thing again):</p>
<p>Awesomeness! Looks great! (Now people will be asking you where you got it XD)</p>
<p>Nice! Good luck with your panel!<br></p>
<p>Thanks, I just noticed one mistake in my suggestion, the Diode I would recommend <strong>ins't</strong> the 1N418 it's the 1N4148.</p>
<p>I've added your suggestion to the last step, thanks!</p>
<p>Hi, I am new to arduino and on a learning curve.i purchased all the needed parts, loaded the code onto the arduino but it doesn't seem to work.Any advice?. Thanks</p>
<p>Hi! Sorry for only responding now, I don't use my computer on Sundays and Saturdays most of the time. I'd recommend checking all the connections, but you've probably already done that. The likely culprit is the volume of the music. The analog in pins on the arduino read a value from 0 to 1023, but I found that most of the music I was playing only went from 0 to about 100. Depending on your music, you it may be so quiet that the arduino doesn't even register it. </p><p>Here's two things I would try:</p><p>First, make sure your volume on the device that is playing the music is all the way up. Some devices automatically lower the volume when you plug something in. This may be all you need to do to fix the problem.</p><p>If that doesn't work, try this:</p><p>Add a line of code in the &quot;void setup&quot; part of the program that says &quot;Serial.begin(9600);&quot;. (Without quotes.) Then, add a line in the &quot;void loop&quot; part of the program that says &quot;Serial.println(signalIn);&quot;. (Again, without quotes.). Upload the code to your arduino, keep the arduinp plugged into the computer via usb, plug the audio cable it in to your device and the arduino, and play the music. Open the arduino serial monitor (Click the little button in the upper right corner of the window that looks like a magnifying glass looking at a row of dots). The arduino should start sending lines of numbers. Watch these numbers. If it's always 0, then check the audio connections again. Watch to see how high the numbers go in general. You don't want to choose the very highest number, because then your LEDs will never light up all the way. (IE, if the numbers are ranging from 0 to 150 max, but it usually only goes to around 130, then use 130, not 150.) Copy that number down to somewhere.</p><p>In the code, find the line that says &quot;ledValue = map(signalIn, 0, 100, 0, 6);&quot;. Change the 100 to whatever the number you copied down was.</p><p>Upload the code to the arduino again, and see if it works. You can remove the &quot;Serial.begin(9600);&quot; and &quot;Serial.println(signalIn);&quot; lines, since you don't need them anymore. </p>
<p>I wonder if I can implement this into my 4x4x4 LED cube...</p><p>Why are there 2 3.5mm jacks - is it so you can attach a pair of headphone while its plugged in?</p><p>For 10bit, thats 0 to 1023 so shouldn't it be: ledValue = map(signalIn, 0, 1023, 0, 6); or have you put 100 in there as the outputs don't reach higher than 100?</p><p>I want to be able to find a way of finding the 'volumes' of certain frequencies so then I could have this visual music display for a low range of frequencies, one for slightly higher, on for higher and one for the highest frequencies. Does this seem even remotely possible...?</p>
<p>That sounds like a great idea! I think thew way to look at it would be more as a visual display, rather than a data display. In other words, the difference between something to inform and something to please the eye.</p><p>The second audio jack so I can listen to the music. ;) I actually usually plug in a portable speaker.</p><p>The value 100 where the 1023 should be is because most songs I found didn't go much higher than that, it often varies, but that seemed to be a good value for most songs. If your music is really loud, you may want to raise it.</p><p>Finding the volumes for different frequencies? Hmm... Like separating the frequencies out individually and finding each frequency's individual volume? Hmm... That's a very interesting idea! All I can tell you is that it helped me to use the serial port to find the volume, but it seems like you'd need some code to detect certain ranges of frequency. That's intreguing, keep me updated (Or better yet, write an instructable!) about it! I might even fiddle around with it myself later.</p>
<p>Hi there!</p><p>Look for a part called MSEQ7</p><p>(</p><p><a href="https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf" rel="nofollow">https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf</a></p><p>)</p><p>It will do the Job for seven frequency bands. No really big deal.</p>
<p>Hmm, thanks! Although, it kinda takes the challenge out of having to program it entirely yourself using arduino... ;)</p>
You just need to decide which plane would be the base (not bass clef).
<p>Do you mean the base of the LED cube?</p>
Sort of. when you visualize a sprectrum analyzer, the bars have to start somewhere. I think it might be interesting to have it run on any axis: x, y, or z. there are 6 possible start points.
Love it - voted!
<p>Thanks! :D</p>
<p>This gives me a great idea. You could use an Arduino to make a music activated lock system. You could just program it to remember a sequence from a certain song and use that to activate a program. </p>
<p>Hmm! Interesting idea! Tell me if you make it!</p>

About This Instructable

5,293views

105favorites

License:

Bio: I am a electronic maniac. I take things apart to see how they work or what I could use out of them, and I love ... More »
More by Jfieldcap:Restoring a Vintage Calculator LEDs for the clueless beginnner  Repair a Blown CPDM (Core Power Distribution Module) 
Add instructable to: