← Back to projects
Police Lights

Police Lights

Police cars use a much more aggressive light pattern than a simple back-and-forth. Each side of the light bar usually fires two or three quick strobes before the other side takes over. That double-flash rhythm is instantly recognizable.

In this project we simulate that effect using two LEDs — one red and one blue — controlled from a Raspberry Pi with Pi4J. It is a natural next step after the Ambulance Lights project.

Source code: projects/police/Police.java

What You Will Learn

  • How to build more complex blinking patterns with nested loops
  • How to control two LEDs with independent timings
  • How rhythm and grouping change the visual "personality" of a light
  • How to keep GPIO code readable when patterns become more elaborate

Components

  • Raspberry Pi
  • 1 red LED
  • 1 blue LED
  • 2 × 220Ω resistors
  • Breadboard
  • Jumper wires

Wiring

  1. Connect the anode of the red LED to a GPIO pin through a 220Ω resistor.
  2. Connect the anode of the blue LED to another GPIO pin through a 220Ω resistor.
  3. Connect both cathodes to any GND pin on the Pi.

How It Works

The program configures two GPIO pins as digital outputs. Instead of a simple alternating flash, each side fires three quick strobes before handing over to the other side. A short delay between the two bursts sells the "police strobe" feel.

The pattern is essentially:

  1. Red strobes three times, very fast.
  2. Short pause.
  3. Blue strobes three times, very fast.
  4. Short pause.
  5. Repeat.

Tweaking the number of strobes and the on/off durations gives you a whole family of related effects.

Possible Enhancements

  • Add a siren tone with a piezo buzzer
  • Add more LEDs on each side for a fuller light bar
  • Randomize the number of strobes per burst for a more chaotic effect
  • Trigger the pattern with a button press

Why It Matters

Once you can time nested patterns like this, you can drive almost any real-world signal light: fire trucks, tow trucks, road hazard beacons, and construction lights. It is a great exercise in structuring blinking code that goes beyond a single loop.