VU Meter

51,777

51

22

Posted in TechnologySensors

Introduction: VU Meter



This project shows you how to take inputs from a computer, MP3 player, or stereo via a headphone jack and get LEDs to respond and visually display the peaks and troughs of the music.

For this project you will need:
-One (1) ArduinoMega w/ USB upload cable
-Two (2) 10-Segment LED Bar Graphs
-One (1) breadboard
-A few feet of 22 gauge solid wire
-One (1) 3.5mm Male to Spade-Tongue Speaker Cable


Attached is a video of the finished project.

Step 1: Setting Up the Breadboard

For this step you will need:
-Two (2) 10-Segment LED Bar Graphs
-One (1) breadboard
-A few feet of 22 gauge solid wire

NOTE: For this project we used two 10-Segment LED Bar Graphs for a total of twenty individual LEDs. However, using just regular LEDs, either less or more, will work perfectly fine. The Bar Graphs create a cleaner look. Though we do recommend using at least five LEDs for the desiref effect to be achieved.

With the breadboard positioned vertically, insert the LED bar graphs vertically with each line of pins straddling the void traveling vertically up the breadboard so that the positive and negative pins of the bar graphs are on opposite sides of this void.  

Next, since wires are connected horizontally in breadboards, insert twenty (20) jumper wires into the plugs of the breadboard that are  horizontal to where the negative (for the bar graphs there is no predesignated positive or negative side, you get to choose) pins of the bar graphs plug into the breadboard. Then take each of those jumper wires and connect them to the negative bus of the breadboard on that same side.

Now, insert twenty (20) jumper wires into the plug of the breadboard just like you did in the previous step except this time insert them on the positive side of the bar graphs. DO NOT connect these jumper wires to the positive bus of the breadboard.


Step 2: Connecting to the Arduino Mega

For this step you will need:
-One (1) Arduino Mega
-One (1) longish jumper wire

Take each of those positive jumper wires and insert the free ends into the pins numbered from 34 to 53. IMPORTANT: Insert the bottom-most jumper wire into pin 34 on the Arduino, then the jumper wire DIRECTLY above that into pin 35, the pin DIRECTLY above that one into pin 36, and so on and so forth until you put the last jumper wire into pin 53. The reason for being so meticulous in inserting the jumper wires into the Arduino is because if the LEDs in the bar graphs are not connected to the )Arduino sequentially they either not light up in the correct order (if you use our code) or (if you program this yourself) it will make coding for this project more frustrating.

Next, insert the longish jumper wire into THE SAME negative bus on the breadboard as that you plugged the negative jumper wires from the bar graphs into. Then take the free end of this jumper wire and plug it into one of the two (does not matter which) ground (GND) plugs on the Arduino.

Step 3: Setting Up the Arduino to Take Inputs

For this step you will need:
-One (1) 3.5mm Male to Spade-Tongue Speaker Cable

NOTE: You can use any cable that will fit into a 3.5mm headphone jack. The reason for us using the specific cable we did was purely cost based. Using another cable will not affect the functionality of this project.

First, cut off the both of the spade-tongues on the speaker cable. Next, separate the two wires from each other and strip of approximately 1/3 of an inch of the insulation.

NOTE: Since the speaker cable is not made out of solid wire we suggest that you spin the threaded wire together so that it is easier to stick into the plugs on the Arduino which you will do next.

Now take one of the exposed ends of the speaker cable (does not matter which one) and insert it into the other ground plug on the Arduino. Then take the other exposed end of the speaker cable and insert it into ANALOG plug 8 on the Arduino.

NOTE: If you are using our code (attached in the next step) for this project you must use Analog plug 8 on the Arduino because it corresponds to our code. If you are writing your own code for this project feel free to use any plug AS LONG AS it is still an Analog plug.
,

Step 4: Upload Code to Arduino

If you have never used or programmed an Arduino, the required software can be found at:
http://www.arduino.cc/en/Main/Software
This website is also a great resource for learning how to write and troubleshoot your code.

Connect your Arduino to your computer with the USB cable. Upload the code to the Arduino.

Leaving the USB cable plugged into BOTH your computer and the Arduino (your computer acts as the power supply for this project) plug the Speaker Cable into your computer or whatever device you are using to play music with and turn on some sort of music.

Open the serial monitor from the Arduino window on your computer and you should see values displayed. If for some reason you are getting zeros, or very low values try changing to a different song with a heavier beat and if that does not change the values you are seeing check all of your connections.

Share

    Recommendations

    • Woodworking Contest

      Woodworking Contest
    • Make it Move Contest

      Make it Move Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    22 Comments

    I referred to your instructable to make my VU Meter. I used the following code on an Arduino Uno (i do not own the code, was taken off the internet). The only problem i am facing is that when i plug in my jack into my computer I only get the output on my VU Meter, but i want the sound as well. Is there any solution to this?

    And i also wanted to know what kind of mic will i need to get an analog signal? (except electret)

    CODE:

    // Led VU Meter Example

    // Version 1.0

    // Written by James Newbould

    int led[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; // Assign the pins for the leds

    int leftChannel = 0; // left channel input

    int left, i;

    void setup()

    {

    for (i = 0; i < 10; i++) // Tell the arduino that the leds are digital outputs

    pinMode(led[i], OUTPUT);

    // Serial.begin(9600); // Uncomment to enable troubleshooting over serial.

    }

    void loop()

    {

    left = analogRead(leftChannel); // read the left channel

    // Serial.println(left); // uncomment to check the raw input.

    left = left / 50; // adjusts the sensitivity

    // Serial.println(left); // uncomment to check the modified input.

    // left = 1500; // uncomment to test all leds light.

    // left = 0; // uncomment to check the leds are not lit when the input is 0.

    if (left == 0) // if the volume is 0 then turn off all leds

    {

    for(i = 0; i < 10; i++)

    {

    digitalWrite(led[i], LOW);

    }

    }

    else

    {

    for (i = 0; i < left; i++) // turn on the leds up to the volume level

    {

    digitalWrite(led[i], HIGH);

    }

    for(i = i; i < 10; i++) // turn off the leds above the voltage level

    {

    digitalWrite(led[i], LOW);

    }

    }

    }

    Could this be done with out having it plugged into a computer? Could it be independently powered, Like through the uno's power port, and still work?

    Thanx for the post
    I am new to arduino e really useful for me

    Regards
    www.mzubair.com

    Your code is ok, but way to long.

    int sound[4];
    int soundav;
    const int inputPIN =8; //audio input pin, you have to amplify your output to max 5V
    const int firstLED= 34; //first output pin for the leds
    const int lastLED = 53; //last output pin for the leds
    int leds;
    int x;
    int y;

    void setup ()
    {
    pinMode (inputPIN, INPUT); // put input pin in input state
    for (int a=firstLED; a <=lastLED; a++){ // loop through all the outputpins and put them in output state
    pinMode(a, OUTPUT);
    }
    leds = (firstLED + lastLED) +1; //count how many leds you have connected + add 1 for all leds off
    }

    void loop ()
    {
    for (int num=0; num < 4; num++) {
    sound[num]= analogRead (inputPIN);
    if(num==3) {
    soundav=(sound[0]+sound[1]+sound[2]+sound[3])/4; // average sound levels
    x = map(soundav, 1, 255, 0,leds); // map the sound values from 0 to 20 because we have 21 levels. OFF & 20 leds.
    y = firstLED + x; //get the correct led pin number where the led state changes
    for (int b= firstLED; b < y; b++) { //loops through all the leds from firstLED to the level of the sound
    digitalWrite(b,HIGH);
    }
    for (int c = y; c <= lastLED ; c++) { //loops through all the leds from lastLED to the level of the sound
    digitalWrite(c,LOW);
    }
    }
    }
    }

    This should do the trick in about 35 lines of code.

    You can use this example for a normal arduino. You only have to change the inputPIN, firstLED and lastLED. And you have to connect all your LED in sequence.

    7 replies

    Oh sweet Jebus! I was going nuts 'til I used your code. Thanks!

    No problem, I'm glad it worked, because I never tried or used it.

    Hi Cinez, great code but it's wrong in a few places and thus doesn't work as it is.
    Since it's otherwise really good and elegant, I prefer to post just the tiny corrections so you can update it and keep the credit :)

    leds = (firstLED + lastLED) +1; // wrong
    leds = (lastLED - firstLED) +2; // right
    You did a sum on the LEDs inputs, when it should be substracted. And you should add "2" instead of "1", or you'll be missing the last LED, since 54-35 = 19 and not 20. We should add 1 for that LED and another 1 for the ALL OFF as you already pointed out.

    You should also change "PrintSerial" to "Print.serial".

    And then it'll be working.

    Best wishes

    I tried your code but it dosn't work, when i play music the LEDS are always on and when i don't play music the LEDS are still always on

    HELP ME!!!

    There is probably something wrong with your input: Try to write a sketch that outputs the soundlevels to the serial console. Use Serial print to debug your sketch. you can see the values in the

    int sound[4];
    int soundav;
    const int inputPIN = 8; //audio input pin, you have to amplify your output to max 5V
    const int firstLED= 34; //first output pin for the leds
    const int lastLED = 53; //last output pin for the leds
    int leds;
    int x;
    int y;

    void setup () {
         pinMode (inputPIN, INPUT); // put input pin in input state
         leds = (firstLED + lastLED) +1;
         Serial.begin(9600);
    }

    void loop () {
         SerialPrint("soundlevels:");
         for (int num=0; num < 4; num++) {
             sound[num]= analogRead (inputPIN);
             SerialPrint(sound[num]);
             SerialPrint(" ")
             if(num==3) {
                  soundav=(sound[0]+sound[1]+sound[2]+sound[3])/4;
                  SerialPrint(" Average soundlevel: ");
                  SerialPrint(soundav); // Print average sound levels in console
                  x = map(soundav, 1, 255, 0,leds);
                  SerialPrint(" Mapped soundlevels: ")
                  SerialPrintln(x); delay(1000); // add delay to prevent to much data been send over Serial connection
             }
         }
    }

    I did not test the code. But you should get different value outputs when making noise. If not check your circuit if everything is connected the way it should.

    Ask wunderschonen how he did it.

    thank you i got it to work now, it turned out to be my input plug, also can you tell me how to adjust the sensitivity because my ipod has to be on full volume for it to work and then the headphones might as well be used as desk speakers not headphones. thanks

    You can very easily adjust the sensitivity of the input.
    Change the 255 on this line to a lower number.
    x = map(soundav, 1, 255, 0,leds);

    If you want to change the sensitivity on the fly with a trimpot.
    Use this http://arduino.cc/en/Tutorial/AnalogInput
    To change the 255 value on x = map(soundav, 1, 255, 0,leds);.

    sensorValue = analogRead(sensorPin);
    x = map(soundav, 1, sensorValue, 0,leds);

    how can i add a sound shield so i can have one line in and then have the leds flash and have it output sound to a stereo?

    Volume is a logarithmic function of amplitude - how does this code sort that out ?

    Great project! take a look my similar project

    http://candelectronica.blogspot.com/2011/12/led-vu-meter-en-un-hcs08-freescale.html

    hey ,

    thanks for the instructable

    i can't seem to find the code you speak of, is it online? where can i find it..
    perhaps it is in front of my nose..but where..scratches head.

    thanks

    stephen

    4 replies

    ~its on the last page

    Thanks a mil

    I have got the vu meter up and running thanks!!!!.. just one question

    when i used a normal mp3 the response is great ..but when i use a microphone that is feeding just ambience streets sounds into the system i get very little response.. the mic works fine i wonder how i can calibrate the vu meter to respond to that kind of sound input? any ideas?

    even if i record a short street ambinance mp3 and then play it into the system...turn it up full i still get practically no response??

    much appreciated!

    kind regards

    stephen

    You would need a small amplifyer circuit for the microphone, such as this one https://www.instructables.com/id/Altoids-Amp/

    Basicly you are using the circuitry from the tape player to amplify the microphone, if you need any help email/inbox me, id be glad to help :)

    I keep getting a .tmp file. Is there another way to download this code other than right-clicking? Sorry, total noob here.

    what is the operating voltage i should use for the LEDs?