Point the sound sensor at your speaker and watch an RGB LED pulse and change colour with every beat.
What you’ll build
The sound sensor’s analog output follows the loudness around it. The Arduino Nano samples it fast, and every peak above the running average triggers a colour hop and a brightness flash on a common-anode RGB LED.
Components you’ll need
| Component | Qty | Price |
|---|---|---|
| Arduino Nano ATmega328P Compatible Board | 1 | ₹149 |
| Sound Sensor | 1 | ₹89 |
| RGB LED CA | 1 | ₹9 |
| 220 Ohm 1/4W | 3 | ₹147 |
| 400 Point Breadboard | 1 | ₹299 |
| Total | ₹693 |
Step-by-step guide
- Wire the sound sensor: VCC to 5V, GND to GND, A0 (analog out) to the Nano’s A0.
- Connect the RGB LED’s common anode to 5V, and R, G, B legs to D9, D10, D11 each through a 220Ω resistor.
- Upload the sketch and play music near the sensor.
- Turn the sensor’s blue trim pot until the LED reacts to beats rather than staying on or off constantly.
The code
A running average tracks the ambient level, so the effect adapts itself to quiet or loud rooms. Note the common-anode LED is driven inverted (255 = off).
const int mic=A0, R=9, G=10, B=11;
float avg=512;
byte hue=0;
void setColor(byte r, byte g, byte b){ analogWrite(R,255-r); analogWrite(G,255-g); analogWrite(B,255-b); }
void setup(){}
void loop(){
int v = analogRead(mic);
avg = avg*0.99 + v*0.01;
if(abs(v-avg) > 60){ // beat!
hue += 40;
byte r = hue<85 ? 255-hue*3 : (hue<170 ? 0 : (hue-170)*3);
byte g = hue<85 ? hue*3 : (hue<170 ? 255-(hue-85)*3 : 0);
byte b = 255 - r - g;
setColor(r,g,b);
delay(60);
} else setColor(8,8,12); // dim idle glow
}Build this project
Add all 5 required components to your cart in one click — total ₹693.
Add all components to cart