My Halloween Light Show

Step 4: Software and Arduino Code

Picture of Software and Arduino Code
I used Vixen light control software to control the Arduino. The Arduino receives serial data from Vixen and uses a simple sketch to turn the relays on and off. I found the small sketch from the DIY Christmas Forum. Below is how I configured mine to five channels. 
#define NCH 5    // ALTER THIS: the sum of pwm and digital pins (number of channels from vixen)
#define NPWM 3 // ALTER THIS: the number of PWM pins you use
#define NDIG 2  // ALTER THIS: the number of DIGITAL pins you use...make sure NPWM+NDIG=NCH

int pins[NCH]={ 3,5,6, 2,4  }; //ALTER THIS FOR YOUR PHYSICAL PINS...pwm first then normal digital pins (set for UNO currently)
int data[NCH];   // to buffer incoming data

void setup()
  Serial.begin(38400);  // ALTER THIS: for various serial speeds on Vixen                   
  for (int i=0; i<NCH; i++) pinMode ( pins[i], OUTPUT ); 

void readSerialBuffer()  { for (int i=0; i<NCH; i++) data[i] =; }

void outputToPins()   {
  for (int i=0; i<NPWM; i++) analogWrite(pins[i], data[i]); // first pwm
  for (int i=NPWM; i<NCH; i++) // now digital outputs
         if (data[i]<127) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH);

void loop()

   if (Serial.available() >= NCH) {

I had to make sure the exact numbers of channels I was going to use in Vixen is setup in the sketch. I also had to make sure that the Baud rate matched on Vixen and the Arduino sketch.  I had Vixen output to the Arduino via the Generic Serial Output. Lastly I had to make sure the serial output matched the serial port on the Arduino. 
Remove these adsRemove these ads by Signing Up

Get More Out of Instructables

Already have an Account?


PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!