Learn

Driving a 12V Warning Beacon Light from a Raspberry Pi 4B

Wire a 12V warning beacon (LED strobe or rotating) to a Raspberry Pi 4B through an NPN transistor and a 12V battery — why a GPIO pin can never drive a beacon directly, and why a rotating beacon needs a flyback diode.

Note: the Beacon Light (12V) is a Premium-tier component in the simulator — you’ll need a Premium or VIP plan to use it there.

Try this directly in the free Raspberry Pi 4B simulator — no hardware or signup required. New to the GPIO header? Start with the interactive pinout guide.

What you’ll need

  • Raspberry Pi 4B
  • Beacon Light (12V)
  • Battery (12V 7Ah, SLA)
  • NPN Transistor (2N2222 or BC547)
  • Resistor (~1kΩ, for the transistor's base)
  • Diode (only if using the rotating beacon)

Step by step

  1. Drag Raspberry Pi 4B onto the Canvas.
  2. Drag the Beacon Light onto the Canvas — it's canvas-only (drawn wires, not a breadboard part), matching a real beacon's roof-mount body and flying-lead cable.
  3. Hover its two pins to confirm the labels: +12V and − (GND). Open its settings panel to choose LED or Rotating, pick a lens color, and set its rated current (0.1A–3A, defaulting to a typical 0.8A LED strobe).

A beacon draws far more current (roughly 0.1A–3A) than a Pi GPIO pin can ever supply (community figures put the safe limit around 16mA per pin) — wiring +12V or − directly to a GPIO pin doesn't just risk the Pi, this simulator won't light the beacon at all and logs a warning instead. A beacon must always be switched through a transistor.

  1. Drag a Battery (12V 7Ah, SLA) onto the Canvas — this is the beacon's own 12V supply, separate from the Pi.
  2. Wire the battery's + terminal → the beacon's +12V pin.
  3. Drag an NPN Transistor onto the Canvas. Wire the beacon's − pin → the transistor's Collector, and the transistor's Emitter → the battery's − terminal (also tie the battery's − terminal to a Pi GND pin, so the Pi and the 12V circuit share a common ground).

The transistor's Collector/Emitter legs are labeled Leg 1 and Leg 3 in this simulator — hover them to see which is which for your chosen transistor type (2N2222: Leg 1 = Emitter, Leg 3 = Collector; BC547: the opposite way around).

  1. Wire a Resistor between a Pi GPIO pin and the transistor's Base — this limits the base current the same way a resistor limits current into an LED.
  2. If you picked the Rotating beacon type, wire a Diode directly across the beacon's own two terminals (cathode toward +12V) — a real spinning motor generates a voltage spike when its coil switches off, and this flyback diode gives that spike somewhere safe to go. Skip this step for the LED strobe type; an LED beacon has no motor coil to protect.
  3. Go to the Code tab and write a script that toggles the beacon through the transistor's base:
import RPi.GPIO as GPIO
import asyncio
 
GPIO.setmode(GPIO.BOARD)
BEACON_BASE = 37 # adjust to match your wiring
 
GPIO.setup(BEACON_BASE, GPIO.OUT)
 
while True:
GPIO.output(BEACON_BASE, GPIO.HIGH) # drives the transistor's base HIGH — beacon on
print("Beacon ON")
await asyncio.sleep(3)
 
GPIO.output(BEACON_BASE, GPIO.LOW) # beacon off
print("Beacon OFF")
await asyncio.sleep(3)
  1. Click Start.

What “working correctly” looks like

  • Driving the base pin HIGH lights the beacon — an LED beacon strobes in its chosen color, a rotating beacon spins its beam — and driving it LOW turns it off, in sync with the Console's printed "Beacon ON"/"Beacon OFF" lines.
  • The flash/rotation speed scales with the battery's actual voltage — a fully-charged 12V battery runs at normal speed; a battery that's drained below about 9V runs the beacon too slow to light at all.
  • Wiring the beacon's +12V or − pin directly to a Pi GPIO pin (instead of through the battery/transistor) logs a Console warning and the beacon never lights, regardless of what your script does.
  • Choosing the Rotating beacon type with no flyback diode wired across its terminals still lights it, but logs a "NO DIODE" warning — an educational nudge, not a hard block, since this simulator can't actually be damaged the way real hardware could.

If something’s wrong

  • The beacon never lights, and the Console shows a wiring warning → confirm the beacon's +12V/− pins connect only to the battery and transistor, never directly to a Pi GPIO pin.
  • The beacon lights but very dimly or not at all, with an overload-style warning → your beacon's rated current exceeds what your chosen transistor can carry (2N2222: 600mA max, BC547: 100mA max) — lower the rated current in the settings panel or switch to a 2N2222.
  • You see a "NO DIODE" warning → you picked the Rotating beacon type; wire a Diode directly across the beacon's own +12V and − pins (cathode toward +12V) to clear it.
  • The beacon does nothing at all when Start is clicked → double-check the transistor's Base is wired through a resistor to a GPIO pin your script actually drives, and that the Battery's − terminal reaches both the transistor's Emitter and a real Pi GND pin.