Introduction: Arduino Christmas Lights
Let me add this to the beginning of this... I made some very large safety mistakes in this... please if you do anything with this understand the electricity, how it should be used, and how to NOT do it like I did. There are some things are are fine... great even... and there are some things that should NOT be done. (the biggest ones I can think of are putting the relay on the neutral, instead of the hot, and using low voltage wire instead of 120v wire).
That being said everything here works, and was very educational for me. With a few minor changes you can amke this functional AND safe. Thank you.
I am very new to Arduino, but am having a lot of fun with it!!! After finishing the animatronics for my office Christmas float I decided to make some automated Christmas lights.
I know this has been done many times online, but I think this shows the best, easiest, and cheapest of some of the different ways I have found.
Most of this deals with the electrical box. I didn't take pictures of the cable build, so it is all in one step, but there is a lot there.
Also the software and a MP3 is at the end.
Let me know if you have any questions.
I will also say that I got the hot/neutral backwards. You don't want to be switching the neutral on and off and constantly pushing electrons down the other lines (the hot). Any leak, insulation damage, or whatever else will results in leaking electrons... and this is never good. So make sure the lines that are being switched are the hot lines, not the neutral.
I have keep this the same (wrong) way so as not to cause more confusion with the colors. If you are doing this I am going to assume you can make this switch without too much problem. Just make sure you are switching the hot, not the neutral.
Attachments
Step 1: Intro
Arduino. I used the Arduino Mega 2560 and Ada Fruit Wave Shield. I went with the Mega because I wanted to be able to control more lights. With the mega I effectively can control as many as I want (not hundred, but dozens). If you want to go this way make sure you check out the differences in building the Wave Shield for the Mega as opposed for the Uno. Basically pins 10-13 need to be redirected to 50-53 ("CCS" to 53, 11 to 51, 12 to 50, 13 to 52). I'm not going to go into all of the changes for that, the AdaFruit forums are much better than I could do.
If you haven't used electrical scissors get them, I love them. Same with wire strippers. These are both things I have been reluctant to use for years, preferring to stick with a knife. Go for the succors and stripper.
In-sure wire connectors are not needed, but they sure make the connections easier.
Be sure to get jumper wires that are male on one end, and female on the other. There aren't many like that, so look for them, the ones from AdaFruit are good.
cheap electrical outlets.
Cheap plug from Home Depot
4-Gang Old Work Outlet Box. This makes a pretty good project box. I still need to get a 4 place faceplate to finish it off, and get another outlet box to house the arduino and relays. Currently it is functional, but not pretty.
Romex wire. It may be easer and better to just use some speaker wire or something like that, but I had the romex and so I used it.
SainSmart 8-Channel Relay Module. This makes this easy, and is likely cheaper than any you would roll yourself. The only downside is you have to make sure you program them backwards from what I am used to... low is on, high is off. Strange, maybe that is how they do it in China.
Laptop for programing the Arduino. Make sure you switch the board from the Uno to the Mega... that one took me a while to figure out why it was not compiling right!!!
Step 2: The Outlets
I will be passing the neutral through the relay. You can use hot, but it is not as safe, and not the standard. I would just stick with neutral. A few ways to know the difference is neutral has the wider outlet, the neutral is on the left of the receptacle (assuming ground is down), the neutral is often aluminum color and the hot is copper, the neutral line is ribbed, and usually the writing is on the hot line. A line tester will only light on hot side. These are only guidelines, so check and make sure you know which line you are working with.
There is a little tab between the screws on the outlet that is the only thing that connects the top and bottom receptacle in an outlet. If you want to have two different circuits in a outlet you can easily break this off. In our project ONLY BREAK OFF THE HOT SIDE (the side with the large plug). (I have 4 extra receptacles with both the hot and neutral tabs broken off if you need them). You can do it with both tabs broken off, but is is much easier if you don't.
In these pictures you can see the tab, see it half broken off, and see if off.
Step 3: Wire the Hot
At this point go ahead and make the wall plug in. Cut a romex piece 2-3 foot long. Make sure the neutral is attached to the wide plug. Twisting the two lines together keep things much better organized.
Step 4:
Also you can see the plug put together, and the lines twisted.
Also there are 8 pieces of romex cut about 10-12 inches long. I will take these apart, using the hot and neutral insulated wires, but keep the ground wire is not used, and kept for recycling.
Step 5:
The short 1/4-1/8 inch end is for connecting to the relay.
Step 6:
Step 7:
Step 8: Label the Wires
I used a line for 1, and a block for 5. In the picture you can clearly see a 7 and 8 in the middle, and a 1 is blurry on the right.
Step 9:
The hot wire goes directly to the hot screw on the closest outlet. The electricity will be spread to all of the plugs through the jumpers that gang all of the plugs together.
All of the other wires you see down in the box (most of them) are neutral. It would have been better to have another color, but I didn't... so the dark color is the neutral that is all ganged together with the In-sure connectors, and going out to the relays, and the white is the neutral coming back from the relay, and will only be neutral when the relay is closed.
Step 10:
The power is coming in from the top right. The hot is going to the first outlet, and a jumper wire is used to gang together all 4 outlets.
The neutral line is then ganged tougher with the In-sure connectors and going out of the box as the dark wires. The white wires will be coming back from the relay. If you look you can see the numbering system I put on the wires with brown sharpie.
Step 11:
The 8 dark lines are all ganged together neutral, and are connected to the common (C) relay contact.
The whites are attached to the normal open (NO) contact. You can see that I have now numbered the outlet, and the wire.
Step 12:
Step 13:
First, two things. First I have made a few changes because of the education someone else took the time to help me with. The hot and neutral do matter. You don't want to be constantly sending elections down the wire unless you want to do something with them. Sure they will do nothing as long as there is no where to go, but just one little knick and you will have trouble. The common should be neutral for a reason. I think I have made all of theses changes, but if you find an area that does not agree with the rest sorry... I may have missed one.
Second... use your brain. Just because someone did it one way... just because you can do something one way... does not mean you should. Using things differently than they were designed should always be cause for concern. Fuses, gauge size, insulation, GFCI outlets, and just good ole common sense all should come into play when doing anything like this, especially when working with 110v AC.
What you need:
7 strand sprinkler cable
6 male and 6 female plugs
two stranded wire (lamp cord)
black electrical tape... quite a bit of it.
I used 7 circuit sprinkler cable. It has 7 solid copper strands, each with their own color. You can see most of the colors where I have the male plug ends. The neutral is not seen in this version. I made two of them, and I liked the way I did this one better.
Strip about 1-2 feet of the outer black sheath exposing the 7 wires. Pick which color you want to be neutral, I chose white.
Strip most of the insulation off the white (or whatever color you want to be neutral). Leave about 1" near the base so you can make sure the insulation is totally covered.
Take 3 strands of the two stranded wire about the same length as your stripped wire (about 1-1.5 feet). Split these two wires from each other so you have 6 wires. Strip 1/2" from one end, and 1-2" from the other.
Twist all 6 of these around the base of the stripped (white) wire (this is where you will appreciate the 1-2 inches you stripped from the wire!!). Then take long bare copper wire and wrap it around the bundle of wire you now have. This will not only ensure you have a bullet proof connection, and will more importantly make sure you don't have one wire come loose from the rest. You then coat this with a generous covering of electrical tape.
You will then put the male plugs together using one wire from the sprinkler cable, and one from the neutral wire you have all ganged together with the white wire.
Now you decide how far down the line you want each connector. As I wanted my line to be fairly generic I spaced them all evenly apart.. about 18 foot (really 3 fully stretched arms, and the last two just split half way to the end, and then the end).
Very carefully split the black outer sheath only. You don't want to nick the insulation of any of the inner wires. You then pick which line you want to use first. I usually try and follow rainbow orders of colors, so I always know which one is next (Roy G Biv anyone?) So my first female plug was red, then yellow, green, blue, brown, and finally black. Make sure you label each female plug as you will not know what color they are once you are done.
Once you have your hot wire (red for the first one) and neutral (white) isolated from the rest (they will always be at the bottom of the bundle, it is a rule of projects, one of Murphy's) you can take the insulation off. The hot (red) wire can be cut if you aren't going to be using it further down the line, but as I may want to put a line somewhere else down the line I kept all the lines intact. Make sure you keep the white (neutral) line intact, or if you cut it reconnect the ends together. You will for sure need it to be intact all the way to the end.
Use the two stranded wire to attach to the wires you have now exposed. A generous amount of electrical tape will keep everything in place, and hopefully watertight. I made the tail from the female plug about 1.5 feet long, but you can make it as long as you like.
Continue connecting each hot (colored) strand until all of the colors are used it. In my wire it was 6, as I had a 7 strand wire. There are also 5 strand wires.
I am still not sure if I should make the white (common) wire as the hot or the neutral, but as long as you are consistent it should be fine. I am sure there is some EE groaning right now... so please educate me.
*********************** Someone did educate me!!! (Thank you very much). The HOT is the one what should be switched. This way you only have electrons being pushed down the line when the lights should be one. Otherwise electrons are always trying to be pushed down the line. Sure, it will work either way, but it is a fairly big safety thing).
I am also trying to decide if the electrical tape is good enough to be left outside. I have several layers, all wrapped very tight, but it still makes me a little nervous.
Step 14: Software
So here is the code. Again it is the code for the Joy to the World file. The version I uploaded is MP3, but if you use the wave shield it will need to be converted to WAV.
Also, I got tired of dealing with the very long code for the lights in the loop, so I made it a function, called "joy()".
Here is the Arduino code:
// By: Tre' Landrum
#include
#include
#include
#include "WaveUtil.h"
#include "WaveHC.h"
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
#define DEBOUNCE 5 // button debouncer
//This is for the dancing lights durring joy to the world
// if you are using the Uno instead of the Mega you will need to change these pins. If you use the WaveShield you will only have a few pins avaialbe... 6-9 from the top of my head.
int light1 = 22;
int light2 = 24;
int light3 = 26;
int light4 = 28;
int light5 = 30;
int light6 = 32;
int light7 = 34;
int light8 = 36;
int s = 150;
int ds = 225;
int e = 300;
int de = 450;
int q = 600; //600
int dq = 900;
int h = 0; //1200
int dh = 1800;
int start;
int end;
int time;
int now;
// Variables will change:
// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {14, 15, 16, 17, 18, 19};
// This handy macro lets us determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
// we will track if a button is just pressed, just released, or 'pressed' (the current state
volatile byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
// this handy function will return the number of bytes currently free in RAM, great for debugging!
int freeRam(void)
{
extern int __bss_end;
extern int *__brkval;
int free_memory;
if((int)__brkval == 0) {
free_memory = ((int)&free_memory) - ((int)&__bss_end);
}
else {
free_memory = ((int)&free_memory) - ((int)__brkval);
}
return free_memory;
}
void sdErrorCheck(void)
{
if (!card.errorCode()) return;
putstring("\n\rSD I/O error: ");
Serial.print(card.errorCode(), HEX);
putstring(", ");
Serial.println(card.errorData(), HEX);
while(1);
}
void setup() {
byte i;
// set up serial port
Serial.begin(9600);
putstring_nl("WaveHC with ");
Serial.print(NUMBUTTONS, DEC);
putstring_nl("buttons");
putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad
Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!
// Set the output pins for the DAC control. This pins are defined in the library
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
// pin13 LED
pinMode(13, OUTPUT);
// Make input & enable pull-up resistors on switch pins
for (i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT);
digitalWrite(buttons[i], HIGH);
}
// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
putstring_nl("Card init. failed!"); // Something went wrong, lets print out why
sdErrorCheck();
while(1); // then 'halt' - do nothing!
}
// enable optimize read - some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);
// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
putstring_nl("No valid FAT partition!");
sdErrorCheck(); // Something went wrong, lets print out why
while(1); // then 'halt' - do nothing!
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
putstring_nl("Can't open root dir!"); // Something went wrong,
while(1); // then 'halt' - do nothing!
}
// Whew! We got past the tough parts.
putstring_nl("Ready!");
TCCR2A = 0;
TCCR2B = 1<
//Timer2 Overflow Interrupt Enable
TIMSK2 |= 1<
pinMode(light1, OUTPUT);
pinMode(light2, OUTPUT);
pinMode(light3, OUTPUT);
pinMode(light4, OUTPUT);
pinMode(light5, OUTPUT);
pinMode(light6, OUTPUT);
pinMode(light7, OUTPUT);
pinMode(light8, OUTPUT);
//the SainSmart Relay's are off high
digitalWrite(light1,HIGH);
digitalWrite(light2,HIGH);
digitalWrite(light3,HIGH);
digitalWrite(light4,HIGH);
digitalWrite(light5,HIGH);
digitalWrite(light6,HIGH);
digitalWrite(light7,HIGH);
digitalWrite(light8,HIGH);
Serial.begin(9600);
} //void setup()
SIGNAL(TIMER2_OVF_vect) {
check_switches();
}
void check_switches()
{
static byte previousstate[NUMBUTTONS];
static byte currentstate[NUMBUTTONS];
byte index;
for (index = 0; index < NUMBUTTONS; index++) {
currentstate[index] = digitalRead(buttons[index]); // read the button
/*
Serial.print(index, DEC);
Serial.print(": cstate=");
Serial.print(currentstate[index], DEC);
Serial.print(", pstate=");
Serial.print(previousstate[index], DEC);
Serial.print(", press=");
*/
if (currentstate[index] == previousstate[index]) {
if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
// just pressed
justpressed[index] = 1;
}
else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
// just released
justreleased[index] = 1;
}
pressed[index] = !currentstate[index]; // remember, digital HIGH means NOT pressed
}
//Serial.println(pressed[index], DEC);
previousstate[index] = currentstate[index]; // keep a running tally of the buttons
}
}
//**********************************************************************************************************
//**********************************************************************************************************
void loop() {
byte i;
//Make sure you change the name of the file to what you want
playfile("JOY.WAV");
joy(); // This is the function that plays joy to the world
}//void loop() {
//**********************************************************************************************************
//**********************************************************************************************************
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}
void playfile(char *name) {
// see if the wave object is currently doing something
if (wave.isplaying) {// already playing something, so stop it!
wave.stop(); // stop it
}
// look in the root directory and open the file
if (!f.open(root, name)) {
putstring("Couldn't open file "); Serial.print(name); return;
}
// OK read the file and turn it into a wave object
if (!wave.create(f)) {
putstring_nl("Not a valid WAV"); return;
}
// ok time to play! start playback
wave.play();
}
// Function for making the diffrent strands light diffrent
void joy() {
putstring_nl("Start of Joy to the World");
start = millis();
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(q);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(de);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(s);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(1050);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(s);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(q);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(q);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(dq);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
digitalWrite(light7, LOW);
delay(dq);
digitalWrite(light2, HIGH);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
digitalWrite(light6, LOW);
delay(dq);
digitalWrite(light3, HIGH);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light3, LOW);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
digitalWrite(light6, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(dq);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light3, HIGH);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
//8100
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light8, HIGH);
digitalWrite(light1, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light7, LOW);
delay(e);
digitalWrite(light7, HIGH);
digitalWrite(light2, LOW);
delay(e);
digitalWrite(light2, HIGH);
digitalWrite(light6, LOW);
delay(e);
digitalWrite(light6, HIGH);
digitalWrite(light3, LOW);
delay(de);
digitalWrite(light3, HIGH);
digitalWrite(light5, LOW);
delay(s);
digitalWrite(light5, HIGH);
digitalWrite(light4, LOW);
delay(e);
digitalWrite(light4, HIGH);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light8, HIGH);
digitalWrite(light1, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light7, LOW);
delay(e);
digitalWrite(light7, HIGH);
digitalWrite(light2, LOW);
delay(e);
digitalWrite(light2, HIGH);
digitalWrite(light6, LOW);
delay(e);
digitalWrite(light6, HIGH);
digitalWrite(light3, LOW);
delay(de);
digitalWrite(light3, HIGH);
digitalWrite(light5, LOW);
delay(s);
digitalWrite(light5, HIGH);
digitalWrite(light4, LOW);
delay(e);
digitalWrite(light4, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(e);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(e);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
//13806
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(75);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(75);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(dq);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(75);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
//15235
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(75);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(e);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(e);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(e);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(75);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(75);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(dq);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(75);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
//17339
digitalWrite(light2, LOW);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
digitalWrite(light7, LOW);
delay(75);
digitalWrite(light2, HIGH);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
digitalWrite(light6, LOW);
delay(e);
digitalWrite(light3, HIGH);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light3, LOW);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
digitalWrite(light6, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(q);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light3, HIGH);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
//18315
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(e);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(de);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(s);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
delay(e);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light3, LOW);
digitalWrite(light6, LOW);
delay(e);
digitalWrite(light3, HIGH);
digitalWrite(light6, HIGH);
putstring_nl(" "); //19817
digitalWrite(light2, LOW);
digitalWrite(light7, LOW);
delay(300);//delay(q);
digitalWrite(light2, HIGH);
digitalWrite(light7, HIGH);
now = millis();
time = now - start;
Serial.println(time); //20117
digitalWrite(light1, LOW);
digitalWrite(light8, LOW);
delay(300);//delay(q);
digitalWrite(light1, HIGH);
digitalWrite(light8, HIGH);
putstring_nl(" last bit ");
// 21018
digitalWrite(light1, LOW);
digitalWrite(light2, LOW);
digitalWrite(light3, LOW);
digitalWrite(light4, LOW);
digitalWrite(light5, LOW);
digitalWrite(light6, LOW);
digitalWrite(light7, LOW);
digitalWrite(light8, LOW);
delay(h);
digitalWrite(light1, HIGH);
digitalWrite(light2, HIGH);
digitalWrite(light3, HIGH);
digitalWrite(light4, HIGH);
digitalWrite(light5, HIGH);
digitalWrite(light6, HIGH);
digitalWrite(light7, HIGH);
digitalWrite(light8, HIGH);
delay(000);
putstring_nl("end of the song");
end = millis();
time = end - start;
Serial.println(time);
Serial.println(start);
Serial.println(end);
}