Simple Christmas Automated Light Show (Arduino + Processing)

Welcome everyone, my name is John and today we concluded our project for our door decorating contest at Korah Collegiate and Vocational School, where we placed third. I thought this would be an amazing idea to share as this is a pretty simple project to complete with an amazing final product! This guide will be in order of: Materials, Schematic, Arduino Code, Processing Code.
Link to Final Product: Computer Engineering - YouTube

Materials Required:
-3 different colour LED lights. These are found around Christmas time at the Dollar store for 1.25$ CAD for 10 lights (Use as many light strips of each colour you want.
-Breadboard
-Wiring
-Arduino (In our case UNO)
Optional:
-Soldering Iron/Electrical Tape
-Wire Strippers

Schematic:
Lightshow Breadboard - Album on Imgur - I apologize I could not figure out how to post pictures in this forum
Arduino Code:

char state;
char ledPinState = 'i';
char ledPinState2 = 'o';
char ledPinState3 = 'p';
void setup() {
  // put your setup code here, to run once:   
pinMode(11, OUTPUT);    
pinMode(5, OUTPUT);  
pinMode(3, OUTPUT); 
pinMode(7, OUTPUT); 
Serial.begin(9600);

}
void loop() {
  delay(50);
  digitalWrite(11, LOW);
  digitalWrite(5, LOW);
  digitalWrite(3, LOW);
  digitalWrite(7, LOW);
   if (Serial.available() > 0) {
    state = Serial.read();
    if (state == 'i') {
      digitalWrite(11, HIGH);
      digitalWrite(7, HIGH);
    }
   }
    if (Serial.available() > 0) {
    state = Serial.read();
    if (state == 'p') {
      digitalWrite(3, HIGH);

      }
   }
   if (Serial.available() > 0) {
    state = Serial.read();
    if (state == 'o') {
      digitalWrite(5, HIGH);
              }
          }
}

Processing Code:

import org.firmata.*;
import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;

Serial port;
Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl; 
class BeatListener implements AudioListener
{
  private BeatDetect beat;
  private AudioPlayer source;
  
  BeatListener(BeatDetect beat, AudioPlayer song)
  {
    this.source = song;
    this.source.addListener(this);
    this.beat = beat;
  if(song.isPlaying() == false){
    indexFile++;
    beat = new BeatDetect(song.bufferSize(), song.sampleRate());
    song = minim.loadFile(namesFiles[indexFile], 2048);
      }
  }
  
  void samples(float[] samps)
  {
    beat.detect(song.mix);
  }
  
  void samples(float[] sampsL, float[] sampsR)
  {
    beat.detect(song.mix);
  }
}
int powerPin = 11;
int ledPin = 5;    // LED connected to digital pin 12
int ledPin2 = 4;    // LED connected to digital pin 1
int ledPin3 = 3;    // LED connected to digital pin 0
float kickSize, snareSize, hatSize;
  String[] namesFiles = {"\\Users\\John Pierman\\Desktop\\JingleRockTrap.wav"};
  int indexFile = 0;

void playSong(){
   song = minim.loadFile(namesFiles[indexFile], 2048);
   song.play();
  beat = new BeatDetect(song.bufferSize(), song.sampleRate());
  beat.setSensitivity(10); 
}


void setup() {

  printArray(Serial.list());
  size(512, 200, P3D);
    port = new Serial(this,Serial.list()[1], 9600);
  minim = new Minim(this);
  playSong();
  
  kickSize = snareSize = hatSize = 16;
  bl = new BeatListener(beat, song);  
  textFont(createFont("Helvetica", 16));
  textAlign(CENTER);
}

void draw() {
  if(song.isPlaying() == false){
    indexFile++;
    playSong();
    bl = new BeatListener(beat, song); 
      if (indexFile == namesFiles.length){
        indexFile = 0;
        playSong();
        bl = new BeatListener(beat, song); 
      }
  }
  background(0);
  fill(255);
  if(beat.isRange(0,1,1)) {
     // arduino.digitalWrite(ledPin, Arduino.HIGH);
      port.write('i');
      kickSize = 32;
  }
  if(beat.isRange(1,2,1)) {
      //arduino.digitalWrite(ledPin2, Arduino.HIGH);
      port.write('p');
      snareSize = 32;
  }
  if(beat.isRange(2,3,1)) {
     port.write('o');
      hatSize = 32;
  }
 
  textSize(kickSize);
  text("Beat1", width/4, height/2);
  textSize(snareSize);
  text("Beat2", width/2, height/2);
  textSize(hatSize);
  text("Beat3"", 3*width/4, height/2);
  kickSize = constrain(kickSize * 0.95, 16, 32);
  snareSize = constrain(snareSize * 0.95, 16, 32);
  hatSize = constrain(hatSize * 0.95, 16, 32);
}
void stop() {
  // always close Minim audio classes when you are finished with them
  song.close();
  // always stop Minim before exiting
  minim.stop();
  // this closes the sketch
  super.stop();
}

Ideas Behind Code: Processing uses Minim Libraries to detect sound frequencies from the beats, and then sends a serial input to the Arduino. This input is a character specific to the pin which will distribute power. Following this idea to Arduino IDE, it then asks if this latest serial input is the specified character, then release power. There is some extra functionalities in the processing code such as the ability to play multiple songs. *Note when it finishes the queue (array) of songs, the program hangs. This is a known bug and is a WIP.

I am happy to help, feel free to reply and I will respond ASAP, thanks!

I apologize I could not figure out how to post pictures in this forum

At the bottom:
more > modify > attachments and other options
If you have the schematic as a jpg or png file and attach it then it will be displayed.

You might have to go back and move the auto inserted code to display the image where you want it shown.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.