Pi Switch Control

Determine if switches are on (high) or off (low)

1
2
3
4
5
6
7
8
9
10
11
12
import RPi.GPIO as GPIO

GPIO.setwarnings(False) # Ignore warning for now
GPIO.setmode(GPIO.BOARD) # Use physical pin numbering

GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial value to be pulled low (off)

print("Waiting for button push")

while True: # Run forever
if GPIO.input(10) == GPIO.HIGH:
print("Button was pushed!")

References