Electronics 101 - Blinking LED

July 16, 2018
electronics led

Parts

  • 1x Raspberry PI
  • 1x LED
  • 1x 220Ω resistor
  • 2x jumper cables

Schematics

Fritzing schematics

Connect the long leg (positive, anode) to pin GPIO23 on Raspberry and the short leg (negative, diode), via a 220Ω resistor to GND.


Python Code

from gpiozero import LED
from time import sleep

led_pin = 23 # BCM
timeout = 0.25  # seconds

led = LED(led_pin)

try:
    while True:
        led.on()
        sleep(timeout)
        led.off()
        sleep(timeout)
except KeyboardInterrupt:
    led.off()