ARDUINO – LED VU-METER

In questo tutorial vi mostrerò come creare un Vu-Meter con arduino.

Elementi necessari:
– Arduino
– 10 LED
– 10 Resistenze da 470 Ω
– Un cavo jack audio come questo

VU meter leds

Come vedete dall’immagine i led sono collegati con il catodo (negativo) a massa e l’anodo (positivo) alla resistenza che a sua volta è collegata ad una delle uscite digitali di arduino.
Il cavo audio è dotato di 3 conduttori, uno va collegato a massa, mentre gli altri 2 ai rispettivi ingressi analogici in questo caso A0 e A1.
Codice: 
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++)
  pinMode(led[i], OUTPUT);
}

void loop()
{

left = analogRead(leftChannel);  // read the left channel
left = left / 50;    // adjusts the sensitivity  

// 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);
     }
  }
}

 

Video: