WS2812b Music Rhythm Light Bar Using Arduino

By Tanmoy Kundu

Updated On:

Music Rhythm Light Bar Using Arduino

Bring your music to life with a cool glowing music meter!

Imagine you create your own Music Rhythm Light Bar at home that captures the essence of the music rhythm and adds a vibrant, dynamic light show to your living room during a party with friends. With the powerful combination of Arduino and WS2812B NeoPixel LEDs, you can transform your audio experience into a visually stunning spectacle.

In this tutorial, we will walk you through the step-by-step process of building an RGB Music Rhythm Light Bar using Arduino. Whether you’re a hobbyist or a curious beginner, this project is a fantastic way to dive into electronics, programming, and creative design. By the end of this tutorial, you’ll have built a fully functional VU meter that reacts to the beat of the music playing in your room, which makes it perfect for parties, home decor, or just for a fun project.

Music Rhythm Light Bar Using Arduino

Must Read WS2812b Music Reactive LED Light Using WLED

Circuit Diagram

Music Rhythm Light Bar Circuit Diagram

Components Required

  • Arduino Nano
  • Sound Sensor
  • WS2812b Neopixel Led
  • Led Casing
  • Connection Wire
  • 5 Volt Power Supply

Understanding Components of Music Rhythm Light Bar

Arduino Uno: Acts as the brain of the project, processing input from the microphone sensor and controlling the LED strip.

WS2812B NeoPixel LED Strip: Contains individually addressable RGB LEDs, allowing for complex colour patterns and animations.

Sound Sensor: Detects sound levels in the environment, converting them into an electrical signal that the Arduino can process.

Connection of the Components

Powering the LED Strip:

  • Connect the 5V power supply’s positive terminal to the +5V pin on the LED strip.
  • Connect the ground terminal of the power supply to the ground pin on the LED strip.

Connecting the Data Line:

  • Connect the data pin of the LED strip to a digital pin on the Arduino (e.g., pin 2).

Sound Sensor Connection:

  • Connect the VCC pin of the sound sensor to the 5V pin on the Arduino.
  • Connect the GND pin of the sound sensor to the GND pin on the Arduino.
  • Connect the analog output pin of the sound sensor to an analog input pin on the Arduino (e.g., A0)

Arduino Power:

  • Connect the Arduino to your computer via USB or use an external 5V power supply.

Installing the Required Libraries

To control the WS2812B LEDs, you’ll need the Adafruit NeoPixel library. Install it through the Arduino IDE by following these steps:

  • Open the Arduino IDE.
  • Go to Sketch > Include Library > Manage Libraries.
  • In the Library Manager, search for “Fastled“.
  • Click “Install” to add the library to your Arduino IDE.
#include <FastLED.h>

#define LED_PIN     2
#define NUM_LEDS    29
#define BRIGHTNESS  255
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB

CRGB leds[NUM_LEDS];

#define AUDIO_PIN   A0  // Pin where the audio signal is connected

void setup() {
  // Initialize FastLED
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(BRIGHTNESS);

  // Initialize serial communication
  Serial.begin(9600);
}

void loop() {
  // Read audio signal from analog pin
  int audioValue = analogRead(AUDIO_PIN);

  // Smooth out the audio value to reduce flickering
  static int smoothedValue = 0;
  smoothedValue = (smoothedValue * 0.9) + (audioValue * 0.1);

  // Map the audio value to the number of LEDs
  int numLedsToLight = map(smoothedValue, 0, 1023, 0, NUM_LEDS);

  // Create a moving rainbow effect
  static uint8_t hue = 0;
  hue += 1;  // Adjust this value to change the speed of the rainbow effect

  // Set the LEDs based on the audio signal and apply the rainbow effect
  for (int i = 0; i < NUM_LEDS; i++) {
    if (i < numLedsToLight) {
      leds[i] = CHSV((hue + (i * 10)) % 255, 255, 255); // Rainbow effect
    } else {
      leds[i] = CRGB::Black; // Turn off the remaining LEDs
    }
  }

  // Update the LEDs
  FastLED.show();
  
  // Add a small delay to smooth the visualizer effect
  delay(10);
}

Fine-Tuning and Enhancements

Depending on your sound sensor capturing capability, adjust the preset using a screwdriver to set it at your suitable sound-capturing range.

Troubleshooting Tips

LEDs Not Lighting Up: Double-check all connections, especially the data line and power supply. Ensure that the LED strip is receiving the correct voltage.

Inconsistent Lighting: Verify that the VCC +5V is installed correctly across the power supply terminals to stabilize voltage fluctuations.

Sound Sensitivity Issues: Adjust the sound sensor’s preset to smooth out the microphone sensor’s output.

Conclusion

Creating a Music Rhythm Light Bar using Arduino and WS2812B NeoPixel LEDs is a very interesting project that combines electronics, programming, and creativity. By following the steps in this guide, you can easily build a visually stunning lighting system that enhances your music-listening experience. Whether you are using it for a party, a DIY home theatre setup, or simply as a fun project, the possibilities for customization and enhancement are endless.

Output Video

Tanmoy Kundu

I'm the founder of Circuit Diagrams, holds a B.Sc in Electronics and a Master's in Computer Applications (MCA). With a strong foundation in both hardware and software, I combines my passion for electronics and programming to create practical, real-world DIY projects. Driven by the goal of simplifying embedded systems and IoT development, I designs, tests, and documents each project to ensure it's accessible for students, beginners, and makers of all levels. My mission is to turn complex concepts into easy-to-follow solutions through detailed tutorials, eBooks, and custom circuit designs.

Leave a Comment

Item added to cart.
0 items - 0.00