Instructables
Picture of Simple Arduino L.E.D Police Lights

This was one of the first programs i wrote for the arduino after having it a few days :)

we will be making l.e.d police lights with minimal materials




 
Remove these adsRemove these ads by Signing Up

Step 1: You will need.

Picture of You will need.
You will need

Arduino (or suitable clone)
Breadboard
2x 240ohm resistors
1x Clear Red l.e.d
1x Clear Blue l.e.d
Some Jumper Cables

Step 2: Place Components Onto Breadboard

Picture of Place Components Onto Breadboard
DSC02230.JPG
Place the components onto the breadboard as the diagram shows


Step 3: Writing The Code.


The code for this project is very, very basic



// Project 1 - Police Lights by Dave1324

int ledDelay = 50; // delay by 50ms
int redPin = 9;
int bluePin = 11;


void setup() {
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}

void loop() {

digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 50 ms

digitalWrite(redPin, LOW); // turn the red light off
delay(ledDelay); // wait 50 ms

digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 50 ms

digitalWrite(redPin, LOW); // turn the red light off
delay(ledDelay); // wait 50 ms

digitalWrite(redPin, HIGH); // turn the red light on
delay(ledDelay); // wait 50 ms

digitalWrite(redPin, :LOW); // turn the red light off
delay(ledDelay); // wait 50 ms

delay(100); // delay midpoint by 100ms

digitalWrite(bluePin, HIGH); // turn the blue light on
delay(ledDelay); // wait 50 ms

digitalWrite(bluePin, LOW); // turn the blue light off
delay(ledDelay); // wait 50 ms

digitalWrite(bluePin, HIGH); // turn the blue light on
delay(ledDelay); // wait 50 ms

digitalWrite(bluePin, LOW); // turn the blue light off
delay(ledDelay); // wait 50 ms

digitalWrite(bluePin, HIGH); // turn the blue light on
delay(ledDelay); // wait 50 ms

digitalWrite(bluePin, LOW); // turn the blue light off
delay(ledDelay); // wait 50 ms


}



Now upload to your arduino and thats it ! :)


Step 4: Experiment

Now you can experiment with the code

for example:

can you alter the code to power 2 more l.e.d's?

can you alter the code to make the lights flash faster?

Good luck!


This is great! I'm using it to make strobe lights for plowing. So instead of using the resistors and leds I'm using dc to dc solid state relays. those will make the cab marker lights on my truck and 3 interior mounted window lights flash. I just tested it on my test bench and it worked great.... THANKS! Also how would I make this sequence start when I push a momentary button connected to the arduino? or make them stay on if I pushed a different button? what would the code be?
KegRaider2 years ago
I found a slight error in the code. Pretty easy to fix, but a total n00b may not know where it is....

[quoted code]
digitalWrite(redPin, :LOW); // turn the red light off
delay(ledDelay); // wait 50 ms
delay(100); // delay midpoint by 100ms
[/quoted code]

Basically, take out the : from before the LOW command. ;)
Other than that, my young boy loves the lights, thanks.

-KegRaider
Crimson133 years ago
Great instrucable. I'm working on an emergency led lighting system, so this comes in handy.

One thing I would suggest for a smoother pattern, is to add another delay of 100ms at the end of your loop.

Right now it loops from blue-off to red-on without a delay, but the opposite has the 100ms delay at the midpoint. Adding that same midpoint delay at the end will make everything balance out.
I have been researching flash patterns to use with my Arduino, and I have found that this works fairly good:

-Red flashes 3 times (50ms on, 50ms off)
-Blue flashes 3 times (50ms on, 50ms off)
-Alternating flashes of each (back and forth)
I have been researching flash patterns to use with my Arduino, and I have found that this works fairly good:

-Red flashes 3 times (50ms on, 50ms off)
-Blue flashes 3 times (50ms on, 50ms off)
-Alternating flashes of each (back and forth)
krzxsiek4 years ago
it's very cool simple effect :) thanks ;]