Simple GPIO input/output program for raspberry pi

By: prayag nao

Today we are going to discuss about simple I/O program of raspberry is pin diagram of raspberry.

so we are going to talk about GPIO I/O program then we need 2 pins,one for output and one for input from button.

material required:
  • Raspberry pi.
  • A push Button.
  • some connector wires.
  • A LED.
  • connect 5v pin of raspberry pi to one pin of push button.
  • Now connect one end of push button ti 11th pin of raspberry pi.
  • Now connect 13th pin to +ev pin of led and ground to -ev pin of led (you should use a resistance of 330omhs in series with LED).

  •  open text editor of raspberry pi and paste the following code.
      import GPIO.RPi as GPIO            ##import GPIO library
      import time
      GPIO.setmode(GPIO.BOARD)    ##use board pin numbering
      GPIO.setup(11,GPIO.IN)          ##set 11th pin as Input pin
      GPIO.setup(13,GPIO.OUT)       ## set 13th pin as output pin

      while 1:
        if GPIO.input(11):
             GPIO.output(13,1)  ## Turn on led
             time.sleep(1)           ## 1 second delay
             GPIO.output(13,0)  ## Turn off led
  • Now save the following code with name of
  • Run this code as root user and you will see when we press button led will start blinking in 1 second delay.
For any query pls comment below.


Popular posts from this blog

Solar-Powered Piezoelectric Sports Stadium Breaks Ground in India........:)

Awesome iris mechanism