www.techvilla.org.in
TECHVILLA
www.techvilla.org.in
www.techvilla.org.in
Interfacing a push button
 read data through GPIO.
 read the value of a push button on a breadboard.
 Writing a code to detect a push button being switched on/off .
www.techvilla.org.in
Button circuit
www.techvilla.org.in
Writing the code
 On the terminal type : nano button.py
 Write following code.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state == False:
print('Button Pressed')
time.sleep(0.2)

Rasperry pi Part 15