In our old guide we made VU Meter using microphone and LEDs, also our Arduino door bell project have kind of VU meter with 3 LEDs. Now, our one reader asked how to create good looking but easy Music Analyzer or VU Meter using Audio input from devices like microphone out or smartphone’s USB out. Here is Arduino Simple Music Analyzer VU Meter From Stereo Input Project. It is nothing but reproduction of an old German blog :
1 | http://playingwitharduino.blogspot.in/2011/12/vumetro-leds-al-ritmo-de-la-musica.html |
Basic reason to “copy” it is nothing but :
- That is easiest
- That blog post has demonstration video
- The particular code has way to debug on serial monitor
- Original is not in English
- We will probably improve it in future and need a reference English text guide
The blog does not seem to be active after 2012.
---
Arduino Simple Music Analyzer VU Meter From Stereo Input
We tested it and it is not exactly just bad. Wiring is very easy. Each negative pole of 8 LEDs will go to GND of Arduino. Each positive pole of LED will have a resistor (value can be 220 Ohm, 470 Ohm, 1 K Ohm depending on LED and board’s current). Stereo input will have only one pole going to Analog pin of Arduino. The other one will connect to GND of Arduino. You can use various colors of LEDs and the thing will look like this :
This is the code, which actually nice logic with an arbitrary value from analog pin as viewed from serial monitor of Arduino IDE :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | //www.playingwitharduino.blogspot.com int LED1 = 3; int LED2 = 4; int LED3 = 5; int LED4 = 6; int LED5 = 7; int LED6 = 8; int LED7 = 9; int LED8 = 10; int Valor; int Valor1; int Valor2; int Valor3; int Valor4; void setup (){ Serial.begin(9600); pinMode(LED1,OUTPUT); pinMode(LED2,OUTPUT); pinMode(LED3,OUTPUT); pinMode(LED4,OUTPUT); pinMode(LED5,OUTPUT); pinMode(LED6,OUTPUT); pinMode(LED7,OUTPUT); pinMode(LED8,OUTPUT); } void loop (){ //Leemos el valor Valor = analogRead(A0); //Transferimos los valores para saber cual era el estado anterior Valor4 = Valor3; Valor3 = Valor2; Valor2 = Valor1; Valor1 = Valor; //Visualizamos los valores en Serial Monitor Serial.print("Value: "); Serial.print(Valor); Serial.print("\t Value1: "); Serial.print(Valor1); Serial.print("\t Value2: "); Serial.print(Valor2); Serial.print("\t Value3: "); Serial.print(Valor3); Serial.print("\t Value4: "); Serial.println(Valor4); if (Valor1+Valor2+Valor3+Valor4==0){ digitalWrite(LED1,LOW); digitalWrite(LED2,LOW); digitalWrite(LED3,LOW); digitalWrite(LED4,LOW); digitalWrite(LED5,LOW); digitalWrite(LED6,LOW); digitalWrite(LED7,LOW); digitalWrite(LED8,LOW); } else{ if (Valor>0){ digitalWrite(LED1, HIGH); } else{ digitalWrite(LED1, LOW); } if (Valor>50){ digitalWrite(LED2, HIGH); } else{ digitalWrite(LED2, LOW); } if (Valor>100){ digitalWrite(LED3, HIGH); } else{ digitalWrite(LED3, LOW); } if (Valor>150){ digitalWrite(LED4, HIGH); } else{ digitalWrite(LED4, LOW); } if (Valor>200){ digitalWrite(LED5, HIGH); } else{ digitalWrite(LED5, LOW); } if (Valor>250){ digitalWrite(LED6, HIGH); } else{ digitalWrite(LED6, LOW); } if (Valor>300){ digitalWrite(LED7, HIGH); } else{ digitalWrite(LED7, LOW); } if (Valor>350){ digitalWrite(LED8, HIGH); } else{ digitalWrite(LED8, LOW); } } } |
We can, actually do similar with 10 LEDs in same kind of wiring with different way of code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | int led[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int input, i; void setup() { for (i = 0; i < 11; i++) pinMode(led[i], OUTPUT); } void loop() { input = analogRead(A0); input = input / 12; if (input < 12) { if (input == 0) { for (i = 0; i < 11; i++) { digitalWrite(led[i], LOW); } } else { for (i = 0; i < input; i++) { digitalWrite(led[i], HIGH); delay(4); } for (i = i; i < 11; i++) { digitalWrite(led[i], LOW); } } } } |
Conclusion on Arduino Simple Music Analyzer aka VU Meter
We can use anything analog input as logic to visually or audibly represent it with Arduino and code. As number of LEDs are lower in number in these projects, we need not to think about how to increase the number of pins of Arduino board. That is exactly where we need to know about charplexing, multiplexing etc.
Charplexing, multiplexing like for 8×8 dot matrix displays will need more code and that code will become library.
Tagged With vumetro arduino