0% found this document useful (0 votes)
7 views3 pages

LED-Interfacing-Raspberry Pi (2)

This document outlines the process of programming a Raspberry Pi to control an LED using GPIO pins. It includes objectives, a circuit diagram, and a step-by-step procedure for setting up the circuit and writing a Python program to blink the LED. The program utilizes the RPi.GPIO library and provides instructions for executing the code in the Python IDE.

Uploaded by

samsonpillai1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

LED-Interfacing-Raspberry Pi (2)

This document outlines the process of programming a Raspberry Pi to control an LED using GPIO pins. It includes objectives, a circuit diagram, and a step-by-step procedure for setting up the circuit and writing a Python program to blink the LED. The program utilizes the RPi.GPIO library and provides instructions for executing the code in the Python IDE.

Uploaded by

samsonpillai1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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 “LED.py” file name.

Program:
#LED interfacing with Raspberry Pi

import RPi.GPIO as GPIO # import GPIO library


import time # import time library
GPIO.setmode(GPIO.BCM) #use BCM pin numbers
GPIO.setwarnings(False)

LED=23
GPIO.setup(LED,GPIO.OUT) # setup pin 23 as output
time.sleep(1) #time delay for 1sec
while True:
GPIO.output(LED,True) # set LED1 high
time.sleep(1) # time delay for1 sec
GPIO.output(LED,False) # set LED1 low
time.sleep(1) # time delay for1 sec

GPIO.cleanup() #clear all pins

2
Steps to execute Program

1. Make the connections as given above.


2. Open ‘led.py’ file in python3 IDE
3. Select Run from top menu and click Run Module.

You might also like