Arduino Police Lights

Difficulty Level = 4 [What’s this?]

This is an amusing project inspired by flashing blue and red lights on police cars, ambulances, etc.  This is a perf board Arduino with 5 blue and 5 red LEDs, and the Arduino code lights them up in a pattern similar to police lights.

First, the Arduino built on a perf board.  It’s not hard to build your own Arduino.  I use a real Arduino board to upload code to the ATMega328 chip, then just move it to the project board.

Perfboard Arduino with blue and red LEDs for police lights mini-project

Now here it is in action — I really think if you don’t know what you’re looking at, it looks realistic in the dark.

Here’s the code that makes it work. Notice that some of the LEDs are controlled using PWM; the second and fourth LED in each of the blue and red groups. I would invite people to build something similar and tweak this to get the most realistic effect possible!

#define NUM_OFF 3
#define DELAY 50
#define PWM_MIN 10
#define PWM_MAX 128

int blue[5];
int red[5];

void setup()
  blue[0] = 19;
  blue[1] = 5;
  blue[2] = 18;
  blue[3] = 6;
  blue[4] = 17;
  red[0] = 13;
  red[1] = 11;
  red[2] = 12;
  red[3] = 10;
  red[4] = 9;

  for(int i=0;i<5;i++) {
    pinMode(blue[i], OUTPUT);
    pinMode(red[i], OUTPUT);

void loop()
  analogWrite(blue[1], random(PWM_MIN, PWM_MAX));
  analogWrite(blue[3], random(PWM_MIN, PWM_MAX));
  analogWrite(red[1], random(PWM_MIN, PWM_MAX));
  analogWrite(red[3], random(PWM_MIN, PWM_MAX));

  for(int i=0;i<NUM_OFF;i++) {
    digitalWrite(blue[random(5)], LOW);
    digitalWrite(red[random(5)], LOW);

void allOn() {
  for(int i=0;i<5;i++) {
    digitalWrite(blue[i], HIGH);
    digitalWrite(red[i], HIGH);

Published by Michael, on January 8th, 2010 at 10:03 pm. Filed under: Arduino,Level 4. | 3 Comments |

3 Responses to “Arduino Police Lights”

  1. New to all of this, so sorry for the dumb questions. How do I get this to run on my UNO board first ? I assume Blue (0) = 19 means pin 19 on the 328 so how does that correlate to the UNO board pins. Can you give me that pinout please ???

    Comment by Rich Russo on September 22, 2014 at 9:40 AM

  2. Why not google for “Arduino pinout”? That would be a much easier way to find the info you are looking for.

    Comment by Michael on September 22, 2014 at 10:32 AM

  3. I have the starter kit and yes I see Digital I/O pins. So Just randomly choose 10 pins starting with D2 ? Change your code to reflect the new pins ??

    Comment by Rich Russo on September 22, 2014 at 12:02 PM

Leave a Reply