Using a sound sensor and an Arduino Uno to control a WS2812B RGB LED strip.
In order to be able to control the LEDs, the FastLED must be installed on the Arduino IDE.
In this project, you will be connecting a sound sensor to an Arduino Uno, and making the LED strip light up to sound. This sound sensor can be placed next to a speaker to make the lights react to the speaker's bass. In this tutorial you will solder jumper wires to the light strip, connect the LED strip and sound sensor to the Arduino, and get the code requried to make the setup functional.
All of these items can be found on Amazon.
Arduino Uno,
WS2812B LED Strip,
Sound Sensor,
Breadboad,
Soldering Iron,
Helping Hand,
Jumper Wires M/M,
Shrink Tube 14mm wide (optional)
Before soldering the wire
The arrows on the LED Strip indicate the data flow, data flows from the Arduino to the LED strip. Make sure that the arrow are facing away from the wires.
After soldering the wire
Solder a black wire to "-", green to"Di", and white to "+5V". Once all three solders are complete, cover them with a short piece of a 14mm shrink tube.
WS2812B to Arduino Uno -
GND (Black wire) ----> GND
DI(Green wire) ----> Pin 2
+5V (White wire) ----> 5v
Sound Sensor to Arduino -
OUT ----> Pin 4
GND ----> GND
VCC ----> 5V
#include <FastLED.h> /// must have the FastLED library installed
#define LED_PIN 2 /// pin that the strip is connected to
#define NUM_LEDS 20 /// this number changes depending on how many leds are on each strip
CRGB leds[NUM_LEDS];
int soundSensor = 4; /// pin that the sound sensor is connected to
int red = 0;
int green = 0;
int blue = 0;
/// The three variables above will be used to generate a random number and create a different color everytime that the strip lightens up.
/// If you want only one color to show up, you do not need the three variables, but you will need to insert a number as an argument where the variables do show up in the void loop.
void setup() {
// put your setup code here, to run once:
pinMode(soundSensor, INPUT);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
// put your main code here, to run repeatedly:
int statusSensor = digitalRead(soundSensor);
if (statusSensor >= 1){
/// if you do not want the random color lights, do not write the next line
red = random(1, 255); green = random(1, 255); blue = random(1, 255);
for (int i = 0; i < 19; i++){
/// if you want only the single color, in the next line insert a number for each variable.
/// for example, to get the color white
/// leds[i] = CRGB(255, 255, 255); FastLED.show();
leds[i] = CRGB(red, green, blue); FastLED.show();
}
delay(100);
}
else if (statusSensor <= 2)
{
for (int i = 0; i < 19; i++){
leds[i] = CRGB(0, 0, 0); FastLED.show();
}
}
}