Arduino Police Lights
The purpose of this project was to create police lights to install on my children's cozy coupe so that they could chase each other around, pretending to be police officers.
This is an instructable for the lights only. There are no sirens!!
Supplies
1 Arduino Nano (5 volt). I did not use a genuine Arduino but rather used an alternative with ATmega328P.
1 usb cable that fits the Ard.
2 LED ring lights ws2812, 12 bit/pixel, with drivers for arduino
1 portable usb power bank. Mine was a 4000 ah but ensure it has a large USB-A port on it.
Assorted wires
Electrical tape
Soldering supplies
1 cozy coupe or alternative
(No resistors used)
Build the Circuit Prototype
I assembled the circuit to test it and tweak it before I started building it onto the car. It is a very straightforward and simple circuit to set up. Each of the ring LED's can be daisy chained together with the in-and-out ports on them. By doing that you increase the total bits/pixels of the lights that will be reflected in the code.
Note that you are using the 5V from the Arduino to power these lights. Ensure the one you use is a 5V model and not a 3.3V. The Nano is a great choice as it is small and this is a fairly simple operation.
Note that I did not use any resistors here. I don't know if it is absolutely necessary but I did play around with it separately and yes, you can install a resistor to reduce the brightness. For this particular instructable I will leave it without a resistor and see what happens.
I should also note here that I was not initially able to get this Nano board compatible with my laptop and the Arduino IDE interface. This would not show up in my list of ports and so after doing some searching I had finally found some instructions on how to get this device to work. Apparently these alternative boards have some different drivers that required me to go out and find new drivers to make them work. If you clicked on your device manager you would see that there should be an ! next to the USB device and that required updating. Google search the CH340 drivers for the Nano and you will find separate instructions on that. I should note that it is not necessary to install the executable that was included in the download. You can just extract the files to act the files to a folder on your hard drive, and from device manager you can update the driver and have it search in that extracted folder.
Code
The code starts below this line. I should mention that I am not the author of this code. I received this code from a neighbor who tweaked it as I was trying to explain what I wanted to do. I have since tweaked it to work specifically for this project of mine.
You can change this if you want. I tried to incorporate some kind of a Flash pattern that looped.
You'll also see up at the top pin number 3 is what I referenced on the sketch, and 24 number of pixels is the total amount of lights between the 2 rings of 12 lights each. Obviously if you get a ring light that has as a different count than 12, or if you string multiple ring lights together, then you'll need to update that number accordingly.
And you will also need to add the Adafruit Neopixel library. That is done from within the Arduino program on your computer.
-‐---------------------------------
#include
#ifdef __AVR__
#include // Required for 16 MHz Adafruit Trinket
#endif
//This is the board pin that sends controls
#define PIN 3
#define NUMPIXELS 24
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 100 // Time (in milliseconds) to pause between pixels
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code .
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
//Red Side Loop 255,0,0
//Flashes half red/half white for 5 flashes
for(int i=0; i<5; i++){
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL);
pixels.setPixelColor(12, pixels.Color(255, 0 , 0));
pixels.setPixelColor(13, pixels.Color(255, 0 , 0));
pixels.setPixelColor(14, pixels.Color(255, 0 , 0));
pixels.setPixelColor(15, pixels.Color(255, 0 , 0));
pixels.setPixelColor(16, pixels.Color(255, 0 , 0));
pixels.setPixelColor(17, pixels.Color(255, 0 , 0));
pixels.setPixelColor(18, pixels.Color(255, 0 , 0));
pixels.setPixelColor(19, pixels.Color(255, 0 , 0));
pixels.setPixelColor(20, pixels.Color(255, 0 , 0));
pixels.setPixelColor(21, pixels.Color(255, 0 , 0));
pixels.setPixelColor(22, pixels.Color(255, 0 , 0));
pixels.setPixelColor(23, pixels.Color(255, 0 , 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
//Blue Side Loop 0,0,255
//Flashes half blue/half white for 5 flashes
for(int i=0; i<5; i++){
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL);
pixels.setPixelColor(0, pixels.Color(127, 127, 127));
pixels.setPixelColor(1, pixels.Color(127, 127, 127));
pixels.setPixelColor(2, pixels.Color(127, 127, 127));
pixels.setPixelColor(3, pixels.Color(127, 127, 127));
pixels.setPixelColor(4, pixels.Color(127, 127, 127));
pixels.setPixelColor(5, pixels.Color(127, 127, 127));
pixels.setPixelColor(6, pixels.Color(127, 127, 127));
pixels.setPixelColor(7, pixels.Color(127, 127, 127));
pixels.setPixelColor(8, pixels.Color(127, 127, 127));
pixels.setPixelColor(9, pixels.Color(127, 127, 127));
pixels.setPixelColor(10, pixels.Color(127, 127, 127));
pixels.setPixelColor(11, pixels.Color(127, 127, 127));
pixels.setPixelColor(12, pixels.Color(0, 0, 255));
pixels.setPixelColor(13, pixels.Color(0, 0, 255));
pixels.setPixelColor(14, pixels.Color(0, 0, 255));
pixels.setPixelColor(15, pixels.Color(0, 0, 255));
pixels.setPixelColor(16, pixels.Color(0, 0, 255));
pixels.setPixelColor(17, pixels.Color(0, 0, 255));
pixels.setPixelColor(18, pixels.Color(0, 0, 255));
pixels.setPixelColor(19, pixels.Color(0, 0, 255));
pixels.setPixelColor(20, pixels.Color(0, 0, 255));
pixels.setPixelColor(21, pixels.Color(0, 0, 255));
pixels.setPixelColor(22, pixels.Color(0, 0, 255));
pixels.setPixelColor(23, pixels.Color(0, 0, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
//Blue Side Loop 0,0,255
//Flashes half blue/half white for 5 flashes
for(int i=0; i<5; i++){
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL);
pixels.setPixelColor(0, pixels.Color(0, 0, 255));
pixels.setPixelColor(1, pixels.Color(0, 0, 255));
pixels.setPixelColor(2, pixels.Color(0, 0, 255));
pixels.setPixelColor(3, pixels.Color(0, 0, 255));
pixels.setPixelColor(4, pixels.Color(0, 0, 255));
pixels.setPixelColor(5, pixels.Color(0, 0, 255));
pixels.setPixelColor(6, pixels.Color(0, 0, 255));
pixels.setPixelColor(7, pixels.Color(0, 0, 255));
pixels.setPixelColor(8, pixels.Color(0, 0, 255));
pixels.setPixelColor(9, pixels.Color(0, 0, 255));
pixels.setPixelColor(10, pixels.Color(0, 0, 255));
pixels.setPixelColor(11, pixels.Color(0, 0, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
//Red Side Loop 255,0,0
//Flashes half red/half white for 5 flashes
for(int i=0; i<5; i++){
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL);
pixels.setPixelColor(0, pixels.Color(255, 0, 0));
pixels.setPixelColor(1, pixels.Color(255, 0, 0));
pixels.setPixelColor(2, pixels.Color(255, 0, 0));
pixels.setPixelColor(3, pixels.Color(255, 0, 0));
pixels.setPixelColor(4, pixels.Color(255, 0, 0));
pixels.setPixelColor(5, pixels.Color(255, 0, 0));
pixels.setPixelColor(6, pixels.Color(255, 0, 0));
pixels.setPixelColor(7, pixels.Color(255, 0, 0));
pixels.setPixelColor(8, pixels.Color(255, 0, 0));
pixels.setPixelColor(9, pixels.Color(255, 0, 0));
pixels.setPixelColor(10, pixels.Color(255, 0, 0));
pixels.setPixelColor(11, pixels.Color(255, 0, 0));
pixels.setPixelColor(12, pixels.Color(127, 127 , 127));
pixels.setPixelColor(13, pixels.Color(127, 127 , 127));
pixels.setPixelColor(14, pixels.Color(127, 127 , 127));
pixels.setPixelColor(15, pixels.Color(127, 127 , 127));
pixels.setPixelColor(16, pixels.Color(127, 127 , 127));
pixels.setPixelColor(17, pixels.Color(127, 127 , 127));
pixels.setPixelColor(18, pixels.Color(127, 127 , 127));
pixels.setPixelColor(19, pixels.Color(127, 127 , 127));
pixels.setPixelColor(20, pixels.Color(127, 127, 127));
pixels.setPixelColor(21, pixels.Color(127, 127 , 127));
pixels.setPixelColor(22, pixels.Color(127, 127 , 127));
pixels.setPixelColor(23, pixels.Color(127, 127 , 127));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
Attach to Coupe
You'll need a 1" drill bit and a 3/8" drill bit, and a soldering iron for this part.
I drilled a hole in each headlight, and another hole under the front center for access. I soldered the wires to the ring led's and threaded the wires into the drilled hole. At the bottom you can grab the wires and bring them together. These were then soldered to a piece of heavy phone wire I had in a box, so I could send to the back end.
I then drilled another 1" hole near the back license plate, and was able to fish the phone wire through. Then I was able to get the wires soldered directly onto the Nano.
Next step is to drill a 3/8" hole in the cup holder, and run the USB cable down into. I then fished the USB cable through the 1" hole, and was able to get it plugged into the Nano.
Final step was to then hook up the power, and off we went!
My neighbor has a 3D printer and offered to make some plastic plugs where I drilled the holes.
Final Thoughts
I might add a diffuser to the headlights, as they are pretty bright. I stood outside on a dark night with my neighbor and it ran the flashing loop for a solid 10 minutes without even denting the power supply. So it doesnt seem as if i needed resistors at all.
I thought about adding a switch on the coupe's dashboard for the rider to toggle on/off, but didn't. Adding a simple switch to interrupt the power wouldnt be that hard to do, but it would be more wiring.
I thought about adding lights to the rear of the coupe. That could be done fairly easily.