# lighting control



## goneferal

Hi there. I'm a newbie to electrical circuitry, but I have done some simple projects with LEDs and 9v Batteries. I am making a bunch of LED spots and was wondering how difficult it would be to somehow control them so that they dim and different LEDs are light at different times. I'd like to do some sort of sequence where my cemetery is all dark and then the warm whites come on, then maybe some different colored spots to add drama. I'm thinking something like the x-mas lights to music, but on a much simpler scale. I've just started looking into arduinos and I have my first basic circuitry class this week.


----------



## JeffHaas

If you just want to turn them on and off by controlling them with an Arduino, then it's pretty simple. Dimming is more sophisticated. I suggest for your first project you group the colors of lights into different groups; start with them all off, turn on your whites, then your other colors when you want.

One of the other users here found a relay board for a great price:
http://www.futurlec.com/Opto_Relay_4.shtml

With one of these and an Arduino, you can control four lights, or four sets of lights. Have it use the relays to turn the power to the lights on and off. You could also have the Arduino play a music track as well, if you're willing to work out the timing and put it into the code.


----------



## goneferal

*I got one!*

Here's my geek post on my arduino uno I just got in the mail.

http://goneferalinid.blogspot.com/2011/03/its-here-possibilities-are-endless.html


----------



## thrilltainment

goneferal said:


> Hi there. I'm a newbie to electrical circuitry, but I have done some simple projects with LEDs and 9v Batteries. I am making a bunch of LED spots and was wondering how difficult it would be to somehow control them so that they dim and different LEDs are light at different times. I'd like to do some sort of sequence where my cemetery is all dark and then the warm whites come on, then maybe some different colored spots to add drama. I'm thinking something like the x-mas lights to music, but on a much simpler scale. I've just started looking into arduinos and I have my first basic circuitry class this week.


Arduinos are an awesome way to get things started. I use them extensively in my projects. What's great is that they have abstracted the C language so beginners don't have to deal with so many low level chip-specific details.

Using the "analogWrite(pin, value)" function will get your lights to dim. one thing to note is that you probably don't want the arduino to be driving the LEDs directly because you most likely won't have enough current for more than a few LEDs.... if you're driving 5 or more LEDs, I would recommend having the arduino control a transistor that feeds current through the LEDs instead.

I'll be providing a tutorial on LED circuits in a week or so. Stay tuned =)


----------



## goneferal

*Just an update on my previous post*

I shared this with the Arduino Forum and I figured I'd beat this dead horse some more. I am still determined to figure this project out.

I originally ordered a bunch of prewired 5mm ultra bright LEDs that had resistors already soldered in place to run off a 12V DC power source. I was going to make four sets each of a different color ie: 10 white spots, 10 green ones, 10 blue ones, and 10 violet ones. They were going to be set up for my Halloween display. Pretty easy stuff. But now I have and Arduino Uno and I really would like to somehow control each set of each color as channels via PWM. I can't figure out how to power the sets of LED spots with the output of the arduino. I need an external power source and don't want to scrap all the wired LED's I bought. What I would like is to control each channel either through a manual control, or better yet have then light according to sound frequencies to slowly fade in and out along with ambient music. I've already posted this before, but I wasn't clear on the parameters I imposed on myself by needing to use the 12 V LEDs. Here are the specs for the blue ones:

High Brightness 5mm LEDs - 8000mcd
12V DC
Presoldered Resistor
20 mA
20 cm Wire Length
High Intensity - Low Power 0.36W

I need to figure this out by October and I know I have bitten off more than I can chew, but I really would love to be able to figure this problem out. I'm not looking for one of those light-o-rama style light shows, just simple fading in and out to help make the ambiance for my display.

Thanks in advance for any help.
~GF


----------



## pshort

SInce you are using the pre-wired 12V LEDs, you will need to use transistors in between the Arduino and the LEDs. This is because 12V is too large a voltage for the Arduino to handle directly. You can either use individual transistors, or a ULN2803 IC.

If you are using individual transistors (such as the 2N3904 or 2N2222A) you will need to use resistors (perhaps 2.2K or 4.7K) to connect the output of the Arduino to the base pin of the transistors.

The ULN2803 has can handle eight LEDs, and the inputs to the ULN2803 can be directly connected to the Arduino pins.

The easiest way to do all of this is to search the internet for an appropriate shield for the Arduino and purchase it. For where you are at I think that this is better than spending time and effort trying to do everything yourself.


----------



## goneferal

*Sheild*

That's the thing, I can't seem to find a sheild that will do what I want it to do.


----------



## pshort

This one is over-kill...

http://www.solarbotics.com/products/50516/

Similarly over-kill (it might even be the same thing)

http://www.sparkfun.com/products/10305

Also, you could use one of the experimenter's kits, although they are a bit pricey.


----------



## pshort

Also, if you're not totally fixated on the Arduino, the PICAXE is another attractive alternative. Something like this would work I think:

http://www.sparkfun.com/products/8330

You also need to purchase the PICAXE chip and the ULN2803 separately, I think. AFAIK they are available from Sparkfun.

One of the benefits of the PICAXE is that there several very active members of this forum who are quite familiar with that approach.


----------



## goneferal

*Shield*

The funny thing is that I feel more comfortable doing it myself than using some "magic" shield that I don't understand how it works. At least with doing it myself, I am really learning the basics. Every time I look into shields, it makes the arduino more mystifying. It may be that I'm from a generation of women that were taught that women don't get math or electronics, anywhoo... I think setting up 4 outputs with a transistor for each will provide me with basically 4 independent channels that I can then figure out how to control by some sort of input, be it manual or audio. I'll have to find a sketch for that.

As far as the arduino, its what I have and I don't want to buy another thing to figure out for this project. I have set the challenge for myself.

I LOVE all the help I'm getting. If I figure this out, I'll post a huge how to.


----------



## goneferal

*Arduino Forum*

here's the link to the forum discussion:

http://arduino.cc/forum/index.php/topic,65767.0.html


----------



## Ryan Wern

At the risk of sounding like a broken record, I would recomend using Light-O-Rama. These controllers work for everything, from props to lights. Each controller box has 16 channels, and you can run just about as many controllers as you like with Wi-Fi. You can make your lights do almost anything and synch it all with music or sound effects. I use mine on Halloween, Christmas, and pretty much any other holiday where I can get away with using lights and making them do stuff. The downside to these things are the price. 1 box and the software will set you back about $450.00 plus shipping, but trust me, if you can afford it they are WELL worth the price.


----------



## corey872

Probably overkill for what you want, but I'm starting in on a 'smart string' system from DIYlightanimation.com.

In essence, you'd program the light pattern, fades, flickers, strobes, color switches, brightness, etc in free software such as Vixen, the computer/software sends those commands through USB port to the dongle where they are converted to 'pixelnet' commands. Those commands are then relayed to a central hub where 12V power is injected, then out to LED pixel nodes. Just like a pixel on your TV, the nodes have red, green, and blue lights - so they can basically be any color you want, just by varying the amount of red/green/blue.

So you could program a whole sequence where the cemetery comes on warm white, maybe turns yellow orange and flickers like fire, fades out, then turns red, blue, orange, green, purple, then various tombstones light up at different intervals, finally ending with blue-white 'strobe' - or just about any other sequence, color and effect you can dream up. Take the lights down, program in red, green, blue, yellow and they are then your christmas or holiday lights.

They -and several other places have DMX control type lights which are a bit more simple to run, but still offer quite a bit of flexibility.


----------



## Ryan Wern

To piggy-back onto corey872's post, the Light-O-Rama WILL NOT let you switch colors the way the system he described will. You would have to use multiple channels with different colored LED's to do that. His system sounds cool, especially if you can make 1 LED switch to 3 or 4 different colors


----------



## pshort

Meanwhile, back at the ranch...

Basically, I agree with what KE7GKP said in the first reply to your question on that other forum. One thing that I would do a little bit different, though, is to limit the current through each 2N2222 to some smaller value, perhaps 100 mA each. The reason that I say this is that the gain of the transistor goes down at the higher current levels, which means that you need a smaller base resistor than what he described, which in turn increases the output current that the Arduino must provide. While I'm not sure of the specs of that Arduino chip, I think that it would be a good idea to keep the current from each output below 5 mA or so (unless you know a better number).


----------



## corey872

Ryan Wern said:


> ... His system sounds cool, especially if you can make 1 LED switch to 3 or 4 different colors


LOL - Technically 16,581,375 colors - each R, G, or B LED in the pixel can be programmed to levels from 0 to 255* - so they mix to just about any color you can dream up, but yeah there are some benefits! Though for Halloween I'd mainly stick to the saturated colors...red, green, blue, yellow, orange, purple.

Somehow a corpse or tombstone lit with a lovely shade of pastel pink with an apricot fringe just doesn't look right.


----------



## fritz42_male

The ideal solution would be to head down the dmx route but that might be a bit pricey.

Sparkfun do individual mosfet boards that you could use with an arduino or picaxe instead of a shield or specific board.

http://www.sparkfun.com/products/10256

The high output Picaxe board is this one:

http://www.techsupplies.co.uk/epage...ath=/Shops/Store.TechSupplies/Products/CHI035

The nice thingabout this is that each channel could be controlled by a separate program as the 18m2 chip for this board will run 4 programs in parallel. You could for example have 2 set sequences and 2 other sequences that change with a pir trigger event (for example)


----------



## goneferal

Those look a bit over my head.


----------



## pshort

We've certainly managed to make things complicated here.


----------



## pshort

Not to change the topic too much, but what are you planning on using for powering the lights?


----------



## goneferal

*power*

A 12v wall wart.


----------



## pshort

OK, here is my thought of the moment.

As I understand your idea, you have four sets of LED lights that you want to control. You want to turn them on and off, bright and dim, in some manner, hopefully coordinated with some sounds/music and with various props. Right?

There have been a lot of suggestions here, mostly using some sort of computer or microprocessor controller. You made reference to an Arduino, I mentioned a PICAXE, and other people have suggested LOR or DMX and other solutions. I think that this approach is complete over-kill for controlling four sets of LEDs.

My suggestion is an (almost completely) analog solution. This would use an audio recording device of some sort, either an MP3 player or a PC (or MAC) playing tones at various frequencies. There would be an external analog device that could be built that would decode these tones and in turn control the LEDs. This would be very similar to the way in which the phone company decodes the phone numbers that you would enter in an old touch-tone telephone. One channel of a stereo player could be used for these control tones and the other channel would be the sound-effects for your display.

The simplest way to do this would result in simple on-off control of the LEDs. Each LED would be assigned a tone frequency, and would go on or off if the tone is present on the audio output. This decoding could be very simply with an LM567 tone-decoder chip with an extra resistor and capacitor (or two). So, if we assign 1000 Hz as the frequency for the white LEDs, the output of a 1000-hz tone decoder would turn the LED on if that tone is detected. For four LED channels you would have four such decoders, each programmed for a different audio frequency.

To create those tones and put them on the mp3 player you would use any one of a number of sound editing programs (some free) on the PC. One example is a program called audacity (which I have not used, btw).

This is a significantly different approach from all of the prior postings on this thread. The main advantage over the Arduino (and PICAXE) approach is that the LED activity can be tightly synchronized with the sound (since they are presumably just separate channels on the same audio recording). the advantage over the other approaches over the LOR and DMX approaches is that it should be quite a bit cheaper and less complicated.

As far as dimming goes, I have ideas on how to handle that in a similar fashion, but I think what I've written above is enough for now.


----------



## goneferal

*This might do it*

I think this might meet my needs. I just have to figure out how to make one and use it.

http://railstars.com/hardware/led-intruder/


----------



## goneferal

It looks like the local science, electronic, etc... supply place is willing to help me out! I'm gonna get 1st hand help setting up my project! Woot!


----------



## fritz42_male

Cool. However, if you want some really nice and controllable lighting, go over to http://www.doityourselfchristmas.com/

They are a bunch of hobbyists that have some very nice setups for control of lighting. Custom designed Renard and Vixen controllers.

Some of the effects are here:


----------



## pshort

goneferal said:


> I think this might meet my needs. I just have to figure out how to make one and use it.
> 
> http://railstars.com/hardware/led-intruder/


That is going to be hard to make, because the spacing between the pins of the TLC5941 on is very small. You should either try to buy one pre-assembled, or use a Radio-Shack prototype board (like this and a larger, through-hole version of the main chip from that LED board.

And if you are not experienced with soldering or are unsure about soldering such small parts, then use a solderless breadboard instead.


----------



## pshort

Also, bear in mind that time will pass quickly. Halloween is less than four months away and all of this can be very time-consuming. Try to keep the electronics as simple as possible and concentrate on the presentation aspects of your display.


----------



## pshort

Oops, forgot to mention...

If you go to the site that Fritz mentions, you will find mention of a Grinch board. I'll have to double-check when I am more awake, but I think that you can solder up the Grinch board with the TLC5941N part that I mentioned above onto that board and connect it to your Arduino board, and use it just like that LED intruder board.

Edit: Oops, I'm wrong...I was looking at the pinout for the SOIC version of that part, not the PDIP version (which is what you would need).


----------



## goneferal

I already have the simple backup plan of just having the led lights on the whole time powered by a wall wart. I will also be having professional help with assembly, and I must say, I can solder fairly well, so I feel I'm in good hands. Thanks for all your help!


----------



## pshort

Which approach are you taking, then? Some variation of that LED controller that you linked to above?


----------



## goneferal

*Crap*

I'm back at the drawing board. I've been trying to get Vixen to work with my Arduino, but Windows 7 is giving me problems. I'll try vixen 2.5 this weekend. I got 9 LEDs on pin 9 of the Arduino dimming up and down without external power or transistors but I think that since they were parallel, they didn't drain the power supply. I'm looking at powering about 40 LED's at least, and maybe more if I can use some of the digital I/O pins as well. I just need to make sure I don't blow anything up. If I can get Vixen and my Arduino to talk, I'd be happy with that. I'm just crappy with breadboarding since I'm used to tinkering with direct connections like wire to wire. I am really frustrated.

Oh, and I found that you can safely power the Arduino with 7v-about 24V (don't take my word on the upper end though.

So I guess I hope to maybe use a transistor for each channel of parallel LED's. One or two white, one blue, one purple, etc.


----------



## ctmal

Are you receiving an error in Vixen?


----------



## HomeyDaClown

I should have read this earlier on....

I would use the Arduino Softpwm library http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268806013

It will allow you to use just about any/all Arduino pins easily for PWM led control. Then just add a transistor to each pin to boost the current for your spots. 
r
I used the TLC5940s but only when I needed more than a dozen high current outputs.
You then have to use the TLC5940 library as well.


----------



## goneferal

*Thanks*

Thanks Homey, I'll look into it tonight.


----------



## HomeyDaClown

I'm glad you didn't fry the Arduino (they are hard to kill) by running all those leds on one pin. Most Arduinos will only sink about 40 milliamps per pin.

Using this method will let you drive around 20 leds off each Arduino pin through a ULN2003 driver chip. The ULN2003 is cheap and has 7 IN and OUTs and can drive anywhere from 5 to 12 volts on the output side with up to 500 milliamps per output. It is basically an array of darlington transistors made for this sort of thing.

The SoftPWM library will let you use up to 20 pins for PWM so that should get you going. Vixen is pretty easy to talk to as well. You can get the Arduino to mimic just about any of the Vixen plugins over USB.


----------



## goneferal

*Wow!*

Thanks so much for all the help! I really appreciate it. I might even put a tutorial together for other newbies like me if folks are interested.

Again, thank you very much.

Oh, I'm not sure how the channels work through the ULN2003. I mean how do the outputs of the transistor work. It looks like you are connected to arduino pins 2,3, and 4 to the ULN2003. Does my question make sense? Is it ULN2003input 123 each a separate channel through the driver with the three outputs then being 14, 15, 16? So would I go from Arduino 5678 to the four remaining inputs on the ULN2003 and the outputs are 9 and 10 as one channel output, 11, 12, and 13? I hope this doesn't look like gibberish.


----------



## pshort

You would leave pin 9 unconnected, since you are just driving LEDs (you would make use of pin 9 if you were trying to control an electromechanical relay or drive some sort of coil).

In any case, pin 13 of the ULN is the output corresponding to pin 4, pin 12 corresponds to pin 5, and so forth for output pins 11 and 10.

Also, when homey drew an LED in the schematic, he actually meant an LED with series limit resistor (like what you have), not just a plain-jane LED.


----------



## goneferal

Got it, you guys are the bomb! This is really making sense.


----------



## HomeyDaClown

Glad it helps...

Once in a while I pull something usefull out of my brain.

Yes, the drawing was to get you started, only showing three channels from the Arduino to the Leds. The Leds in the diagram were for reference only. The leds you choose and the voltage you supply to that side will determine what if any resistor you need on each output channel.

I'd use digital pins 2345678 with the SoftPWM on the Arduino (pins 0 and 1 are for serial tx/rx and they'll get used (even if not connected) if you are talking to Vixen. Besides there are still 12 other free pins that could be used for PWM.

As Pshort said, leave pin 9 out of the picture. Ground pin 8, then all the other pin pairs (7 channels) go straight through in to out from left to right.










The ULNs can drive quite a few leds but don't get too greedy. spread them out over the channels evenly to keep the simultaneous current draw under the maximum for the chip. Or.....the magic smoke may come out!​


----------



## goneferal

*Vixen Problem*

I am using Generic Serial Output and the shimmer and fade in-out stuff work fine, but why are my channels seemingly randomly assigned and sometimes don't work. Is there a better output to use? I feel like I'm so close.


----------



## goneferal

*Jeez! Soory for so many posts!*

I'm wondering if it's because the original sketch was set up for 7 channels, and I only put in 5 in Vixen.


----------



## HomeyDaClown

I see.....you musbe using this guy's code:

http://doityourselfchristmas.com/forums/showthread.php?12757-Vixen-Generic-Serial-Output-controls-the-Arduino!&p=129693#post129693

Just add a few more lines if want to use all 7 channels, should be easy.


----------



## goneferal

*Sketch*

Yeah, that's the code I'm using. It has 5 PWM channel outputs and I had 5 channels in my Vixen sequence. I found that if I make it 7 to account for the actual channels in the Arduino Sketch, it works great. Now I have to figure out how to make more channels work with the softPWM library. For the first time in the year since I envisioned this project, it is working!

Talk about not giving up even though I found at least a hundred ways how not to do it.


----------



## HomeyDaClown

Without the SoftPWM (or some serious extra coding) or an Arduino Mega board, you will only get 5 PWM outs period. A Mega would really be overkill for this simple task though.

SoftPWM makes it very simple. The 7 byte values (hex 0 - 255) coming from Vixen tell SoftPWM what PWM level to set the pins.

This is another example of how open source hardware and software comes together for a simple solution.

Ok, here you go:

/*
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
*/

*/Code revised by HomeyDaClown to integrate B. Hagman's SoftPWM library so 7 PWM (or more) outputs are available for use. SoftPWM library files need to be installed for this to work.
Modified: 18 July 2011
*/

#include <SoftPWM.h>

void setup()
{
// Initialize Serial
Serial.begin(9600); // set up Serial at 9600 bps
// Initialize SoftPWM
SoftPWMBegin();

// Create and set pins for PWM use and turn them off
SoftPWMSet(2, 0);
SoftPWMSet(3, 0);
SoftPWMSet(4, 0);
SoftPWMSet(5, 0);
SoftPWMSet(6, 0);
SoftPWMSet(7, 0);
SoftPWMSet(8, 0);
}

// Initialize Loop counter
int i = 0; 
// Set array to store the 7 values from the serial port 
int incomingByte[7];

void loop()
{ // 7 channels are coming in to the Arduino
if (Serial.available() >= 7) {
// read the oldest byte in the serial buffer:
for (int i=0; i<8; i++) {
// read each byte
incomingByte_ = Serial.read();
}
SoftPWMSet(2, incomingByte[0]); // Write current values to LED pins
SoftPWMSet(3, incomingByte[1]); // Write current values to LED pins
SoftPWMSet(4, incomingByte[2]); // Write current values to LED pins
SoftPWMSet(5, incomingByte[3]); // Write current values to LED pins
SoftPWMSet(6, incomingByte[4]); // Write current values to LED pins
SoftPWMSet(7, incomingByte[5]); // Write current values to LED pins
SoftPWMSet(8, incomingByte[6]); // Write current values to LED pins
}

Ok, so now I'll have to find another prop to use this Vixen interface for_


----------



## goneferal

*Sweet!*

I just did this to his sketch: See after the rest of my post. I'll integrate yours to it and have at least 12 PWM Channels going! I'm on the upswing of the learning curve! I owe you a cold one Homey!

/*
The purpose of this code is to allow the Arduino to use the 
generic serial output of vixen lights to control 12 channels of LEDs. 
Author: Matthew Strange Changed by Jeanne Pepalis
Originally Created: 14 October 2010, Revised 7/18/11

*/

// Output
int Chan1 = 2; // LED, connected to digital pin 2
int Chan2 = 3; // LED, connected to digital pin 3
int Chan3 = 4; // LED, connected to digital pin 4
int Chan4 = 5; // LED, connected to digital pin 5
int Chan5 = 6; // LED, connected to digital pin 6
int Chan6 = 7; // LED, connected to digital pin 7
int Chan7 = 8; // LED, connected to digital pin 8
int Chan8 = 9; // LED, connected to digital pin 9
int Chan9 = 10; // LED, connected to digital pin 10
int Chan10 = 11; // LED, connected to digital pin 11
int Chan11 = 12; //LED, connected to digital pin 12
int Chan12 = 13; // LED, connected to digital pin 13

int i = 0; // Loop counter
int incomingByte[12]; // array to store the 12 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);
pinMode(Chan7, OUTPUT); 
pinMode(Chan8, OUTPUT);
pinMode(Chan9, OUTPUT);
pinMode(Chan10, OUTPUT);
pinMode(Chan11, OUTPUT);
pinMode(Chan12, OUTPUT);
}

void loop()
{ // 14 channels are coming in to the Arduino
if (Serial.available() >= 14) {
// read the oldest byte in the serial buffer:
for (int i=0; i<14; i++) {
// read each byte
incomingByte_ = 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
analogWrite(Chan7, incomingByte[6]); // Write current values to LED pins
analogWrite(Chan8, incomingByte[7]); // Write current values to LED pins
analogWrite(Chan9, incomingByte[8]); // Write current values to LED pins
analogWrite(Chan10, incomingByte[9]); // Write current values to LED pins
analogWrite(Chan11, incomingByte[10]); // Write current values to LED pins
analogWrite(Chan12, incomingByte[11]); // Write current values to LED pins
}}_


----------



## HomeyDaClown

Just make sure your count of Vixen channels matches the expected incoming byte count in the sketch.

SoftPWM will shorten your code and I think makes it cleaner.
The other advantage to SoftPWM is that it only uses one timer across all the pins, other native PWM pins share several timers and may interfere with anything else you may add.


----------



## goneferal

*Thanks*

Thanks again Homey. I just about got my face ripped off over at arduino forum for writing crappy code. What a jerk. I said I'm brand new to this. I've gotten way better help here and at diychristmas than from the snobs at arduino forum. I hope that guy cringes all day at my horrible code (that actually works!).


----------



## HomeyDaClown

goneferal said:


> Thanks again Homey. I just about got my face ripped off over at arduino forum for writing crappy code. What a jerk. I said I'm brand new to this. I've gotten way better help here and at diychristmas than from the snobs at arduino forum. I hope that guy cringes all day at my horrible code (that actually works!).


Making code that works is all that matters, making it pretty does nothing at all is what I always tell em. The processor doesn't care one bit how pretty your code is.


----------



## fritz42_male

Ahhh - you just came across a Code Snob - one of the most childish people you will be unfortunate to meet. Ignore them.

I'm totally impressed with your learning curve. I can't believe you've got so far so quickly. 

If anybody criticises you for plagiarism by using other people's code and code snippets - ignore them. EVERY programmer I've ever come across (& I used to be a director in a software company) plagiarises like crazy.

Extremely nicely done!

(don't forget to post the video of the night though)


----------



## HomeyDaClown

Yep,

That guy is on the wrong side of the fence and should be sternly reminded that the whole idea behind the Arduino and it's huge web following is "Open Source" or shared code. Why should anyone have to re-invent the wheel, just grab it and start driving, you can clean it up and put some paint on it later (like you'll ever find time to do that)


----------



## goneferal

*I get this!*



> /*
> sftPWM*with*
> */
> 
> #include*<SoftPWM.h>
> 
> void *setup*()
> {
> //*Initialize*Serial
> *Serial*.begin(9600); // set up Serial at 9600 bps
> //*Initialize*SoftPWM
> SoftPWMBegin();
> 
> //*Create*and*set*pins*for*PWM*use*and*turn*them*off
> SoftPWMSet(2, 0);
> SoftPWMSet(3, 0);
> SoftPWMSet(4, 0);
> SoftPWMSet(5, 0);
> SoftPWMSet(6, 0);
> SoftPWMSet(7, 0);
> SoftPWMSet(8, 0);
> SoftPWMSet(9, 0);
> SoftPWMSet(10, 0);
> SoftPWMSet(11, 0);
> SoftPWMSet(12, 0);
> SoftPWMSet(13, 0);
> SoftPWMSet(A0, 0);
> SoftPWMSet(A1, 0);
> SoftPWMSet(A2, 0);
> SoftPWMSet(A3, 0);
> SoftPWMSet(A4, 0);
> SoftPWMSet(A5, 0);
> }
> 
> //*Initialize*Loop*counter
> int i = 0;
> //*Set*array*to*store*the*18*values*from*the*serial*port*
> int incomingByte[18];
> 
> void *loop*()
> {*// 18 channels are coming in to the Arduino
> if (*Serial*.available() >= 18) {
> //*read*the*oldest*byte*in*the*serial*buffer:
> for (int i=0; i<18; i++) {
> //*read*each*byte
> incomingByte_*=**Serial*.read();
> }
> SoftPWMSet(2, incomingByte[0]); // Write current values to LED pins
> SoftPWMSet(3, incomingByte[1]); // Write current values to LED pins
> SoftPWMSet(4, incomingByte[2]); // Write current values to LED pins
> SoftPWMSet(5, incomingByte[3]); // Write current values to LED pins
> SoftPWMSet(6, incomingByte[4]); // Write current values to LED pins
> SoftPWMSet(7, incomingByte[5]); // Write current values to LED pins
> SoftPWMSet(8, incomingByte[6]); // Write current values to LED pins
> SoftPWMSet(9, incomingByte[7]); // Write current values to LED pins
> SoftPWMSet(10, incomingByte[8]); // Write current values to LED pins
> SoftPWMSet(11, incomingByte[9]); // Write current values to LED pins
> SoftPWMSet(12, incomingByte[10]); // Write current values to LED pins
> SoftPWMSet(13, incomingByte[11]); // Write current values to LED pins
> SoftPWMSet(A0, incomingByte[12]); // Write current values to LED pins
> SoftPWMSet(A1, incomingByte[13]); // Write current values to LED pins
> SoftPWMSet(A2, incomingByte[14]); // Write current values to LED pins
> SoftPWMSet(A3, incomingByte[15]); // Write current values to LED pins
> SoftPWMSet(A4, incomingByte[16]); // Write current values to LED pins
> SoftPWMSet(A5, incomingByte[17]); // Write current values to LED pins
> }}
> 
> _


_

I can't get channels 17 and 18 to work, but that might be a vixen thing. Woot! Look at me learnin'_


----------



## Gorak

You're getting close! 

One problem that pops out is you set your array to 19 values. Remember they are zero indexed. After that you can tackle the for loop!


----------



## HomeyDaClown

The array declaration should not cause a problem. The analog pins for 17 and 18 shoould not be an issue either (no timer conflicts). Looks like that Vixen flashy light thingy program is where it's at.:googly:


----------



## Gorak

HomeyDaClown said:


> The array declaration should not cause a problem. The analog pins for 17 and 18 shoould not be an issue either (no timer conflicts). Looks like that Vixen flashy light thingy program is where it's at.:googly:


True! I have not played with Arduino in awhile. But I still don't think it is Vixen.

Take a closer look at the for-loop  You will easily see the error. Or a error at least. lol


----------



## Gorak

WoW I'm 0-2 now! 

I'm thinking of how I setup my arduino and I included some beat tracks. The For-loop looks sound in your code. I will have to setup my arduino in the next few days and make this work.


----------



## goneferal

What should the number be in the for loop? I tried 19 and 20, but nothing changed.


----------



## Gorak

goneferal said:


> What should the number be in the for loop? I tried 19 and 20, but nothing changed.


No the For-Loop is correct. I was thinking about YOUR problem only using MY setup in my head which is not the same as yours. I was using extra channels at the end. The Loop is correct. I will have to setup my arduino and play with this code for a bit because everything looks fine.


----------



## pshort

What are the problem symptoms at the momentt?


----------



## goneferal

Trying to get 18 channels. I can only get 16 to work. A4 and A5 output isn't working, or Vixen can't do more than 16 channels.


----------



## pshort

Just for isolating the problem, try writing incomingByte[0] to A4 or A5, since it seems that you think that the other channels are working. If you see the light on A4 duplicating channel 0, that tells you that channel A4 is probably working, and the problem is either in your program or in data coming from Vixen.


----------



## goneferal

Will do, Thx!


----------



## HomeyDaClown

How's he gonna learn if we debug for him?
Structured code? Utoh

Debugging is the best part!

void loop() { 
if (Serial.available() >= 18) { // Data there?
for (int i=0; i<18; i++) {
incomingByte_ = Serial.read(); // Stuff it in the array
}
}
SoftPWMSet(2, incomingByte[0]); // Write current values to LED pins
SoftPWMSet(3, incomingByte[1]); // Write current values to LED pins
SoftPWMSet(4, incomingByte[2]); // Write current values to LED pins
SoftPWMSet(5, incomingByte[3]); // Write current values to LED pins
SoftPWMSet(6, incomingByte[4]); // Write current values to LED pins
SoftPWMSet(7, incomingByte[5]); // Write current values to LED pins
SoftPWMSet(8, incomingByte[6]); // Write current values to LED pins
and so on......
}

Being sarcastic.

Have you tried expanding the number of channels to like 32? Looks like the design of Generic Serial
is pretty basic and should easily handle more than 16 channels. I would use the Vixen Data Logger plugin and view the outputs from there to see if you are really getting anything out._


----------



## pshort

Debugging is as much a learned skill as coding, and maybe even more important at this stage.


----------



## goneferal

Meon arduino forum:


----------



## Gorak

Awesome video!

I've gotten my arduino duemilanove to control 64 led channels. I haven't used the softpwm library though. Is it able to change the I/O port direction? Looking at this page it seems those 2 problem channels are inputs and can be used for TWI communication. Then again maybe they can if you are using other inputs for outputs.


----------



## HomeyDaClown

Nice vid. So what was the problem before? Your final code?


64 outs on a standard Arduino would have to be either charlieplexing or some external shift registers. SoftPWM would not work on either charlieplexed outputs or shift registers. There is a good library and docs using the TLC4950 to do this though. You'd need 4, each one would get you 16 channels.....


----------



## goneferal

The video was a bit of a joke.


----------



## Gorak

I was holding back asking for more cowbell


----------



## HomeyDaClown

Were they supposed to blink and change color? 

Leds always look better after a few beers for some strange reason.


----------



## goneferal

I thought I'd make the lamest use of 16 channels by using each one on the cowbell in the song. It was a lame joke. I actually have a sequence to Concrete Blonde's Bloodletting that will be finished this week. It is looking pretty cool so far. I just kinda wish I had more channels, but 16 is pretty good for my first year on a budget of under $75 dollars for the whole lighting setup and animation.


----------



## goneferal

*Ta Da!*


----------



## niblique71

Wow that was awesome!!! As a musician, I could really tell that the different aspects of the music were triggered rather accurately!! I'm going to have to go back and get caught up on this thread!! How would you feel about bringing that to NJ?? LOLOL


----------



## goneferal

You wanna pay for the ticket? I actually have a background in music with some time doing lighting. Mostly mixing and such in the days when midi just came out and all boards were not automated and no computers!
That was a huge compliment. Thanks!


----------



## fritz42_male

I am impressed. I think you should do an Instructable on this so others can duplicate it. I'd buy an arduino in to do this!


----------



## goneferal

*How to*

I plan on doing a how to once I get it all together. It probably won't be until after this season, being as busy as I am, but there is no way that I can't share this info.


----------



## RoxyBlue

I watched this one the way Niblique would - "drum there, cymbal over there, bass guitar on those two, and singer in the middle"

The technical aspects of this thread are over my head, but the final product is not. You and your fellow advisors here put a lot of time and thought into this - beautifully done!


----------



## HomeyDaClown

Well, It's about time!!! ....just kidding

Actually I've got the code running on 32 channels and it's easily upward scaleable but you'll reach a point where the Generic Serial plugin can't pass data fast enough. Good thing I have another way to do handle that

Time to fire up Eagle and make another Arduino Shield, How about the Arduino Vixen Shield?



goneferal said:


> I plan on doing a how to once I get it all together. It probably won't be until after this season, being as busy as I am, but there is no way that I can't share this info.


----------



## goneferal

RoxyBlue said:


> I watched this one the way Niblique would - "drum there, cymbal over there, bass guitar on those two, and singer in the middle"
> 
> The technical aspects of this thread are over my head, but the final product is not. You and your fellow advisors here put a lot of time and thought into this - beautifully done!


Roxy, I have a lot of people to thank for getting me where I'm at! Thanks to Haunt Forum getting this project off and running.


----------



## Hellspawn

Thats really fantastic work, kuddos to everyone.

Makes me feel like taking the plunge myself, I dont need anything as crazy as what you did there, I just need something to turn my lighting/props and ambient and prop sounds on/off at a specific time (on at 7:00pm, off at 10:00pm) so maybe I can pull that off with arduino


----------



## goneferal

OK, the project is still working. I went to the local surplus supply store and the amazing proprietor spent an hour on how I'm going to wire the spotlight up and make the whole thing work. I'm going to need a lot of speaker cable. All in all, the project box won't be near as big as I thought it would be. I will try to do my best tutorial I can when the season is over. With Vixen and Arduino, the project can be expandable to a really decent number of light channels and even some prop controllers.


----------



## Dead Things

Absolutley freakin brilliant! And I agree with Niblique and Roxy, your synching was impeccable (btw I always thought Concrete Blonde was way underated). I too eagerly await your tutorial. I haven't got Picaxe figured out yet so why not throw Arduino into the mix 
Really fantastic job!


----------



## goneferal

Aw, darn, Dead Things. Thanks! I just hope I don't disappoint.


----------



## goneferal

HomeyDaClown said:


> Nice vid. So what was the problem before? Your final code?
> 
> 64 outs on a standard Arduino would have to be either charlieplexing or some external shift registers. SoftPWM would not work on either charlieplexed outputs or shift registers. There is a good library and docs using the TLC4950 to do this though. You'd need 4, each one would get you 16 channels.....


Actually I haven't figured it out yet. I am happy with 16 channels for this year. I still plan to figure out what didn't work.


----------



## beelce

WOW....what a great thread....makes me want to try it out myself


----------



## HomeyDaClown

Now you've done it.....

You'll have to get that library cranking some bits to the TLCs and see how many channels you can make light out of. I did the same thing about a year back with Vixen and a bunch of super bright RGB leds only using the parallel port driver to run three sets of shift registers instead of serial.


----------



## goneferal

Argh! What am I doing wrong? I got my ULN2003s and tried to set it up on the breadboard with a 12V power source. I know me sKetch and Vixen are OK. The LED will go on and PWM works, but the LED won't turn all the way off. I had 7 channels going and they do the sequences fine, but the LEDs stay on at about 25% and won't turn all the way off.


----------



## fritz42_male

Have you got pulldown resistors on the inputs to the uln? Try a 10k resistor to ground and see if that does it.


----------



## pshort

What were you using before?


----------



## pshort

Also, what do you have connected to pin 9 of the ULN? Hopefully you've either left it open or connected it to +12V.


----------



## goneferal

Sorry, here is a link to the photo:
https://picasaweb.google.com/117276536531095808292/20110930?authkey=Gv1sRgCLqXoLTw6tTmRQ

I was susing regular LED with resistors right off the arduino. The point of the ULN2003 is to drive multiple 12V LEDs.


----------



## pshort

My eyes aren't as good as they were when I was younger...but is pin 1 of that IC in the up or the down position in the picture? It appears that the notch on the IC is pointing down, but I can't be sure...


----------



## goneferal

pshort said:


> My eyes aren't as good as they were when I was younger...but is pin 1 of that IC in the up or the down position in the picture? It appears that the notch on the IC is pointing down, but I can't be sure...


I don't know what that means, but I popped the chip out and flipped it over and it works better, but something is still very wrong.


----------



## pshort

Could you post another picture as it is now (after flipping the chip), zoomed in on the breadboard more than the last time around?


----------



## goneferal

OK I pulled everything out and set it up the old way with resistors and lEDs only, and guess what, my sketch is bad. I have no idea what happened, but I have been sequencing without the LED output and some where between 2 months ago and now, I seem to have messed up the sketch somehow. Now I have to figure out what went wrong with that before I move on. OK I got the sketch back to running. Now lets see if I can get this thing going. I have plans this evening, so I might not have results until tomorrow. I swear I'm going to cry if I don't get this to work! And I don't cry very often.


----------



## Rod Zombie

The ULN2003 is just a transistor array. You still new a current limiting resistor in series with the LED unless you have enough LED's to drop the entire 12 volts. Most LEDs drop about 1.2 volts so 10 in series would drop the whole 12 volts. Without the resistor you will fry the LED and possibly the ULN driver. The dot on the part indicates pin 1. That side of the part should go to your processor. Pin 9 should be tied to the + side of you power supply.


----------



## pshort

Pin 9 should be either left open or tied to the power supply for your LEDs (not the power supply for the Arduino).


----------



## Rod Zombie

After looking at you picture closer it does appear you had the part installed backwards but can't be 100% positive. There should be a notch or dot at the top of the part. with the dot or notch at the top pin one is to the left side of the part.


----------



## goneferal

Ha Ha! I got it. I had the chip in upside down duh! AND the sketch was corrupt. Who knows if I had been using some other sketch that I forgot about and left it on the Arduino. Ahh, that sweet sense of satisfaction is worth it I guess.


----------



## pshort

Does that mean that it's working for you now?


----------



## pshort

By the way, I think that the LEDs there have built-in resistors for 12v, at least there was previous talk about that.


----------



## goneferal

Yes, it is working. Yeah they are pre-wired 12V LEDs. 
Thanks for the help!


----------



## Indyandy

Been following this thread, great job everyone! I hope to see a tut after the season. I am going to start to learn more about controllers and programs this year. This is one to get my feet wet. Thanks again.


----------



## goneferal

There will be a tut after the season. Please be patient. I am right now sitting happily with 16 red LEDs running on 12 volts, that will soon turn into 16 separate dim-able channels that work with Vixen. 

Ahh, I'm basking in the sweet sweet glow of LED goodness. 

Don't even bother bringing up RGBs! I've accomplished enough for one year (with lots of help).

nighty night,


----------



## HammieTime

I hope I won't be strung up for bumping I thread that is nearly 2 years old. Any ways here I go.

I am using a Arduino Uno with Vixen 2.1.1 with the code using the SoftPWM library. In Vixen I am using the Generic Serial plug in. I start the sequence and I do have LEDs light up, but not in the way I want. It doesn't match the sequence. 

Has anyone else had this issue?

Thank You in Advance


----------



## goneferal

My best bet is a problem with your code. I was surprised to see this thread come back up. Thank you for reminding me how much I've learned. My guess is that some of the numbers in your sketch are wrong, your library also has an arbitrary limit on it as well that may need to be changed. Maybe you can share your setup and sketch with us for some help. I know it is really frustrated, but once you get the blinky lights going with Vixen, the sense of accomplishment is amazing.


----------



## HammieTime

Thanks for getting back to me feral, I do appreciate it.



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
*/

/*Code revised by HomeyDaClown to integrate B. Hagman's SoftPWM library so 7 PWM (or more) outputs are available for use. SoftPWM library files need to be installed for this to work.
Modified: 18 July 2011
*/

/* Code revised by HammieTime to test 5 LED's using SoftPWM lilbray
Modified: 19 Sept 2013
*/

#include <SoftPWM.h>

void setup()
{
// Initialize Serial
Serial.begin(9600); // set up Serial at 9600 bps
// Initialize SoftPWM
SoftPWMBegin();

// Create and set pins for PWM use and turn them off
SoftPWMSet(2, 0);
SoftPWMSet(3, 0);
SoftPWMSet(4, 0);
SoftPWMSet(5, 0);
SoftPWMSet(6, 0);
}

// Initialize Loop counter
int i = 0; 
// Set array to store the 5 values from the serial port 
int incomingByte[5]; 

void loop()
{ // 5 channels are coming in to the Arduino
if (Serial.available() >= 5) {
// read the oldest byte in the serial buffer:
for (int i=0; i<6; i++) {
// read each byte
incomingByte[i] = Serial.read();
}
SoftPWMSet(2, incomingByte[0]); // Write current values to LED pins
SoftPWMSet(3, incomingByte[1]); // Write current values to LED pins
SoftPWMSet(4, incomingByte[2]); // Write current values to LED pins
SoftPWMSet(5, incomingByte[3]); // Write current values to LED pins
SoftPWMSet(6, incomingByte[4]); // Write current values to LED pins
}}

This is what I am using. It verified before uploading.

Thanks for taking the time to look.


----------



## HammieTime

FYI| I do have the SoftPWM library installed correctly. I am using the example of SoftPWM_LEDHead_Bounce successfully.


----------



## goneferal

See the highlighted red below. Try changing the six to a 5, it seems counterintuitive, but you only need 5 values and although you were using pins 2-6, the arduino doesn't care. Gosh, HF makes me proud that I am able to answer this question. I was baffled by it for like forever before. The softPWM library is limited to 20 channels, but all you would need to do is change the number if you want to exceed that. I hope hope hope this helps!
/*
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
*/

/*Code revised by HomeyDaClown to integrate B. Hagman's SoftPWM library so 7 PWM (or more) outputs are available for use. SoftPWM library files need to be installed for this to work.
Modified: 18 July 2011
*/

/* Code revised by HammieTime to test 5 LED's using SoftPWM lilbray
Modified: 19 Sept 2013
*/

#include <SoftPWM.h>

void setup()
{
// Initialize Serial
Serial.begin(9600); // set up Serial at 9600 bps
// Initialize SoftPWM
SoftPWMBegin();

// Create and set pins for PWM use and turn them off
SoftPWMSet(2, 0);
SoftPWMSet(3, 0);
SoftPWMSet(4, 0);
SoftPWMSet(5, 0);
SoftPWMSet(6, 0);
}

// Initialize Loop counter
int i = 0; 
// Set array to store the 5 values from the serial port 
int incomingByte[5];

void loop()
{ // 5 channels are coming in to the Arduino
if (Serial.available() >= 5) {
// read the oldest byte in the serial buffer:
*for (int i=0; i<6; i++) {*
// read each byte
incomingByte_ = Serial.read();
}
SoftPWMSet(2, incomingByte[0]); // Write current values to LED pins
SoftPWMSet(3, incomingByte[1]); // Write current values to LED pins
SoftPWMSet(4, incomingByte[2]); // Write current values to LED pins
SoftPWMSet(5, incomingByte[3]); // Write current values to LED pins
SoftPWMSet(6, incomingByte[4]); // Write current values to LED pins
}}_


----------



## HammieTime

Well after the change the code did verify and upload without any problems. I still having the same problems with the LEDs doing what they want. I think I need to look at Vixen next. I'll keep it simple and see what will happen. I still have until Oct 17 to get this working before the party..

Thank You again for your help..


----------



## goneferal

Are you using any LED drivers? You might have one placed upside down. The code verify will say things are OK even if it won't work with another interface. In my experience, either vixen works, or it doesn't. If you are getting some sort of output, in my experience, it has been a problem in the sketch or my circuitry outside of the arduino.


----------



## pshort

How does the pattern on the LED lights differ from the sequence?

In Vixen, make sure that the generic serial plugin is set up for exactly five channels. Also, check that the plugin is set up for the correct baud rate. And if you haven't done it already, try setting up a test sequence where all of the channels except one are off for the duration of the sequence, and one channel is blinking on and off (a completely static sequence is not very useful, because Vixen only sends data when the data changes value). See what that does.


----------



## pshort

Also, when setting up the generic serial driver, make sure that you do not enable either header or footer, as your sketch does not take into account any header or footer characters.

That particular sketch is going to be sensitive to when power is applied to the Arduino and when the Vixen sequence is started. One thing to try is to stop the vixen sequence from running, then power the Arduino off and back on, and then start the vixen sequence running. I suspect that goneferal has a ritual that is gone through religiously when starting up the show to avoid problems.


----------



## goneferal

I don't have any problems. I used to, but no more. Things run pretty smoothly. I don't use that sketch anymore.


----------



## HammieTime

This is the basic setup I am using.









I will check the baud rate in Vixen and I will only enable "Blinking" on one channel and see what my results are.

Thanks again guys


----------



## HammieTime

*ditto*









Sorry for the double post, I guess I can't edit my own post.


----------



## HammieTime

*Success*

SUCCESS

I went back to Vixen and looked and the Baud rate was not correct. After changing it to 9600, I am Rockin'.

Now the creative part. 14 channels and a catchy riff, what could go wrong.

Thank you again.

I'll construct a detailed blog post for what it's worth but, my wife is getting into it.


----------



## goneferal

Yes! Enjoy the blinky blinky!


----------

