Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
kpower
Published © GPL3+

Arduino Stereo Light Stick Speakers synchronized to music

Make a pair of light stick speakers that are synchronized to music and create a stunning light show

IntermediateFull instructions provided5 hours300
Arduino Stereo Light Stick Speakers synchronized to music

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SparkFun VS1053 MP3 Shield
×1
5V RGB Full Color Pixel LED chain with WS2811 IC
×1
5V 2.5A Switching Power Supply
Digilent 5V 2.5A Switching Power Supply
×1
12V 2A Power Supply
×1
Flash Memory Card, SD Card
Flash Memory Card, SD Card
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

WS2811 Specification Sheet

Schematics

Schematic

Stereo Light Speakers and control

Code

MP3 Shield Test

Arduino
Use this simple code to check that the MP3 shield will play a song from the SD Card
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>

SdFat sd;
SFEMP3Shield MP3player;

void setup() {

  Serial.begin(9600);

  // start the SD card reader
  sd.begin(SD_SEL, SPI_HALF_SPEED);
  // start the MP3 shield
  MP3player.begin();

  //start playing track 1
  MP3player.playTrack(1);
}

//do something else now
void loop() {

  Serial.println("Playing");
  delay(5000);

}

Final Demonstration

Arduino
This code will play Back in Black to a light show
/*
/ Example to show working of FastLED with various animations synchronized to music
/ Here are the animations included in this program:
/- applause (a)
/- begin show fade up(b)
/- confetti (c)
/- beat (d)
/- middle to outer (o)
/- top to bottom (t)
/- fill from one to full (w)
/- juggle (j)
/- sprinkle
/- rainbow (r)
/- beats per minute (m)
*/

#include <FastLED.h>
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h> 
#include <SFEMP3Shield.h>

#define NUM_LEDS 23 // define the number of LEDS in your strip
// Using a WS2811 led strip - only need to define a data pin
// Clock pin not required
#define DATA_PIN 5
#define BRIGHTNESS 100 // Set brightness to required value
#define FRAMES_PER_SECOND 60 // This not specifically required for this program
CRGB leds[NUM_LEDS]; // Define the array of leds. For this project was set at 23
byte gHue = 0; // gHue used by various routines to vary color

// Initialize Sd Card and VS1053 chip
SdFat sd;
SFEMP3Shield MP3player;

// Define a C++ data structure that will hold which animation to play after a given time
// See later in program for initialization of structure
typedef void (*pattern)();
struct PatternandTime {
  pattern patFunc;
  unsigned long mTime;
};
// All animations defined in following functions
// An animation to play while the crowd goes wild after the big performance
// Simulates applause
void a() {
  static unsigned int lastPixel = 0;
  fadeToBlackBy(leds, NUM_LEDS, 32);
  leds[lastPixel] = CHSV(random8(HUE_BLUE, HUE_PURPLE), 255, 255);
  lastPixel = random16(NUM_LEDS);
  leds[lastPixel] = CRGB::White;
}

// This routine to begin a show. Lights fade up
void b() {
  static byte bright = 50;
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::DarkMagenta;
  }
  FastLED.setBrightness(bright);
  bright++;
  if(bright > 100){
    bright = 100;
  }
}

// Random colored speckles that blink in and fade smoothly
void c() {  
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

// Lights pulse to a beat. Adjust beatDelay to BPM of song.
// beatDelay = 60000/(BPM * 2)
void d(){
  static bool onOff = true;
  unsigned long beatDelay = 319;  

  if(onOff == true){
    fill_solid(leds, NUM_LEDS,CRGB::Fuchsia); // Fill all LEDs with solid color   
  }
 
  if(onOff == false){
    FastLED.clear(true);  // Clear LED array and set all LEDs to black 
  }
  FastLED.delay(beatDelay);
  onOff = !onOff;
}

// Eight colored dots, weaving in and out of sync with each other
void j() {  
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16(i+7,0,NUM_LEDS)] |= CHSV(dothue, 200, 255);
    dothue += 32;
  }
}

// Colored stripes pulsing at a defined Beats-Per-Minute (BPM)
// Adjust BeatsPerMinute to match music
void m() {
  uint8_t BeatsPerMinute = 94;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}
// Animation to move colored pixels from middle to outer
void o(){
  static byte count = 0;
  byte halfLeds = NUM_LEDS/2;
  for (int i = 0; i <= NUM_LEDS; i++){
    leds[i] = CRGB::FloralWhite;
    if(i >= (halfLeds-count) && i <= (halfLeds+count)){
      leds[i] = CRGB::Red;
    }
  }
  count++;
  if(count > halfLeds){
    count = 0;
  }
  FastLED.delay(200);
}

// Animation that displays rainbow like colors across the string
void r() {
  // FastLED's built-in rainbow generator
  fill_rainbow(leds, NUM_LEDS, gHue, 7);
}

// Animation to move three pixels from top to bottom
void t() {
  static byte count = 0;
  FastLED.clear(true); // Clear all LEDs
  leds[count] = CRGB::FloralWhite;
  leds[count+1] = CRGB::FloralWhite;
  leds[count+2] = CRGB::FloralWhite;
  count++;
  if(count > NUM_LEDS){
    count = 0;
  }
  FastLED.delay(70);
}

// Starting with one pixel, fill to complete array
void w(){
  static byte j = 1;
  for (byte i = 0; i < j; i++){
    leds[i] = CRGB::Yellow;
  }
  j++;
  if(j > NUM_LEDS + 1){
    j = 1;
    FastLED.clear(true);
  }
  FastLED.delay(70);
}

// This is the C++ stucture that holds animation to be played (a,b,c etc) and the time it stays on
// Edit this structure to suit music that needs to be synchronized
// Change size of structure to suit the number of animation changes
PatternandTime playList[12] = {
  { b, 6831 },
  { d, 21119 },
  { m, 21990 },
  { r, 19274 },
  { m, 40699 },
  { o, 40799 },
  { r, 20746 },
  { c, 20493 },
  { r, 19229 },
  { w, 5468 },
  { d, 12803 },
  { a, 19138 }  
};

void setup() {

  delay(1500);  // 1.5 second delay for recovery and stabilization
  FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);  //Create the FastLED arrary / object
  FastLED.clear(true);  // Clear LED array and set all LEDs to black
  sd.begin(SD_SEL, SPI_HALF_SPEED); // Begin SD Card
  MP3player.begin(); // Begin MP3 Player
  MP3player.setVolume(05,05); // Set volume of MP3 Player to about 95%
  FastLED.delay(1000); // Wait a second before beginning
  MP3player.playTrack(1); // Start playing song from sd card
}

int i = 0;
unsigned long patternTime;

void loop() {

  patternTime = millis() + playList[i].mTime; // Add current time to the animation play time from structure
  while (millis() < patternTime){ 
    playList[i].patFunc();  // Call animation
    FastLED.show();
    gHue++; // required for certain animation routines to vary color
  }

  // Once animation time has completed, advance counter to next animation
  i++;
  FastLED.clear(true);
  if (i > 11){  // Adjust number here to suit no of animations in structure
    i = 0;  // Reset back to beginning of show
  }
}

Credits

kpower
19 projects • 6 followers
Qualified Electrical Engineer with experience in software and hardware development
Contact

Comments

Please log in or sign up to comment.