PyRaspBeta

← All practice problems

Raspberry Pi practice problem · LEDs & PWM

Two LEDs, two wires

MediumBudget $4Python · gpiozero

An LED only conducts one way, so two LEDs wired back to back between the same two pins can be lit separately — this is the trick behind bi-colour LEDs.

Wire, each LED with its own 330 Ω resistor:

  • GPIO17 → resistor → red LED → GPIO27
  • GPIO27 → resistor → green LED → GPIO17

(no connection to GND). Then loop every 1.5 s:

timeGPIO17GPIO27result
0–0.5 shighlowred on
0.5–1.0 slowhighgreen on
1.0–1.5 shighhighboth off

The "off" phase must use both pins high — no voltage difference, no current.

More in LEDs & PWM