Hi guys, In this tutorial we will make music reactive LED visualizer with Arduino. Series of light On/Off according to music. So, lets get started.

For making this project you will need,

Connect circuit like this. We are taking sound from sound sensor and giving output to LED light based on sound intensity.

##### Sketch for sound activated music equalizer:
```int soundPin = A0;
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;
int LED8 = 9;

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()
{
long sum = 0;
for(int i=0; i<100; i++) // taking 100 sample of sound
{
}

sum = sum/100; // average the sample of sound

if (sum>=100) digitalWrite(LED1, HIGH); else digitalWrite(LED1, LOW);
if (sum>=200) digitalWrite(LED2, HIGH); else digitalWrite(LED2, LOW);
if (sum>=300) digitalWrite(LED3, HIGH); else digitalWrite(LED3, LOW);
if (sum>=350) digitalWrite(LED4, HIGH); else digitalWrite(LED4, LOW);
if (sum>=400) digitalWrite(LED5, HIGH); else digitalWrite(LED5, LOW);
if (sum>=450) digitalWrite(LED6, HIGH); else digitalWrite(LED6, LOW);
if (sum>=500) digitalWrite(LED7, HIGH); else digitalWrite(LED7, LOW);
if (sum>=550) digitalWrite(LED8, HIGH); else digitalWrite(LED8, LOW);
delay(10);
Serial.println(sum);
}```

Upload the code. Open serial monitor to note the sensor values. We want to know minimum and maximum output values which is given by sound sensor. Play music to know maximum value and no music for minimum value. This value should be in between 0 to 1023. We will add that values in coding. So that whenever music play at highest beat or sound it will turn on all LED light, when there is no sound it will turn off all the LED light. It will gradually ON or OFF depends on music. So we have created our own sound activated disco music visualizer LED with Arduino.

##### Explanation:

Lets come to the programming part.

Defined sound pin and LED.

```int soundPin = A0;
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;
int LED8 = 9;```

Set pinmode for LED light i.e Output

```pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
pinMode(LED6, OUTPUT);
pinMode(LED7, OUTPUT);
pinMode(LED8, OUTPUT);```

Now we are taking 100 sample of sound, you can take any number of sample.

```long sum = 0;
for(int i=0; i<100; i++) // taking 100 sample of sound
{
}```

we will average this sample,

`sum = sum/100; // average the sample of sound`

finally we can set which output of sound will turn which light, you can play with this values until you get perfect result.

```if (sum>=100) digitalWrite(LED1, HIGH); else digitalWrite(LED1, LOW);
if (sum>=200) digitalWrite(LED2, HIGH); else digitalWrite(LED2, LOW);
if (sum>=300) digitalWrite(LED3, HIGH); else digitalWrite(LED3, LOW);
if (sum>=350) digitalWrite(LED4, HIGH); else digitalWrite(LED4, LOW);
if (sum>=400) digitalWrite(LED5, HIGH); else digitalWrite(LED5, LOW);
if (sum>=450) digitalWrite(LED6, HIGH); else digitalWrite(LED6, LOW);
if (sum>=500) digitalWrite(LED7, HIGH); else digitalWrite(LED7, LOW);
if (sum>=550) digitalWrite(LED8, HIGH); else digitalWrite(LED8, LOW);```

you can watch on serial monitor, what sound values you are getting it will be from 0 to 1023. You can adjust above code accordingly.

`Serial.println(sum);`