Saturday, 27 February 2016

Interfacing PushButton and LED to the Raspberry Pi

 LED is Connected to the 16 board Pin
PushButton is Conencted to the 18 pin using 10k Pullup Resistor
Pushbutton is Connected to the 3.3volts power input aka Pin no1(Caution Here)

import RPi.GPIO as GPIO
import time
import sys

GPIO.setmode (GPIO.BOARD)

LED_PIN = 16
Button_PIN = 18

GPIO.setup(LED_PIN,GPIO.OUT)
GPIO.setup(Button_PIN,GPIO.IN)

while True:
    if(GPIO.input(Button_PIN)):
        GPIO.output(LED_PIN,True)
        time.sleep(1)
        GPIO.output(LED_PIN,False)
        time.sleep(1)
    else :
        GPIO.output(LED_PIN,True)




Output :

 

No comments:

Post a Comment