3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Arduino Christmas Light With Music Sync

Arduino Christmas Light With Music Sync
I came across two great instructables and decided to combine them.  http://www.instructables.com/id/Arduino-Christmas-Light-Controller/  takes eight lines of lights and uses code on the Arduino to "play" "Joy To The World".  I tested it using LEDs, and it is very accurate.  I wanted to make this project, but I wanted to have the lights synchronized to music.  So, I took a look at http://www.instructables.com/id/Yet-Another-Daft-Punk-Coffee-TableDisplay/.  It takes musical input and uses it to trigger a sequence of patterns on an LED matrix.  So, I followed the steps in the first project and added the musical input from the second.  Then, I modified the code to work with the eight trees of lights (see code below).  The good thing about this project is if you can't get the synchronization portion to work, you can still use what you have built to run the original Arduino Christmas Light Controller project.  I included two drawings -- the first is the copper trails of the PCB.  These are not to scale.  As the author of the first project pointed out, you use an etching permanent marker to draw the trails.  I recommend drilling the holes for the chip and relays first.  I found that I needed to erase with rubbing alcohol and re-draw some of the trails after drilling.  The second drawing is the component side of the board. 


#define SENSOR_PIN A0 // analog input pin for music
//void showScenario(int);
// trigger next scenario when music amplitude > threshold
// increase threshold to decrease sensitivity
// decrease threshold to increase sensitivity
int threshold = 5;
// debouncing - filter out consecutive triggers that are too close
// together to slow down the animation.  decrease this value
// to make it more sensitive to shorter beat intervals
int minBeatInterval = 1000;
int threshCrossed = 0;
int scenario = 1;
int cnt = 32768;
int tree1 = 6;
int tree2 = 7;
int tree3 = 8;
int tree4 = 9;
int tree5 = 2;
int tree6 = 3;
int tree7 = 4;
int tree8 = 5;
void setup()
{
pinMode(tree1, OUTPUT);
pinMode(tree2, OUTPUT);
pinMode(tree3, OUTPUT);
pinMode(tree4, OUTPUT);
pinMode(tree5, OUTPUT);
pinMode(tree6, OUTPUT);
pinMode(tree7, OUTPUT);
pinMode(tree8, OUTPUT);
digitalWrite(tree1,HIGH);
delay(1000);
digitalWrite(tree2,HIGH);
delay(1000);
digitalWrite(tree3,HIGH);
delay(1000);
digitalWrite(tree4,HIGH);
delay(1000);
digitalWrite(tree5,HIGH);
delay(1000);
digitalWrite(tree6,HIGH);
delay(1000);
digitalWrite(tree7,HIGH);
delay(1000);
digitalWrite(tree8,HIGH);
delay(1000);
digitalWrite(tree1,LOW);
digitalWrite(tree2,LOW);
digitalWrite(tree3,LOW);
digitalWrite(tree4,LOW);
digitalWrite(tree5,LOW);
digitalWrite(tree6,LOW);
digitalWrite(tree7,LOW);
digitalWrite(tree8,LOW);
Serial.begin(9600);
}
void showScenario(int s){
int theScenario;
theScenario = s;
 if (theScenario == 1){
digitalWrite(tree1, LOW);
digitalWrite(tree8, LOW);
digitalWrite(tree1, HIGH);
digitalWrite(tree3, HIGH);
}
if (theScenario == 2){
digitalWrite(tree1, LOW);
digitalWrite(tree3, LOW);
digitalWrite(tree6, HIGH);
digitalWrite(tree8, HIGH);
}
if (theScenario == 3){
digitalWrite(tree6, LOW);
digitalWrite(tree8, LOW);
digitalWrite(tree3, HIGH);
digitalWrite(tree4, HIGH);
}
if (theScenario == 4){
digitalWrite(tree3, LOW);
digitalWrite(tree4, LOW);
digitalWrite(tree5, HIGH);
digitalWrite(tree6, HIGH);  
}
if (theScenario == 5)
{digitalWrite(tree5, LOW);
digitalWrite(tree6, LOW);
digitalWrite(tree3, HIGH);
digitalWrite(tree4, HIGH);
}
if (theScenario == 6){
digitalWrite(tree3, LOW);
digitalWrite(tree4, LOW);
digitalWrite(tree5, HIGH);
digitalWrite(tree6, HIGH);  
}
if (theScenario == 7){
digitalWrite(tree5, LOW);
digitalWrite(tree6, LOW);
digitalWrite(tree1, HIGH);
digitalWrite(tree3, HIGH);
}
if (theScenario == 8){
digitalWrite(tree1, LOW);
digitalWrite(tree3, LOW);
digitalWrite(tree2, HIGH);
digitalWrite(tree4, HIGH); 
}
if (theScenario == 9){
digitalWrite(tree2, LOW);
digitalWrite(tree4, LOW);
digitalWrite(tree3, HIGH);
digitalWrite(tree5, HIGH); 
}
if (theScenario == 10){
digitalWrite(tree3, LOW);
digitalWrite(tree5, LOW);
digitalWrite(tree4, HIGH);
digitalWrite(tree6, HIGH);
}
if (theScenario == 11){
digitalWrite(tree4, LOW);
digitalWrite(tree6, LOW);
digitalWrite(tree5, HIGH);
digitalWrite(tree7, HIGH); 
}
if (theScenario == 12){
digitalWrite(tree5, LOW);
digitalWrite(tree7, LOW);
digitalWrite(tree6, HIGH);
digitalWrite(tree8, HIGH);
}
if (theScenario == 13){
digitalWrite(tree6, LOW);
digitalWrite(tree8, LOW);
digitalWrite(tree1, HIGH);
digitalWrite(tree4, HIGH);  
}
if (theScenario == 14){
digitalWrite(tree1, LOW);
digitalWrite(tree4, LOW);
digitalWrite(tree5, HIGH);
digitalWrite(tree8, HIGH);
}
if (theScenario == 15){
digitalWrite(tree5, LOW);
digitalWrite(tree8, LOW);
digitalWrite(tree2, HIGH);
digitalWrite(tree4, HIGH); 
}
if (theScenario == 16){
digitalWrite(tree2, LOW);
digitalWrite(tree4, LOW);
digitalWrite(tree5, HIGH);
digitalWrite(tree7, HIGH);
}
if (theScenario == 17){
digitalWrite(tree5, LOW);
digitalWrite(tree7, LOW);
digitalWrite(tree1, HIGH);
}
if (theScenario == 18){
digitalWrite(tree1, LOW);
digitalWrite(tree2, HIGH);
}
if (theScenario == 19){
digitalWrite(tree2, LOW);
digitalWrite(tree3, HIGH);
}
if (theScenario == 20){
digitalWrite(tree3, LOW);
digitalWrite(tree2, HIGH);
digitalWrite(tree4, HIGH);
}
if (theScenario == 21){
digitalWrite(tree2, LOW);
digitalWrite(tree4, LOW);
digitalWrite(tree3, HIGH);
}
if (theScenario == 22){
digitalWrite(tree3, LOW);
digitalWrite(tree4, HIGH);
}
if (theScenario == 23){
digitalWrite(tree4, LOW);
digitalWrite(tree3, HIGH);
digitalWrite(tree5, HIGH); 
}
if (theScenario == 24){
digitalWrite(tree3, LOW);
digitalWrite(tree5, LOW);
digitalWrite(tree4, HIGH);
}
if (theScenario == 25){
digitalWrite(tree4, LOW);
digitalWrite(tree5, HIGH);
}
if (theScenario == 26){
digitalWrite(tree5, LOW);
digitalWrite(tree4, HIGH);
digitalWrite(tree6, HIGH); 
}
if (theScenario == 27){
digitalWrite(tree4, LOW);
digitalWrite(tree6, LOW);
digitalWrite(tree5, HIGH);
}
if (theScenario == 28){
digitalWrite(tree5, LOW);
digitalWrite(tree6, HIGH);
}
if (theScenario == 29){
digitalWrite(tree6, LOW);
digitalWrite(tree5, HIGH);
digitalWrite(tree7, HIGH); 
}
if (theScenario == 30){
digitalWrite(tree5, LOW);
digitalWrite(tree7, LOW);
digitalWrite(tree6, HIGH);
}
if (theScenario == 31){
digitalWrite(tree6, LOW);
digitalWrite(tree7, HIGH);
}
if (theScenario == 32){
digitalWrite(tree7, LOW);
digitalWrite(tree8, HIGH); 
}
if (theScenario == 33){
digitalWrite(tree8, LOW);
digitalWrite(tree4, HIGH);
digitalWrite(tree5, HIGH); 
}
if (theScenario == 34){
digitalWrite(tree4, LOW);
digitalWrite(tree5, LOW);
digitalWrite(tree3, HIGH);
digitalWrite(tree6, HIGH); 
}
if (theScenario == 35){
digitalWrite(tree3, LOW);
digitalWrite(tree6, LOW);
digitalWrite(tree2, HIGH);
digitalWrite(tree7, HIGH); 
}
if (theScenario == 36){
digitalWrite(tree2, LOW);
digitalWrite(tree7, LOW);
digitalWrite(tree1, HIGH);
digitalWrite(tree8, HIGH); 
}
if (theScenario == 37){
digitalWrite(tree1, LOW);
digitalWrite(tree8, LOW);
digitalWrite(tree4, HIGH);
digitalWrite(tree5, HIGH); 
}
if (theScenario == 38){
digitalWrite(tree4, LOW);
digitalWrite(tree5, LOW);
digitalWrite(tree3, HIGH);
digitalWrite(tree6, HIGH); 
}
if (theScenario == 39){
digitalWrite(tree3, LOW);
digitalWrite(tree6, LOW);
digitalWrite(tree2, HIGH);
digitalWrite(tree7, HIGH); 
}
if (theScenario == 40){
digitalWrite(tree2, LOW);
digitalWrite(tree7, LOW);
digitalWrite(tree1, HIGH);
digitalWrite(tree8, HIGH); 
}
}void loop() {
int sensorValue = analogRead(SENSOR_PIN);
cnt++;
if (sensorValue > threshold) {
if (!threshCrossed && (cnt > minBeatInterval) ) {
showScenario(scenario);
scenario++;
}
if (scenario > 40){
scenario = 1;

threshCrossed = 1;
cnt = 0;

if (sensorValue < threshold){
threshCrossed = 0;
}
}








































































 
7 comments
Feb 23, 2012. 11:17 AMfibean says:
A lot of DigitalWrite's! PRO programmers may want to use port registers for smaller code. (http://www.arduino.cc/en/Reference/PortManipulation)
Feb 26, 2012. 11:07 AMfibean says:
And btw you could use Switch/Case instead of IF's. Just ideas :D (http://arduino.cc/en/Reference/SwitchCase)
Feb 26, 2012. 11:05 AMfibean says:
Ok, just an idea :3 Nice project man. The port registers are more difficult to debug, I would not recommend to write the first code with them: if something go wrong you will take a lot of time to debug. But after the v1.0 of the code you can convert to the port registers, it will make the code smaller as I already said and you can add more code in the future if you want to :D
Nov 4, 2011. 1:59 PMBlakamiss48 says:
Great PCB design. Are you using a 4 pin relay or a 5 pin relay. Or is it the same as the one used in this project http://www.instructables.com/id/Arduino-Christmas-Light-Controller/. Im just confused on which pin the 120V is conneced to on each relay . Thanks.
Nov 6, 2011. 7:25 PMBlakamiss48 says:
Ok excellent. Thanks for your help!

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
0
Followers
1
Author:psychodot5415