This tutorial provide step by step instruction to perform Switch Interfacing with Raspberry Pi and its Python program.
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) while True: input_state=GPIO.input(18) if input_state == False: print('Botton pressed') else: print('Buttom not pressed') time.sleep(1)