Facebook Twitter Pin It Reddit

Project Build: Arduino Police Flasher Kit

Gain Arduino Experience with This Just For Fun Kit

Jameco Builds logo By Ryan Winters
Product Marketing Manager

After reading about the famous Arduino programmable microcontroller using the "Getting Started with Arduino Kit I was eager to try my hand at some real live electronic programming. The Arduino platform is a great place to start for a novice like me. After learning the basics and getting some LEDs to blink or fade, I was ready to challenge myself, and I mean challenge.

Flasher Overview

Since I just learned how to make LEDs blink and flash, I thought to myself, what else could I do with this newfound knowledge? I wanted to do something difficult because I learn better when I make mistakes. Then it came to me. Well, it actually flew past me, like a police officer with his lights and sirens blaring. I decided I would make my own red and blue LED flashing lights just like the police. I was originally planning to use Red, Green, Blue (RGB) LEDs for this application, but I would need a common anode version of the LED and Jameco currently has the common cathode (ground) variety.



Note: This project is for fun, and should not be used on any vehicle used on public roads. In most states, impersonating an officer or having red, blue, or white flashing lights on your car is illegal. You have been warned!

Arduino Flasher Kit Includes:

Qty.
Description Manufacturer Part No.
20
Red LEDs, 635nm, T1-3/4 LTL-307E-002A
20
Blue LEDs, 3.6V, 470nm, T1-3/4, 3000mcd MCDL-5013UBC-TL
1
Protoboard 1.6" x 2.7" G/S(PCB228)-R
1
Protoboard 2.0" x 4.4" 2853PCB-R
1
ABS box, black, 2.0" x 3.1" x 0.9", fits 105100 H2855-R
1
ABS box, black, 2.5" x 4.9" x 1.5", fits 105129 H2853-R
4
Terminal block, 2-position, screw terminal OSTTE020161
1
Switch, momentary, pushbutton, SPST, OFF-(ON) R18-29A-ROHS
4
Transistor, 2N2222, NPN 2N2222A
100
Resistor, 1/4W, 82Ω CF1/4W820JRC
100
Resistor, 1/4W, 120Ω CF1/4W121JRC
100
Resistor, 1/4W, 1KΩ CF1/4W102JRC
100
Resistor, 1/4W, 10KΩ CF1/4W103JRC
1
Hook-up wire, 22 AWG #9313-0-R
1
Switch, pushbutton, SPST, OFF-ON R13-23B-R-R
2
Protoboard mount kit 00106551
1
9V battery snaps with 6" leads A104-R
1
Plug, DC power, 2.1mm X 5.5mm, right angle PL-007
1
Battery, 9V ALK 9V 522

Build Your Flasher

I had an overall vision for this project before I started and ran into a few part placement issues during my build. I ended up modifying some parts halfway through the project, so I would recommend familiarizing yourself with the project before starting. First, I built the remote module. This kit will require an Arduino microcontroller but is not included in this kit. If you need one, I used the Duemilanove, which has since been replaced by the functionally-similar Uno R3.

I started with the smaller PCB since I knew space was going to be an issue. RGB LEDs would have been nice because it would require less space, but this design uses both red and blue LEDs. The first step is to bend the resistors and mount them starting from the edge of the PCB. You will use one resistor per LED per color, so you will need ten 82Ω resistor and ten 120Ω resistors. The idea here is the power will distribute through both edges of the PCB, through each resistor, then to its connected LED, then ground, where all ground leads from the LEDs will be joined to create one main ground lead.

LED/Resistor configurationFig 1. LED/resistor configuration


Place the resistors through the holes starting from the outer edge and ending in the middle. I also mounted a couple transistors and 2-position terminal blocks, so I had to plan the hole usage accordingly. Start with the PCB solder-side down with the part number at the bottom. Insert the first 120Ω resistor into the bottom row and second hole from the right. (see Fig. 1) It should be the first row that goes from end to end. The other end of the resistor should go in the same column but the third hole up. The resistor should only take up four holes. Insert the other nine 120Ω resistors in the same manner, starting from the bottom row and making sure to skip a column to spread the resistors out. For the 82Ω resistors, mount them the same way as the last ten resistors but start from the other side (top row) and stagger them so they are directly across from blank spaces at the other side. See figure 2 below for example.

Resistor Placement

Solder the resistors, but don't cut off the leads yet. The two edge rows of the PCB where the resistors start will be the power rails. When you turn the board over, the very first resistor that was mounted is now on the left. Starting with that first resistor lead, bend it over the other resistor leads in the same row so that it's flat and makes contact with the other leads. Solder the bent lead to the other resistor leads it contacts. You will have to bend a couple more to connect the ten resistors as a common rail. See figure 3. The idea is to have the row completely connected. After the row is all soldered together, leave the right-most lead alone for later use and cut the extra off the soldered connections.

solder resistors


Situating the LEDs was the tricky part. See figure 4 for a close-up.

It is easiest to mount and solder one LED at a time so you can be sure the mounting height is consistent. Plus, you don't want the other LEDs to crowd your work area. Start with the red LEDs and work from left to right. Insert the anode (longer lead) into the hole just above the leftmost 120 resistor and the cathode (shorter lead) into the hole next to it at the outer edge of the PCB. I wanted the LED to sit a little bit up off the board so that when the PCB was mounted into the enclosure box, the LED surface would be flush with the surface of the box. I used some tape to hold the LED at the desired height and then soldered it into place. The next LED would have to be staggered and installed in the same fashion as the first LED, but one row above the previous row. The anode went in the same column as the resistor, and the cathode in the blank column. Install the third LED the same way as the first, but in the first row. You will see how the LEDs are fitting snugly next to each other with each anode lining up with a resistor, and each cathode lining up to an empty column. See figure 5.
LED placement
LED placement (Ignore the terminal block, I was just checking space. You can see the LEDs are fitting nicely.)

After all the red LEDs are installed, working from the solder side, bend each anode of the LEDs over to contact a resistor lead. I chose the LED lead because it is sturdier than the resistor leads. Each anode can be soldered to an individual resistor and clip off the extra. I would recommend clipping off the extra after testing to make sure everything is properly configured. The negative lead of the LEDs will be bent in such a way that the leads closer to the center of the PCB will all be bent toward one side to form a rail, and the remainder will be bent toward the center to contact that newly formed rail. It should be every other lead because of the way the LEDs were staggered. Be sure to make the ground rail high enough so it doesn't short out on any other component. Once the leads are bent, the extra length of lead over the ground rail can be cut off. Solder all cathode lead contact points to form one common ground lead. Do this for each color, and each finished ground lead will be facing opposite sides of the board. See figure 6.

power rail

For the blue LEDs, they will be installed in the same staggered pattern as the red LEDs. If you are looking at the board from the component side, the next set of LEDs will be installed so there are two blank holes between the red and the blue LEDs. Every other LED's anode will be right below a resistor, while the other half will be installed one row below the other LEDs. The up and down pattern should look just like the red LEDs. The anode of the blue LEDs can be bent over to contact a resistor and soldered at that point, then cut the excess. Bend the cathode in the same manner as you did with the red to form a common ground lead. Looking at the board from the solder side, where the red common ground was constructed to point toward the left side, the blue ground leads will be bent to form a common ground lead that points to the right side. Both of these common grounds will connect to a transistor at either side of the board.

After all of the LEDs on the module were wired together, I decided to test them to make sure they all worked. To be truthful, I learned to solder just before starting this project, so my technique was lacking, and I was unsure all the solder joints were solid. I used my multimeter to test for continuity through each resistor, but I could have also applied 5V to the power rail and connected the ground to make sure they all lit up. Lucky for me they did, and by this time, my solder skills had vastly improved.

Police Flasher Fig 7 Next step is to install the transistors to the module. See figure 7 for the pin configuration. The collector on the transistor will pick up the common ground lead, the emitter will be connected to ground, and the base will eventually connect to an Arduino digital pin after passing through a 1K resistor. Situate the transistor so the collector is closest to the ground lead. There will only be seven empty holes to work with in the area for the transistor, so be sure to spread them out so the connections don't interfere with each other. Solder the collector to the ground lead from the LEDs and clip the excess. Do the same for the other transistor.

Set the terminal blocks at an angle in the only available space on the board. There should be one each opposite the transistor. Because of the pin spacing on the terminal blocks, they have to be installed at an angle using holes that are diagonal of each other. See figure 8 below for the placement.

terminal blocks

One terminal block will be used for the signal wires to the Arduino for each color, and the other block will be used for the power and ground connections. I chose to use terminal blocks, so the modules could be placed at a user-determined distance from each other. Since power will come in from one pin of the terminal block, that pin has to be connected to both power rails. I chose the terminal block on the red side to be the power and ground distribution point. Use a clipped lead piece to join the power rail to the pin closest to it. Use some hook-up wire (Jameco P/N 36792) to tap into the power pin, and run it to the other power rail on the opposite side. See Fig. 9.

wire connections

Use some more hook-up wire to join the emitter pins of the transistors to the other pin of the terminal block that is being used for power/ground distribution. Each base lead of the transistor can be connected to the pins on the other terminal block. (Side note: It wasn't until after completion that I realized I probably could have stuffed the two 1KΩ resistors (Jameco P/N 690865) for the signal wire on this board before the terminal block so I wouldn't have to make more solder connections on the main module board.)

Jumper (Here I could have used the 1K resistor as a jumper)

Scrap Leads (Scrap leads used as a jumper)

Just for kicks, I connected this completed module to my Arduino and wrote a quick program to test the functions of the module. (See the end of the article for sample code.) Now that I knew it worked, it was time to mount it in the enclosure. Using the ABS box (Jameco P/N 18922) and a protoboard mount kit (Jameco P/N 106551), I attached two standoffs to the component side of the PCB using the included hardware. I used the shorter length screws, since the ABS box is probably thicker than the PCB and could use the extra length. Since everything was going into the box somewhat upside-down, it was difficult to locate the standoffs on the box. I made a rough rectangle on the box with a marker where the LEDs would protrude and cut it out with a rotary tool. I cut a bit too much, but now that the LEDs stuck out, the standoffs sat flush when the module was placed in the box. To mark where the standoffs sat in the box, I put some paste on the standoffs, placed the module carefully in the box, then pulled it out to see the marks left by the standoffs. Using a marker, I put a dot where the center of the standoff ought to be and drilled out the hole. Then using the longer screws, I fastened the module into the box. This module will have to come out again to install the connecting wires to the terminal blocks, but at least I knew it would install securely into the box.

Enclosure 1
Enclosure 2

Enclosure 3
Enclosure 4
(It may help to stripe the wires with a marker so you can identify which one goes where from outside the box.)

Main Board Module

The main board module is assembled pretty much the same way as the remote module, but there is much more space to work with. I still wanted the LEDs in the center, so I started by mocking up where the LEDs would go in the middle, staggering them like on the other module. The resistors are still installed starting from the outer edges of the long side of the PCB (Jameco P/N 105129) and the first column that reaches both edges of the PCB. On this module, the common ground leads created by the combination of cathodes from the LEDs can be guided to the same side of the board since there is room for both transistors on the right side.

(1KΩ resistor goes between the base lead of the transistor and the wire that will connect to the Arduino's digital pin. There will be four total.)

Above, you can also see the jumper wires were installed to join the power rails and run power to the board from the Arduino. It also connects ground connection from the Arduino to the board and a couple signal wires. Try to keep the components justified to one side on the PCB because you also have to consider the other components being stuffed into the box (e.g. 9V battery, Arduino, and a couple switches). It is also a good idea to test the LED module to make sure all connections are solid and working as it should. The terminal blocks can be installed and will be used to connect the two boards together. In all, there will be seven wires coming off the main PCB to connect to the Arduino.

Solder a 1KΩ resistor to each base on the transistor, and connect the other end of the resistor to a piece of hook-up wire that will connect to the Arduino. All wires that connect to the Arduino should be short, but long enough to give you room to connect everything while the box is open. Install the terminal blocks.

Terminal Block Connection

The terminal blocks are just used to connect the two boards together. On the remote module, if I had installed the 1KΩ resistors before the terminal block, I could have run the wire from the terminal block straight to the Arduino pins. In this instance, the signal wires from the remote module connect to the terminal block on the main PCB. From the terminal block on the main board, solder a 1KΩ resistor to each pin and solder the other end to a piece of hook-up wire that will connect to the Arduino's digital pins. It is best to solder the connections at the board rather than just free-floating.

The other terminal block will be for the power and ground from the remote module. The pin used for power can be connected to both power rails on the main PCB. Then solder a short piece of hook-up wire to the power pin on the main PCB. The other end will connect to the 5V header on the Arduino. I soldered the emitter pins of both transistors to the same outer edge because the plating is already joined nicely to create a ground bus. In the image above, the wire running between the two LED colors is connecting the ground pin of the terminal block to the ground bus I created at the edge of the board. Next solder a piece of hook-up wire to the ground strip, and the other end will connect to the GND header of the Arduino.

Solder two more pieces of hook-up wire to the main PCB with the base of each transistor. Again, feed the hook-up wire through a hole in the PCB closest to the base and bend the wire to connect to the base lead and solder together. By now you should have six wires coming off the main PCB to connect to the Arduino. I still needed to add a momentary switch (Jameco P/N 26623) which would allow me to select different flash patterns. Wire the switch as in the diagram below.

You will be able to tap into the 5V and ground circuits on the main PCB.

Switch Connection




Switch Connection Schematic
Next step will be to wire up the 9V battery holder, right angle barrel plug and switch. These three will be wired together to supply the Arduino with power, but also give you the ability to cut power without having to open the box. (See below for how to wire.)

Power Connection

Wiring these together is fairly straight forward. Just make sure the positive wire from the battery holder (usually the red wire) is connected to the tab for the center pole of the power plug. The Arduino is set up for a center positive plug, so you don't want to reverse polarity. This photo was taken from my initial design. I changed the battery holder to a smaller type and switched the plug in the photo with a right angle version to account for space. Consider placement of everything in the box, as I just assumed everything would fit. There isn't a lot of space left for the battery and switches to fit inside the box, but if the switches are installed one above the other, the battery should fit right in between the switches and the wall of the box.

As for mounting the PCB and other components into the other enclosure, you will need another PCB mounting kit. I mounted the PCB to the lid of the case, and the Arduino and switches to the bottom of the case. You will also have to drill a hole for the wires to connect to the other light module. Measure the approximate size of the LED array to see how big of a rectangle to cut out of the lid. I just rested the LEDs on the lid and used a marker to mark the edges of the lights. I used my Dremel to cut out a rectangle a little bit smaller than the light area, just to make sure I didn't cut too much this time. Once I had a cut-out big enough for the LEDs, the standoffs would contact the lid. They may be marked in any method of your choosing. Some kind of liquid or paste or even lipstick works well to mark the points where the standoffs touch the lid and it's easy to clean. Now the marks where the standoffs will be can be drilled out, and the PCB can be mounted to the lid of the enclosure. Again, I would recommend marking the seven wires to the Arduino with stripes because once the PCB is mounted, it may be difficult to tell which wire connects where.

Mount the PCB

The Arduino should be situated directly under the light array as close to the edge as possible with the power connector facing the middle of the enclosure. The two spare standoffs from the mounting kit used on the remote module can be used for mounting the Arduino to the bottom of the case. I installed the standoffs on opposite corners. Two screws are all that is needed to keep the Arduino from moving around. Wait to install the Arduino until programming is complete because it will be difficult to gain access to the USB port when the Arduino is in the enclosure. Decide how far you would like the two modules apart from each other and cut four pieces of hook-up wire of that length, plus a little more. You could also use multi-conductor cable.

Assembled Flasher

With the Arduino secured to the bottom of the case, plug the wires into the following pins:

Module Arduino
Power Wire 5V pin
Ground Wire GND pin
Main PCB Red Digital pin 2
Main PCB Blue Digital pin 4
Remote Module Red Digital pin 7
Remote Module Blue Digital pin 8
Momentary Switch Digital pin 12


The modules are now complete and you may now program your Arduino. The software is free and is available here. I have provided my final revision of code so you may use it or modify it as you see fit.

Assembled Flasher Kit

Programming with Arduino

I have four signal wires that correspond to the red and blue colors on each module, and I have a pushbutton to tell the Arduino to change to a different blink pattern. The idea is to have the Arduino count how many times the button is pressed and run a program based on the number. The starting point sets the number to zero, which means off. I only have two blink patterns programmed, so once the counter reaches two, the next instruction will set the count back to zero and turn the lights off. See below for the final program.



/*
* Police Light Flasher using two arrays of red and blue LEDs.
*/

#define RRED 7 // Red LEDs on the remote module
#define RBLUE 8 // Blue LEDs on the remote module
#define LRED 2 // Red LEDs on the base module
#define LBLUE 4 // Blue LEDs on the base module
int button = 12; // button is connected to pin 12
int val; // variable for reading the button status
int state; // variable to hold the last button state
int presses = 0; // how many times the button was pressed
int mode = 0; // what mode the flasher is in
void setup(){
pinMode(RRED,OUTPUT); //sets Red LEDs as output
pinMode(RBLUE,OUTPUT); //sets Blue LEDs as output
pinMode(LRED,OUTPUT); //sets Red LEDs as output
pinMode(LBLUE,OUTPUT); //sets Blue LEDs as output
pinMode(button,INPUT); //sets the button as an input

state = digitalRead(button); //reads buttons start position
}

void loop(){
val = digitalRead(button); //sets val to the state of the button press
delay(10); //debounce multiple button presses
if (val != state){ //compares button press to current state
if (val == LOW){
if (mode == 0){ //if mode is zero and button was pressed, set mode to 1
mode = 1;
} else {
if (mode == 1) { //increment mode to 2
mode = 2;
} else {
if (mode == 2){
mode = 0;
}
}
}
}
state = val;
}

if (mode == 0){ //ALL OFF //mode 0 turns all LEDs off
digitalWrite(RRED,LOW);
digitalWrite(LRED,LOW);
digitalWrite(RBLUE,LOW);
digitalWrite(LBLUE,LOW);
}
if (mode == 1){ // strobe both sides, alternating color
byte count = 0; //sets a counter for flashing
byte number = 0; while (count < 5){ //counter loop to flash red LEDs 5 times
digitalWrite(RRED,HIGH);
digitalWrite(LRED,HIGH);
delay(60);
digitalWrite(RRED,LOW);
digitalWrite(LRED,LOW);
delay(60);
count++;
}
while (number < 5){ //counter loop to flash blue LEDs 5 times
digitalWrite(RBLUE,HIGH);
digitalWrite(LBLUE,HIGH);
delay(60);
digitalWrite(RBLUE,LOW);
digitalWrite(LBLUE,LOW);
delay(60);
number++;
}
}
if (mode == 2){ // red flasher, alternating sides
digitalWrite(RRED,HIGH); //remote red on
delay(400); //wait 400 ms
digitalWrite(RRED,LOW); //remote red off
digitalWrite(LRED,HIGH); //base red on
delay(400); //wait 400 ms
digitalWrite(LRED,LOW); //base red off
}
}

This should help you to get started and at least have the flasher functioning. You may also add additional modes for the flasher. Just add another increment in the state counter and then define what the new mode does.

Tips and Tricks

It is helpful to place the components into the board before any soldering to make sure you will have space for everything. The remote module in this project is packed full of components, so it also helps to understand the circuit diagram.

Plan the layout of the main board before drilling holes and mounting components. It wasn't until after I had gotten the main switch in that I realized the battery would not fit in the case. At that point I also changed the power plug to a right angle version to gain some more clearance.

My code was also quite lengthy when it came to flashing the lights. I had originally written the instructions for each on and off cycle, but soon learned a while() loop would repeat the enclosed set of instructions for a given number of times. Not only was it easier to write, but it decreased the size of the code file by a kilobyte or so, and when your programs start approaching the 32KB maximum memory size, you will need to be as efficient as possible when coding.

Lastly, have fun!

Arduino Flasher Kit Schematic


Ryan Winters is a Product Manager at Jameco Electronics and a Bay Area, California native. He is mostly self-taught and his hobbies include working on cars and computers, fiddling with electronic gadgets and experimenting with robotics.