Programming Raspberry Pi to get feedback from Switch connected to GPIO pins
Programming Raspberry Pi to get feedback from Switch connected to 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 :
1
GPIO Pin Connections:
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.
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
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)