Programming Raspberry Pi to Control LED attached to the
GPIO pin
Aim: Programming Raspberry Pi to Control LED attached to the GPIO pin
Objectives:
a. To understand basics of the GPIO Pins of Raspberry Pi.
b. To write a python program to control LEDs attached to the GPIO pins.
Raspberry Pi Pin-out and circuit diagram (GPIO) :
GPIO Pin Connection:
Pin On Kit Pins on Raspberry Pi Module
GPIO Pin Name
LED GPIO 23
GND GND
(Already Connected)
1
Procedure:
Note: The Raspbian operating system comes with a Python already installed in it.
1. Setting up the circuit:
a. Turn OFF the Raspberry Pi while building/connecting on the circuit board/
components according to the diagram.
b. Then turn the Raspberry Pi and check whether the Raspbian OS is loaded
properly or not. If not then check the circuit connection again.
2. Python Programming:
Python via IDLE
a. Start Raspberry Pi in desktop mode, open the applications menu in the top left of
your screen, and navigate to Programming > Python 3 (IDLE). This will open the
Python-shell.
b. Write a program to blink an LED and save it as “[Link]” file name.
Program:
#LED interfacing with Raspberry Pi
import [Link] as GPIO # import GPIO library
import time # import time library
[Link]([Link]) #use BCM pin numbers
[Link](False)
LED=23
[Link](LED,[Link]) # setup pin 23 as output
[Link](1) #time delay for 1sec
while True:
[Link](LED,True) # set LED1 high
[Link](1) # time delay for1 sec
[Link](LED,False) # set LED1 low
[Link](1) # time delay for1 sec
[Link]() #clear all pins
2
Steps to execute Program
1. Make the connections as given above.
2. Open ‘[Link]’ file in python3 IDE
3. Select Run from top menu and click Run Module.