0% found this document useful (0 votes)
8 views6 pages

Exp2 - Raspberry Pi Interfacing

The document outlines an experiment conducted by a student named Amir Philip Adam, focusing on interfacing an LED with a Raspberry Pi. It includes the aim, components used, theoretical background on GPIO functionality, circuit diagram, procedures for coding, and the resulting program that successfully controls the LED. The experiment demonstrates the ability to turn the LED ON for 1 second and OFF for 2 seconds in a loop, showcasing the Raspberry Pi's GPIO capabilities.

Uploaded by

amirphil38
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)
8 views6 pages

Exp2 - Raspberry Pi Interfacing

The document outlines an experiment conducted by a student named Amir Philip Adam, focusing on interfacing an LED with a Raspberry Pi. It includes the aim, components used, theoretical background on GPIO functionality, circuit diagram, procedures for coding, and the resulting program that successfully controls the LED. The experiment demonstrates the ability to turn the LED ON for 1 second and OFF for 2 seconds in a loop, showcasing the Raspberry Pi's GPIO capabilities.

Uploaded by

amirphil38
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/ 6

University Institute of Engineering

Department of Electronics &Communications


Engineering

Experiment: 2
Student Name: Amir Philip Adam UID: 22BEC10019
Branch: Electronics and Communication Section/Group: 22BEC-2/A
Semester: 6th Date of Performance:13/01/25
Subject Name: Raspberry Pi and its Interfacing
Subject Code: 22ECH-321

1. Aim of the practical:Interfacing LED with Raspberry Pi and Writing a


Program to Turn ON LED for 1 Second After Every 2 Seconds
2. Tool Used/Components:

 Raspberry Pi SBC Model (with microSD card slot).


 MicroSD card (32 GB or higher, preloaded with Raspberry Pi OS).
 HDMI cable and compatible monitor.
 USB keyboard and mouse.
 Power supply (5V, 3A).
 Breadboard.
 Jumper wires.
 5mm LED.
 220-ohm resistor (to limit current).

3.Theory:
The General Purpose Input/Output (GPIO) pins on Raspberry Pi allow hardware control and
interfacing. A basic example of GPIO functionality is turning an LED ON and OFF.

 Digital Output: Raspberry Pi GPIO pins can output HIGH (3.3V) or LOW (0V) states.
 LED Operation: A digital HIGH state can illuminate an LED connected through a current-
limiting resistor. Toggling the state in a time sequence can create a blinking effect.

1
University Institute of Engineering
Department of Electronics &Communications
Engineering

4. Circuit Diagram:
 Connect the longer leg (anode) of the LED to a GPIO pin (e.g., GPIO 2) via a 330 Ω resistor.
 Connect the shorter leg (cathode) of the LED to the GND pin of the Raspberry Pi.

Fig 2.1 shows the circuit for interfacing an LED with Raspberry Pi 5.

5. Proceedures
 Connect the components as per the circuit diagram.
 Open any code editor or IDE eg Thonny,Nano or VS Code.
 Open terminal and run the command: sudo apt install python3 gpiozero.
 Write the Python program to control the LED.
 Save the Python code with .py extension.
 Run the programming by the command sudo python3 file_name.py

2
University Institute of Engineering
Department of Electronics &Communications
Engineering

6. Code

A.Code to blink through looping

from gpiozero import LED


from time import sleep

led=LED(2)
try:
while True:
led.on()
sleep(1)
led.off()
sleep(2)
except KeyboardInterrupt:
Print(“Program stopped by the user”)

B. Code to blink LED with user command

from gpiozero import LED


from time import sleep

# Initialize the LED on GPIO pin 2


led = LED(2)

try:
while True:
signal = int(input("Enter the signal (0 or 1): "))
if signal == 1:
led.on() # Turn LED ON
print("LED is ON")
elif signal == 0:
led.off()
print("LED is OFF")

else:
print("Invalid signal, please enter 0 or 1")
except KeyboardInterrupt:
print("Program stopped by the user")
finally:
led.close()

3
University Institute of Engineering
Department of Electronics &Communications
Engineering

7. Screenshots

Fig 2.2 shows VS Code editor where the Program to blink an LED is written.

Fig 2.3 shows the blinking circuit of an LED.

4
University Institute of Engineering
Department of Electronics &Communications
Engineering

8. Result

The LED was successfully interfaced with the Raspberry Pi. The program successfully turned the LED ON
for 1 second and OFF for 2 seconds in a continuous loop, demonstrating the GPIO control functionality of
the Raspberry Pi.

5
University Institute of Engineering
Department of Electronics &Communications
Engineering

9. Evaluation Grid (To be filled by Faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1. Student Performance 12
(Conduct of experiment)
objectives/Outcomes.
2. Viva Voce 10
3. Submission of Work 8
Sheet
(Record)
Signature of Faculty Total Marks Obtained: 30
(with Date):

You might also like