Simple Arduino L.E.D Police Lights

51,205

40

21

Posted

Introduction: 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.

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

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!


Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest
    • Trash to Treasure

      Trash to Treasure
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    20 Comments

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

    I made police sirens once from a single speaker, any will do (keep it small and pay attention to the required power).

    I used two 555 chips and a couple of resisters and capacitors to get the desired sounds. If you are still interested I can dig out a photo.

    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

    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

    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

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

    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!

    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