Introduction: Lightstik Light Bar Controller

About: Hi, I'm Brad. My interests spread over a large area and I tend to get carried away when something new peaks my interest. I picked up my basic electronics knowledge in bed. Say what? I was laid up after surgery…

A friend of mine gave me a Lightstik traffic control light bar for my service truck. Only problem being that he didn't have the control box for it. So I'm in the process of making my own control box for it. Everything is done and working, I just need to clean it up and put it all together in a nice little package.

I'm willing to bet you don't have a traffic control light bar lying around but perhaps you'll be inspired and figure out something else you can do with this.

The light bar has eight lights (12v car/truck/trailer running light type) in total. Those are wired (from left to right)
1. Left arrow - one light, one wire out (this light is off in the pic)
2. two lights left of center wired together, one wire out
3. center two lights wired together, one wire out
4. Two lights right of center wired together, one wire out
5. Right arrow - one light, one wire (this light is off in the pic)
6. Two (2) positive wires out

To get this thing working I'm using a relay block, 5 position rotary switch, LEDs, resistors, my Arduino of course, and some fun coding. Oh yeah, and a 12v car battery, need the amps for that light bar. When it's moved from breadboard to project enclosure there will also be an on/off switch and a 12v to 5v step down module.

Components: relay block purchased from http://www.icstation.com/index.php?cPath=79&aid=55

Step 1: Getting My Relays and Switch Setup

I'm currently using my Arduino's 5v out to power a board with eight relays on it. I only need 5 of those relays so I'll swap that board out for a 4 block board and 1 single relay (when they get here). I'm using my Arduino's 3.3v out, through a five position rotary switch, to control which light bar pattern is run in the Arduino code.

To setup the RELAY block;
1. Arduino 5v out to the relay board's Vcc in
2. Arduino GND to the relay board's GND
3.Arduino digital pins 2-6 to corresponding INC pins on the relay board

And I added the 5 position rotary switch;

4. 3.3v out from Arduino to the primary IN on my switch
5. Connect wires 1-5 out from the switch to Arduino's ANALOG pins 1-5

So know you can determine which position the switch is in by locating the analog pin with voltage on it.

Note:
1. The pic shows digital pins 9 & 10 wired to the relay block, those are gone now.
2. You may need to open the wiring diagram above in a "new tab" which should allow you to zoom in so you can read the thing. (right click on the diagram, select "Open Image in New Tab" - your browser may be different)

Step 2: Power for Light Bar

The light bar requires 12v and 12-amps (8 lights drawing about 1.5 amps each, 8*1.5 = 12) so a car battery was brought to the party.

CAUTION: As we are playing with a car battery now it is important to add a properly rated FUSE to any Positive leads you have coming off of that battery. Something I myself forgot - but have now corrected.

In addition it is important to watch the gauge of the wire you are using. For those circuits with small amounts of current, IE: between the Arduino and relays (remember the Arduino is just switching the relays open or closed) small gauge wire is great. But you have to beef it up for those circuits running the 12v load. Stuffing too much current through a small wire is equivalent to too much water in a small pipe, something bad is going to happen. The pipe will burst and your wire will melt.


The two positive wires from the light bar cable connect to the car batteries positive terminal (don't forget a fuse).

The five ground wires from the lights (or group of lights) are each connected to the N/O (normally open) side of an individual relay.

The COM on all five relays are all tied together with a lead going to the negative terminal on the car battery.

I also added a separate board with five LEDs that mimic what the light board is doing. The LEDs will be incorporated into my final project box to give a visual representation of what the board is doing without having to look at it (I don't want to have to get out of the truck when it's raining).

To accomplish this I just ran 12v (with a fuse) into a breadboard from the car batteries positive terminal. I added five LEDs to the breadboard with five 800Ohm resistors, running the 12v + to one leg on each resistor and the other resistor leg (individually) to the positive leg of a LED.
For the GND leg of the LEDs I pigtailed off of the N/O (not the COM) wires already in the relays and ran those to the corresponding LED. Now when a relay turns on a light in the light bar, the corresponding LED lights as well.

Step 3: Coding

Pop Quiz: In the video, which section of code is executing as the switch is turned. Clue, it starts with the switch in position one and I move the switch sequentially from 1 to 5 and then straight back to 1 at the end. However, the sections of code are not sequential; IE: switch position 1 does not execute the code under the 1st labeled section in the sketch. I'll give you this one - switch position 1 = CA: in the sketch, and CA: is last section in the sketch, not the first as one might suspect.


The way I have this working is to check the analog pins (2-6) for voltage from the rotary switch. I didn't bother with any fancy math or anything here. After monitoring the pins I saw that they always registered a number around 20-30 except for the pin the switch was currently supply voltage to. That pin would be around something like 500-600 (sorry, don't remember the exact number). So I just have the code look for a pin that's >200 and then run the corresponding section of code I want for that switch position.

// Control box sketch for ARROWSTIK traffic control light bar, written by Bradley S. Worthington-White

// DEFINING CONSTANTS

// The relays in use are normally closed, R_ON & R_OFF below make writting the sketch a little easier, reverse R_ON and R_OFF for normally open relays

const int R_ON = LOW; //Relay ON

const int R_OFF = HIGH; //Relay OFF

// defining pin numbers for the lights in the light bar

const int LArrow = 2; //Left Arrow (one light)

const int LTwo = 3; //Left two outer lights

const int Center = 4; //Center two lights

const int RTwo = 5; //Right two outer lights

const int RArrow = 6; //Right Arrow (one light)

// DEFINING VARIABLES

//the waittime(s) below are changed within the individual sections of the sketch as appropriate

int waittime; // waittime

int waittime2; //second waittime

int waittime3; //and a third waittime

void setup()

{

// ensure all lights are off at startup or reset

digitalWrite(RArrow, R_OFF);

digitalWrite(RTwo, R_OFF);

digitalWrite(Center, R_OFF);

digitalWrite(LTwo, R_OFF);

digitalWrite(LArrow, R_OFF);

// set digital pin modes for switching the relays

pinMode(RArrow, OUTPUT);

pinMode(RTwo, OUTPUT);

pinMode(Center, OUTPUT);

pinMode(LTwo, OUTPUT);

pinMode(LArrow, OUTPUT);

// set analog pin modes for input from the 5 position rotary switch

pinMode(A1, INPUT);

pinMode (A2, INPUT);

pinMode (A3, INPUT);

pinMode (A4, INPUT);

pinMode (A5, INPUT);

}

void loop()

{

// ensure the value of all analog pins is zero (0) at startup or reset

analogWrite(A1,0);

analogWrite(A2,0);

analogWrite(A3,0);

analogWrite(A4,0);

analogWrite(A5,0);

Switch: // reads the switch position and goes to the labeled section in sketch that applies

if (analogRead(A1)>200) goto CA1;

else if (analogRead(A2)>200) goto LA1;

else if (analogRead(A3)>200) goto RA1;

else if (analogRead(A4)>200) goto AL1;

else if (analogRead(A5)>200) goto KR1;

KR1: //Knight Rider

// defining waittime(s) for this sequence

waittime = 75;

waittime2 = 25;

digitalWrite(LArrow,R_ON);

delay(waittime);

digitalWrite(LTwo,R_ON);

delay(waittime2);

digitalWrite(LArrow,R_OFF);

delay(waittime);

digitalWrite(Center,R_ON);

delay(waittime2);

digitalWrite(LTwo,R_OFF);

delay(waittime);

digitalWrite(RTwo,R_ON);

delay(waittime2);

digitalWrite(Center,R_OFF);

delay(waittime);

digitalWrite(RArrow,R_ON);

delay(waittime2);

digitalWrite(RTwo,R_OFF);

delay(waittime);

digitalWrite(RTwo,R_ON);

delay(waittime2);

digitalWrite(RArrow,R_OFF);

delay(waittime);

digitalWrite(Center,R_ON);

delay(waittime2);

digitalWrite(RTwo,R_OFF);

delay(waittime);

digitalWrite(LTwo,R_ON);

delay(waittime2);

digitalWrite(Center,R_OFF);

delay(waittime);

digitalWrite(LArrow,R_ON);

delay(waittime2);

digitalWrite(LTwo,R_OFF);

delay(waittime);

digitalWrite(LArrow,R_OFF);

goto Switch; // each section always returns to switch to check if the switch position has changed

LA1: //LEFT direction sequence

waittime = (125); // defining waittime(s) for this sequence

waittime2 = (200);

waittime3 = (50);

digitalWrite(RTwo, R_ON); // begins by turning lights on in sequence from left to right

delay(waittime);

digitalWrite(Center, R_ON);

delay(waittime);

digitalWrite(LTwo, R_ON);

delay(waittime);

digitalWrite(LArrow, R_ON);

delay(waittime);

digitalWrite(LArrow, R_OFF); // Left Arrow flashes after all lights on

delay(waittime2);

digitalWrite(LArrow, R_ON);

delay(waittime2);

digitalWrite(LArrow, R_OFF);

delay(waittime2);

digitalWrite(LArrow, R_ON);

delay(waittime2);

digitalWrite(LArrow, R_OFF);

// turning lights off, from right to left - quickly

digitalWrite(RTwo, R_OFF);

delay(waittime3);

digitalWrite(Center, R_OFF);

delay(waittime3);

digitalWrite(LTwo, R_OFF);

delay(waittime3);

goto Switch; //recheck switch position

RA1: // RIGHT direction sequence

waittime = (125); // defining waittime(s) for this sequence

waittime2 = (200);

waittime3 = (50);

// begins by turning lights on in sequence from left to right

digitalWrite(LTwo, R_ON);

delay(waittime);

digitalWrite(Center, R_ON);

delay(waittime);

digitalWrite(RTwo, R_ON);

delay(waittime);

digitalWrite(RArrow, R_ON);

delay(waittime);

// Right Arrow flashes after all lights on

digitalWrite(RArrow, R_OFF);

delay(waittime2);

digitalWrite(RArrow, R_ON);

delay(waittime2);

digitalWrite(RArrow, R_OFF);

delay(waittime2);

digitalWrite(RArrow, R_ON);

delay(waittime2);

digitalWrite(RArrow, R_OFF);

// turning lights off, from left to right - quickly

digitalWrite(LTwo, R_OFF);

delay(waittime3);

digitalWrite(Center, R_OFF);

delay(waittime3);

digitalWrite(RTwo, R_OFF);

delay(waittime3);

goto Switch; //recheck switch position

AL1: // Flashing sequence with Center light on steady and LTwo and RTwo flashing on both sides of Center

waittime = (125); // defining waittime(s) for this sequence

waittime2 = (50);

if (Center == LOW) goto cont; // avoids playing with the center light after it's on

digitalWrite(Center,R_ON);

cont:

digitalWrite(LTwo, R_ON);

delay(waittime);

digitalWrite(LTwo, R_OFF);

delay(waittime2);

digitalWrite(LTwo,R_ON);

delay(waittime);

digitalWrite(LTwo,R_OFF);

delay(waittime2);

digitalWrite(RTwo, R_ON);

delay(waittime);

digitalWrite(RTwo, R_OFF);

delay(waittime2);

digitalWrite(RTwo, R_ON);

delay(waittime);

digitalWrite(RTwo, R_OFF);

delay(waittime2);

goto Switch; // recheck switch position

CA1: // Lights on steady (no flashing), the arrow lights on each end stay off

waittime = (10); // defining waittime(s) for this sequence, just a short delay for stability

digitalWrite(Center, R_ON);

delay(waittime);

digitalWrite(LTwo, R_ON);

delay(waittime);

digitalWrite(RTwo, R_ON);

delay(waittime);

delay(1000); // waits for a second before checking the switch position again

goto Switch; // checking switch position, but you knew that by know

} // The End

Step 4: Packaging It All Up

Well, I'm done! She's all packaged up and working great.

The pics above pretty much tell the rest of this story for me. So the following is a little detail about each of those.

#1. Getting things packed into one medium project enclosure. Nope, sorry - not enough room in "one" box for everything. The relays, circuit board with the Arduino Pro Mini and couple of connecters, and the 12v to 5v step down module all remain in the "main" box.

Note: I did leave leads connected to the Pro Mini's TX0, RX1 and RST. That way if I change a light pattern or something in the future I have those leads waiting for me so I can reprogram the mini.

#2. That's just a close-up of the 12v DC to 5v DC module I borrowed from a USB car charger. Those come in handy and for .99 cents each at Goodwill (for the car charger - you have to gut it yourself) you can't beat the price.

#3. Something I had not planned on for in this project was making the Light Bar portable, yeah besides driving it around on my truck I mean. However while I was making the mounting brackets for the truck I realized that with very little effort I could also make it a completely stand-alone unit, so I did. And there's a pic of the results. I used (good) Velcro to stick the two boxes to the speaker stand (yep, that's a loud speaker stand, I love repurposing things). This light bar has a track on the back for T bolts so repositioning the bolts is a simple matter of sliding them to where you want them. Which makes moving the light bar between the truck and the stand very easy.

#4. Shows the "main" box (background) and the "control" box in front of it. I could have done a lot more cleaning up of the wiring for the "main" box, but just didn't have the energy - maybe someday.

#5. That's just the side of the control box, the sticker helps hide the fact that my box is an electrical outlet box and cover (less than a $1.00 total at Home Depot).

#6. If it's going to be portable then it has to be convenient to move around. Everything is packed up in those two bags. The light bar in the long bag obviously and the other bag has everything else in it including about 30' of cable to get you to the nearest battery. You can see the main cable going between the bags, guess I'll have to cut that and put a connector on it.

#7. And last, but certainly not least, there's a pic of the light bar where it is supposed to be, on my truck!! Gee, that truck needs cleaning something bad.

This has been a fun project for me. Got to learn some stuff and make something useful in the process. I thank you for allowing me to share it with you, hope you found it interesting.

Happy Holidays,

Brad

___________Comments prior to 11/30/2015 are below _________

I will update this when some components I'm waiting for arrive and I can move this from my work bench to my truck.

CAUTION: When I do move this to my truck everything will be powered from the truck's battery. When doing ANYTHING that involves a connection to your car/truck/whatever battery make sure you put a properly rated FUSE on the positive connection. The fuse should be close to the batteries positive terminal, not the other end of the connection.

I still have some things to decide when I start packaging this up. Am I going to try and put everything into one box or separate some components to make it easier to install in the truck. I'm thinking it will make for a much cleaner install to put the bigger components in their own box which I'd mount under/behind the dash. That box would then be connected to a much smaller box on the dash that only needs the on/off switch, rotary switch and LEDs.

(That decision has been made, or was made for me I should say. A medium size project box is just a hair to small to get everything into nicely and I don't want to use a large box, so two boxes it is.)

UPDATE: 11/26/2015 (Happy Thanksgiving everyone)

I got to play a little today and started on my LightStix Control box. I guess some of the highlights would be;

1. The programs now runs on an Arduino Pro Mini (it's on the circuit board in the pic)

2. The circuit board also has two other connectors on it. The 3 pin connector is connected to the mini's TX0, RX1 and RST (reset) pins. That way I'm already to re-program the mini should I want to in the future. The other 5 pin connector is supplying power to each of the relays.

3. The large 10 pin connector at the bottom of the box brings 5 wires IN, one for COM on each relay (yeah I could have daisy chained one wire for the COM, but what fun would that be). The other 5 wires go OUT, one from each relay to the appropriate light (or group of lights).

I am happy to say that everything is working, not to say that I didn't have some fun times getting it from the breadboard into an actual working box, but isn't that always the case.

I will tell you one thing funny (don't tell anyone else though). I substituted the Arduino Mini for another one I had after I ... well I just needed to replace it. Anyway, sometime later I'm testing things and nothing's working! I spent a couple of hours troubleshooting and finally gave up and went for a walk with the wifey. In the middle of that walk my brain kicks into gear and says to me "Hey dummy, guess why nothings working with the new Arduino Mini in the picture", I had to respond, so I'm like "OK brain, I give up - why isn't it working". I then heard my brain laugh, really my brain laughed at me before I heard, "because you haven't programmed the new mini yet dummy". I hate my brain!

Obviously, from the pic, I still have a couple of wires to shorten up - yeah just a few 'eh. Will update again when she's all done and I have the LightStix and control box installed on/in my truck.

UPDATE: 11/27/2015 (I'm stuffed and now we have to eat turkey sandwiches for a week)

I have been working on my control box this morning. Everything is done!!! I just need to stuff everything into the box far enough to get the screws in the top of the box. I added a quick video showing the LEDs in the control box running in sequence with the lights in the LiteStik. And yes, those are the relays you can hear clicking in the background.

UPDATE: 11/28/2015 (adding 12v to 5v step down module to package)

Quick note, while packaging this up I realized I needed a 5v power supply for the Pro-Mini. The specs for the mini list the Input Voltage range as 5 - 12v. But I don't want to push it to the edge of that range (and beyond) by coming directly to the mini with 12v from my trucks batteries. And besides, we all know that a 12v system in a vehicle can run as high as 14.4v when the alternator is working to charge the battery or batteries.

So I stole a 12v to 5v step down module out of a cell phone car charger. There's a pic of it above.

I purchase a lot of my modules and other items from http://www.icstation.com/index.php?cPath=79&aid=5... (I would like to shop locally, but it's a 90 minute drive (roundtrip) for me to the nearest electronics store. And I'm sorry but I'm not driving that far just to pay $15 bucks for something I can get for $2 with free shipping!

Make It Glow! Contest

Participated in the
Make It Glow! Contest