Introduction: Simple Arduino L.E.D Police Lights

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




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

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!


Comments

D.j.R (author)2017-11-18

question I would like to add a trigger wire to an input pin +5v to activate the program and stop the program when the 5v drops any help would be great

Nidhal Yousuf (author)2015-03-30

i have just tried to make it but it doesnt work .i uploaded the sketch and that was successful.but the led lights are not working

same

HubertC (author)2015-12-28

If you use the code from above you will need to take out the colon before the LOW at about the 6th digitalWrite. digitalWrite(redPin, (needs to be deleted) :LOW); // turn the red light off

the minecrafth (author)HubertC2017-07-29

thx so much :)

PeterQ6 (author)HubertC2016-06-14

Thanks, this helped me solve the error that happened when I copy-pasted the original code.

hhe10 (author)2017-03-29

how do you add a speaker on it. i want to add a siren on it but i cant

GeeL3 (author)2016-10-05

Thanks for posting this up, got an Arduino for my birthday so got hold of some ATTiny85s to make lights for wargaming scenery and this work perfectly with the chips!

bosko90 (author)2016-02-19

Nice project. I will try to make another, like you. I like the way flicker. Some time ago I also did something similar: https://www.youtube.com/watch?v=obikRkdssaE

Nidhal Yousuf (author)2015-03-26

can i do with arduino uno?

anna.ruutna.10 (author)2015-02-25

Arduino: 1.6.0 (Windows 8), Board: "Arduino Uno"

sketch_feb25h.ino: In function 'void loop()':

sketch_feb25h.ino:29:22: error: expected primary-expression before ':' token

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

jerry.daemon (author)2015-01-12

//Most interactive police lights. I reccommend this code.

int yarkost = 50; //The brightness of the LEDs. From 0 to 255

int on_leds[] = {3, 9}; //The pins, which are connected to the LEDs

void setup() {

randomSeed(analogRead(0)); initialization of randomize

}

void loop() {

delay(100);

int red_cy = random(1, 4);

for(int i = 0; i < red_cy; i++){

analogWrite(on_leds[0], yarkost);

delay(70);

analogWrite(on_leds[0], 0);

delay(50);

}

delay(random(50,100));

int blue_cy = random(1, 4);

for(int i = 1; i <= blue_cy; i++){

analogWrite(on_leds[1], yarkost);

delay(70);

analogWrite(on_leds[1], 0);

delay(50);

}

jerry.daemon (author)2015-01-12

You can simplify the code:

void police()

{

for(int i = 0; i < 6; i++){

analogWrite(on_leds[2], yarkost); // turn the red light on

delay(50); // wait 50 ms

analogWrite(on_leds[2], 0);

}

delay(50);

for(int i = 0; i < 6; i++){

analogWrite(on_leds[3], yarkost); // turn the red light on

delay(50); // wait 50 ms

analogWrite(on_leds[3], 0);

}

}

mike.kilroy1 (author)2014-10-22

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?

KegRaider (author)2012-09-14

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

Crimson13 (author)2010-12-23

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.

Wally_Z (author)Crimson132012-05-10

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)

Wally_Z (author)Crimson132012-05-10

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)

krzxsiek (author)2010-09-14

it's very cool simple effect :) thanks ;]

About This Instructable

49,469views

40favorites

License:

More by dave1324:Simple Arduino L.E.D Police Lights
Add instructable to: