Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
74 views

Programming Raspberry Pi to get feedback from Switch connected to GPIO pins

The document outlines a project aimed at programming a Raspberry Pi to receive feedback from switches connected to its GPIO pins and control LEDs. It includes objectives, a circuit diagram, GPIO pin connections, and a step-by-step procedure for setting up the circuit and writing a Python program. The provided code demonstrates how to interface the switches and LEDs using the RPi.GPIO library.

Uploaded by

gangurdesahil52
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Programming Raspberry Pi to get feedback from Switch connected to GPIO pins

The document outlines a project aimed at programming a Raspberry Pi to receive feedback from switches connected to its GPIO pins and control LEDs. It includes objectives, a circuit diagram, GPIO pin connections, and a step-by-step procedure for setting up the circuit and writing a Python program. The provided code demonstrates how to interface the switches and LEDs using the RPi.GPIO library.

Uploaded by

gangurdesahil52
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Raspberry Pi to get feedback from a switch

connected to the GPIO pins


Aim: Programming Raspberry Pi to get feedback from a switch connected to the GPIO pins.

Objectives:
a. To understand some basics of the GPIO Pins of Raspberry Pi.
b. Write a python program to get feedback from a switch connected to GPIO pins
& also to control LEDs attached to the GPIO pins.
Raspberry Pi GPIO Pins :

Circuit/ Block Diagram:

1
GPIO Pin Connections:

Pin On Kit Pins on Raspberry Pi Module

GPIO Pin Name

LED 1 GPIO 14

LED 2 GPIO 15

Switch 1 GPIO 20

Switch 2 GPIO 21
GND GND
(Already Connected)
Procedure:

Note: The Raspbian operating system comes with the Python already installed in it.

1. Setting up the circuit:


a. Turn OFF the Raspberry Pi while building/ connecting the circuit board/
components according to the diagram.
b. Then turn the Raspberry Pi and check the Raspbian OS 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 for LED and a feedback switch interfacing with Raspberry Pi.
3. Steps to execute Program

1. Make connections as given above.


2. Open ‘led.py’ file in python3 IDE.
3. Select Run from top menu and click Run Module.
2
4. Program: #LED and Switch interfacing

import RPi.GPIO as GPIO


import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

SWITCH1 =20
LED1 =14

SWITCH2 =21
LED2 =15

GPIO.setup(SWITCH1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(SWITCH2,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(LED1,GPIO.OUT)
GPIO.setup(LED2,GPIO.OUT)
while True:
new_input_state = GPIO.input(SWITCH1)
new_input_state = GPIO.input(SWITCH2)
if new_input_state= =False:
GPIO.output(LED1,True)
GPIO.output(LED2,True)
else:
GPIO.output(LED1,False)
GPIO.output(LED2,False)

You might also like