Every second and fourth Thursday of each month, I teach a class at my local makerspace, theClubhou.se that centers on STEM Education. Youth between the ages of 8 and 17 attend the class and we strive to teach them how to create fun projects that will hopefully inspire them to embark onto larger projects in the future.
During our November and December sessions this past year, we decided that we would teach the YoungMakers how to index strands of LED Christmas lights using nothing but an Arduino, a few Relays, and some LEDs as a proof of concept. After some research, we decided that the best route to take would be to use a program called Vixen Lights to simplify the sequencing process as much as possible. This was necessary because we only had a total of about six-hours spread out over 2 months to complete everything.
While I have documented the process we took for the curriculum we wrote around this project, I have yet to take the time to document it online. That is the purpose of this posting and by the end of this post I hope you will be able to use Vixen Lights to sequence some LEDs of your own. Below is a list of materials you will need to complete this tutorial, and almost everything can be bought from Newark.com. You can find all of the necessary code, and related files in my GitHub Repository for this project.
- Arduino Uno R3Arduino Uno R3 or an Arduino Mega 2560Arduino Mega 2560
- Arduino IDE
- Vixen Lights 2 Software
- 6 5mm Light Emitting Diodes (LEDs)6 5mm Light Emitting Diodes (LEDs)
- Jumper Wires
- BreadboardBreadboard
- 6 Ping Pong Balls with 4.5mm holes drilled out.
- Arduino Code
So to kick this off, we need to plug our LEDs into the breadboard. To simplify things, I like to plug the cathode of each LED into the GND rail of the breadboard, and place the anode into the five-position strip that is in line with the GND hole you plugged the cathode into. This will allow us to use a jumper wire to connect the anode to the PWM pins on the Arduino, and let us only utilize a single GND port on the Arduino as well.
Make sure to space the LEDs far enough apart to ensure that the ping pong balls will have enough room to fit. To get an idea of how much room you will need, six ping pong balls will take up the entire surface area of a standard breadboard. Once you have all of your LEDs in place, push the ping pong balls onto the 5mm LEDs.
With the LEDs now in position, we can move on to wiring everything up. Starting from the left, attach the first LED anode to digital pin 11 on the Arduino. Follow this up by attaching the next LED’s anode to digital pin 10. The third LED attaches to digital pin 9, with the fourth, fifth and sixth attaching to digital pins 6, 5, and 3 respectively.
Once everything is attached, we can move on to importing and adjusting the code for this project to our specific needs. Head over to my Github repository to download all of the files used in this tutorial, or you can copy and paste the code I have listed below.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Base Code (Needs Modifying)
/* The purpose of this code is to allow the Arduino to use the Generic serial output of vixen lights to control 5 channels of LEDs. Author: Matthew Strange Created: 14 October 2010 */ // Output int Chan1 = 5; // green LED, connected to digital pin 5 int Chan2 = 6; // white LED, connected to digital pin 6 int Chan3 = 9; // red LED, connected to digital pin 9 int Chan4 = 10; // green LED, connected to digital pin 10 int Chan5 = 11; // red LED, connected to digital pin 11 int i = 0; // Loop counter int incomingByte[8]; // array to store the 7 values from the serial port //setup the pins/ inputs & outputs void setup() { Serial.begin(9600); // set up Serial at 9600 bps pinMode(Chan1, OUTPUT); // sets the pins as output pinMode(Chan2, OUTPUT); pinMode(Chan3, OUTPUT); pinMode(Chan4, OUTPUT); pinMode(Chan5, OUTPUT); } void loop() { // 7 channels are coming in to the Arduino if (Serial.available() >= 5) { // read the oldest byte in the serial buffer: for (int i=0; i<8; i++) { // read each byte incomingByte[i] = Serial.read(); } analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins } }
With the code now open in the Arduino IDE, we need to make some adjustments to it to better match our setup. The first thing we need to do is adjust the output to follow the schematic on how we hooked up our LEDs on the breadboard. Edit the output to match the code below. What we are doing is telling the Arduino that channel 1 on the breadboard equals pin 11 and so on. This is important because Vixen will tell the Arduino later which channel to turn on during the sequence.
Adjust Output Pin Definitions
// Output int Chan1 = 11; // green LED, connected to digital pin 11 int Chan2 = 10; // white LED, connected to digital pin 10 int Chan3 = 9; // red LED, connected to digital pin 9 int Chan4 = 6; // green LED, connected to digital pin 6 int Chan5 = 5; // red LED, connected to digital pin 5 int Chan6 = 3; // red LED, connected to digital pin 3
Up next we need to adjust the set up to match the settings of our output. Again make the code in your sketch match the code below. Basically this tells the Arduino that all six channels defined above should be treated as outputs.
Adjust Setup Code
void setup() { Serial.begin(9600); // set up Serial at 9600 bps pinMode(Chan1, OUTPUT); // sets the pins as output pinMode(Chan2, OUTPUT); pinMode(Chan3, OUTPUT); pinMode(Chan4, OUTPUT); pinMode(Chan5, OUTPUT); pinMode(Chan6, OUTPUT); }
Vixen will utilize the serial communication port to tell our Arduino which channels to turn on and which to turn off and as such, we need to adjust the number of channels that are coming into the Arduino from the serial port. The original code specifies 5 channels, but since we are doing 6 channels, we need to adjust this to match. As we did before, make your code match the code I have pasted below.
Adjust Loop Code Part 1
void loop() { // 6 channels are coming in to the Arduino if (Serial.available() >= 6) { // read the oldest byte in the serial buffer: for (int i=0; i<7; i++) { // read each byte incomingByte[i] = Serial.read(); }
Now we are almost finished. We now need to add once analogWrite line to the last part of our code. Since the original code was written for 5 channels, we just need to add one more channel to the loop. The correct code is pasted below. Match your code to this.
Adjust Loop Code Part 2
analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins analogWrite(Chan6, incomingByte[5]); // Write current values to LED pins
With that complete, your code should now look like this. If you see any mistakes, please go back and correct them before continuing on with this tutorial.
Final Code
/* The purpose of this code is to allow the Arduino to use the generic serial output of vixen lights to control 5 channels of LEDs. Author: Matthew Strange Created: 14 October 2010 Adapted for 6-PWM-Channels by Charles Gantt on November 14th 2013. */ // Output int Chan1 = 11; // green LED, connected to digital pin 11 int Chan2 = 10; // white LED, connected to digital pin 10 int Chan3 = 9; // red LED, connected to digital pin 9 int Chan4 = 6; // green LED, connected to digital pin 6 int Chan5 = 5; // red LED, connected to digital pin 5 int Chan6 = 3; // red LED, connected to digital pin 3 int i = 0; // Loop counter int incomingByte[8]; // array to store the 7 values from the serial port //setup the pins/ inputs & outputs void setup() { Serial.begin(9600); // set up Serial at 9600 bps pinMode(Chan1, OUTPUT); // sets the pins as output pinMode(Chan2, OUTPUT); pinMode(Chan3, OUTPUT); pinMode(Chan4, OUTPUT); pinMode(Chan5, OUTPUT); pinMode(Chan6, OUTPUT); } void loop() { // 7 channels are coming in to the Arduino if (Serial.available() >= 6) { // read the oldest byte in the serial buffer: for (int i=0; i<7; i++) { // read each byte incomingByte[i] = Serial.read(); } analogWrite(Chan1, incomingByte[0]); // Write current values to LED pins analogWrite(Chan2, incomingByte[1]); // Write current values to LED pins analogWrite(Chan3, incomingByte[2]); // Write current values to LED pins analogWrite(Chan4, incomingByte[3]); // Write current values to LED pins analogWrite(Chan5, incomingByte[4]); // Write current values to LED pins analogWrite(Chan6, incomingByte[5]); // Write current values to LED pins } }
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Once the code is complete, its time to verify and upload the code to your Arduino. You can do this by simply clicking the “Play” button which is second from the left at the top of the Arduino window. If everything uploads correctly and no errors arose, it is time to move onto installing and configuring Vixen. Head over to VixenLights.com and grab the latest version of Vixen Lights 2.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Installing Vixen is fairly simple as it comes already unpacked into its directory. Make sure to place it somewhere you will remember to find it such as the desktop, or in your documents folder. To begin, launch Vixen and let’s set up a sequence. This is a very important step and very close attention should be paid and every step should be followed exactly for things to work properly. To start, click on the sequence tab and navigate to New Event Sequence > Vixen Standard Sequence.
Once you click on Vixen Standard Sequence the New Sequence Wizard will pop up and prompt you with a few configurable options. The first major thing you will need to set up is the Event Period. This value determines the period of time that each LED will stay lit. You can adjust this time down to 25-miliseconds and up as high as 1 second. For the purpose of this tutorial, we are going to keep it simple at 100-miliseconds, giving us 10 events per channel, per second.
Up next is where most of the configuration happens. To make things simple, we are going to create a profile that we can save and re-use in the future. Click Profile Manager and then click the Add icon that is highlighted in the image above.
Give the new profile a name and then click OK. At this point the Edit Profile screen will pop up, and you need to add six channels.
Once the six channels have been added click the Output Plugins button and you will see the Sequence Plugin Mapping configuration window pop up. Under Available Plugins, select Generic Serial, and click the Use button. Set the channels from 1 to 6, and click the Plugin Setup button.
Set the Com Port to 4 (also make sure your Arduino is set to Com Port 4) and set the Baud Rate to 9600 and then click OK.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
The Profile window will once again pop up, and you will need to select the profile you just created, and then click next. Since we are not adding any audio to this sequence, click next on the Audio and Event Patterns window.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
Finally we are presented with the Sequence Time configuration window. For this tutorial I have set it to 1-minute, but you can set this to any length you desire. Once you have your time set, click the Create It button and you will be prompted to save this sequence. Give it a name, and click Save.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
The PC will take a few moments to process and create your sequence, but when finished, a sequence configuration window will open and the sequence will be represented in a timeline that is sectioned into a grid-like pattern. Each one of these little blocks represents a single event period, and can be used to turn that channel on, off, or set a brightness value.
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
To keep things organized and easy to configure we need to assign a color to each channel. To do this we must right click on the channel list, and select Channel Properties.
When you click Channel Properties, a small window will pop up and will have several configurable options. For the purpose of this tutorial, we will just be changing each channels color. Set the first one to red, and then click the channel dropdown and select channel two.
Continue doing this until each channel has a unique color. I color coded the channels in my sequence to reflect the LED colors on my breadboard.
So let’s begin building the sequence. Click and highlight the event periods you wish to enable, and then click the solid square button in the control bar as seen highlighted in the image above. You can also enable the event periods by pressing the spacebar. Play around with the rest of the buttons on that row for some cool effects. I don’t want to dive too deep into building advanced sequences as that is an entire article on its own, and this tutorial is already long enough.
Now we can run the sequence. Make sure the Arduino is plugged in and is set to Com Port 4 in the Device Manager. If everything is correct, click the play button located at the top left of the Vixen Sequence. You should see the LEDs begin to light up and follow the sequence you just built. If you get a router / com port error, simply save your sequence, close Vixen and Arduino and reopen Vixen and load your sequence. Things should work now.
You can adapt this same setup to trigger relays to control 110v circuits that can activate LED Christmas Lights, Halloween Lighting, or pretty much anything that runs on mains voltage. Below is a video of a 4-christmas tree setup I built with my Makerspace that sequenced 32 channels of LED Christmas Lights.
Top Comments