Blinking an LED with Raspberry Pi GPIO
- Oct 4, 2025
- 2 min read
We teach and learn by making !
At Haruki Robotics Lab, students learn how to combine electronics and coding to create real‑world effects. In this beginner‑friendly project, we use Python and the RPi.GPIO library to make an LED blink. This experiment introduces core skills in electronics, programming loops, and hardware control.


T-Board Name | physical | wiringPi | BCM |
GPIO17 | Pin 11 | 0 | 17 |
Python Code
import RPi.GPIO as GPIO
import time
LedPin = 17
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(LedPin, GPIO.OUT, initial=GPIO.HIGH)
def main():
while True:
print('...LED ON')
GPIO.output(LedPin, GPIO.LOW)
time.sleep(0.5)
print('LED OFF...')
GPIO.output(LedPin, GPIO.HIGH)
time.sleep(0.5)
def destroy():
GPIO.output(LedPin, GPIO.HIGH)
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
main()
except KeyboardInterrupt:
destroy()How It Works
GPIO.setmode(GPIO.BCM): Uses Broadcom (BCM) pin numbering for consistent references.
GPIO.setup(LedPin, GPIO.OUT): Sets the LED pin (GPIO 17) as an output pin.
GPIO.output(LedPin, GPIO.LOW): Turns the LED ON (because it’s connected to 3.3V through a resistor).
GPIO.output(LedPin, GPIO.HIGH): Turns the LED OFF.
time.sleep(0.5): Waits half a second between each blink.
GPIO.cleanup(): Resets all pins when you stop the program safely.
⚙️ Connect your LED correctly: - The longer leg (anode) goes to GPIO 17 through a 220 Ω resistor. - The shorter leg (cathode) goes to a GND pin on the Raspberry Pi.
Learning Goals
Understand what GPIO pins are and how to use them with Python.
Write loops to control real‑world hardware.
Safely set up and clean up GPIO resources.
Experiment Variations
Change time.sleep(0.5) to 1 or 0.1 to make the LED blink slower or faster.
Add more LEDs to different GPIO pins to create light patterns.
Learn about GPIO.PWM to fade LEDs smoothly.
Troubleshooting Tips
Make sure your LED is connected to the correct pin (GPIO 17).
If nothing happens, double‑check your resistor and ground connections.
Run the script with sudo python3 led_blink.py to ensure GPIO access.
At Haruki Robotics Lab, we teach and learn by making. Blinking an LED might seem simple, but it’s the first step toward building robots that signal, react, and communicate using sensors and light.



Comments