Tuesday, December 17, 2013

Arduino Christmas lights

Arduino Lights to Music

Intro

This will show you how to build a lights-to-music controller using an “Ardunio” micro-controller.  You will need a windows computer to run “Vixen” the free software program to make the lights turn off and on, and you will need either a PC or a Mac to run the Arduino programing program.

Here’s what you need (Basic Design)




LED Lights $7.89 for 60 (make sure they come with resistors)
http://www.amazon.com/gp/product/B004UZDKRG/ref=oh_details_o00_s01_i00


Basic Circuit Design

1.    Connect your power wire to the “Anode” side of the LED
2.    Connect your “Cathode” side of the LED to one side of a “Resistor”
3.    Connect the other side of the “Resistor” to the ground wire.
This will complete the circuit and let turn the LED on.  For our project the Power wire will be one of the pin outputs from the arduino (labeled 2 – 13 on the side of the board”

 

Circuit with Arduino

1.    Each pin on the board (2-13) connect to a strip on the board
2.    Each strip then plugs into the Anode of its own LED
3.    Each LED cathode plugs into a strip on the opposite side of the breadboard
4.    That strip is then connected to an adjacent strip on the breadboard by a resistor
5.    The strip on the resistor side then connects to a common ground “BUS” at the bottom of the breadboard
6.    On the right side of the breadboard use a wire to connect the top ground “Bus” to the bottom ground “Bus” as indicated by the green wire on the image below.
7.    Now on the Ardunio you will see a pin near the top that says Gnd.  Make sure this is connected to your ground bus.
Once all LEDs are wired in you are ready to program your ardunio.
This will complete the circuit and let turn the LED on.  For our project the Power wire will be one of the pin outputs from the arduino (labeled 2 – 13 on the side of

Basic Program

To make an Ardunio work you must program it.  To do this we must use the Ardunio programing software.  You can download it from: http://arduino.cc/en/Main/Software
This software will work on both PC and Mac
After downloading your software use a USB cable and plug the Arduino into the computer and start the programming software program.
Under the tools menu you will need to select the device you are using.  In this document we are selecting the “Arduino Uno”

Now you will need to select the port so the computer knows where to find the Arduino.  On a windows machine this will typically be something like “Com 3, Com 4 ect…”, on a Mac it will look like /dev/tty.USB  (don’t use Bluetooth as indicated below because the Arduino does not have a Bluetooth connector).

Now for the code

All arduino code has at least 3 sections
1.    Top of code (you define what things are)
2.    Setup(). The code in setup() is run first always
3.    Loop().  The loop code is where your program runs
In any of the code below, if you see // that means it is a comment and the code will not do anything with that text.  We use this to describe what is happening in each section without messing up our programming code.

Simple code to turn 3 lights on and then off.



Int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
void setup(){
    Serial.begin(9600);
        pinMode(pin2, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin2, 0); // Turn pin 2 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin2, 255); // Turn Pin 2 off and make the light go off
      //Do the same thing with Pin 3
       pinMode(pin3, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin3, 0); // Turn pin 3 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin3, 255); // Turn Pin 3 off and make the light go off
//Do the same thing with Pin 4
       pinMode(pin4, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin4, 0); // Turn pin 3 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin4, 255); // Turn Pin 3 off and make the light go off
}
void loop()
{
Make light 1 blink 2 times
        pinMode(pin2, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin2, 0); // Turn pin 2 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin2, 255); // Turn Pin 2 off and make the light go off
        pinMode(pin2, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin2, 0); // Turn pin 2 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin2, 255); // Turn Pin 2 off and make the light go off
      //make light 3 blink once
        pinMode(pin3, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin3, 0); // Turn pin 3 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin3, 255); // Turn Pin 3 off and make the light go off
       //make light 4 blink twice
        pinMode(pin4, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin4, 0); // Turn pin 3 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin4, 255); // Turn Pin 3 off and make the light go off
        pinMode(pin4, OUTPUT); //Tell what kind of pin this is, We want OUTPUT
        analogWrite(pin4, 0); // Turn pin 3 on and make it light up
        delay(250); // wait for ¼ of a second ( 1000 is 1 second)
        analogWrite(pin4, 255); // Turn Pin 3 off and make the light go off
}

Send the code to the Arduino

Once we have written our code we need to verify it. In order to do that just click the check box in the top left, if there are no errors then click the little arrow next to the checkbox jnext to the arrow.  If everything looks right your lights should start blinking.

VIXEN LIGHTS

I will do another blog on vixen lights and provide refined code for doing that project, but you should understand the concepts in this post before moving on to that.  Until then if you are interested in pursuing this further you may want to download Vixen at http://vixenlights.com Cheers