Electronics All-in-One For Dummies
Book image
Explore Book Buy On Amazon
In this simple electronics project, you get to build a simple breadboard circuit that connects an LED to a Raspberry Pi via the GPIO port on pin 3 of the header. The figure shows the completed project.

electronics-flasher
The Raspberry Pi LED Flasher (Project 55).

In this project, you connect an external LED to a Raspberry Pi, and then use a simple sketch to turn the LED on and off at 0.5-second intervals.

electronics-sketch-a

Parts needed to build an LED flasher

  • One Raspberry Pi 2 or 3 with Raspbian installed, connected to a monitor, keyboard, and power
  • One small solderless breadboard (RadioShack 2760003)
  • One 5mm red LED (RadioShack 2760209)
  • One resistor (orange-orange-brown)
  • Two jumper wires (M/F)
electronics-sketch-b

Steps for building an LED flasher

  1. Insert resistor R1.

    R1 – 330 Ω: A3 to ground bus

  2. Insert LED1.

    Cathode (short lead): D5 Anode (long lead): D3

    electronics-cathode

  3. Connect the ground bus to the Raspberry Pi header pin 2. Use a jumper to connect any hole in the ground bus on the breadboard.
  4. Connect pin 3 on the Raspberry Pi A5 on the breadboard.
  5. Open the Python 2 IDLE Editor with root privileges.
  6. Create and save the sketch shown here, using the filename LedBlink. import RPi.GPIO as GPIO import timeGPIO.setmode(GPIO.BOARD) GPIO.setup(3, GPIO.OUT) while True: GPIO.output(3, GPIO.HIGH) time.sleep(0.5) GPIO.output(3, GPIO.LOW) time.sleep(0.5)
  7. Run the LedBlink program by choosing Run →  Run Module (or press F5). The LED on the breadboard will flash on and off at half-second intervals.

About This Article

This article is from the book:

About the book author:

Doug Lowe is the bestselling author of more than 40 For Dummies books. He's covered everything from Microsoft Office to creating web pages to technologies such as Java and ASP.NET, and has written several editions of both PowerPoint For Dummies and Networking For Dummies.

This article can be found in the category: