← Back to projects
Ambulance Lights

Ambulance Lights

Emergency vehicles have a very distinctive visual signature — a rapid, alternating flash of red and blue lights that instantly grabs attention. With just two LEDs, a Raspberry Pi and Pi4J we can recreate that effect on a breadboard.

This project builds directly on the Blink LED example. Instead of a single LED going on and off, we alternate two LEDs so that when one is on, the other is off.

Source code: projects/ambulance/Ambulance.java

What You Will Learn

  • How to control multiple GPIO pins from Java with Pi4J
  • How to alternate outputs to create a "flashing" effect
  • How timing changes the perceived intensity of the flash
  • How to organize a small Pi4J program with more than one LED

Components

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

Wiring

  1. Connect the anode (longer leg) 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 (shorter legs) to any GND pin on the Pi.
  4. Double-check the polarity before powering the Pi.

How It Works

The program configures two GPIO pins as digital outputs, one for each LED. Inside a loop it turns the red LED on and the blue LED off, waits a short delay, then flips them. Repeating this cycle produces the alternating flash you see on real ambulances.

Shorter delays give a nervous, urgent flash. Longer delays feel calmer and closer to a warning beacon. Play with the timing until it feels right.

Possible Enhancements

  • Add a small buzzer for a siren sound
  • Add a physical button to start and stop the flashing
  • Use PWM to fade between the two lights instead of a hard switch
  • Add extra LEDs on each side to build a full light bar

Why It Matters

This is a tiny project, but it is the first step toward more expressive lighting patterns: police cars, tow trucks, fire engines, disco lights. Any effect that alternates between two states is essentially this program with different colors and timings.