Raspberry pi GPIO control : LED controlled by push switch

Raspberry pi GPIO control : LED controlled by push switch

Project Description

led connected to 4th pin of the RPi GPIO push switch connected to 17th GPIO pin

Project Facts

  • Category : Diy
  • Skill : Basic
  • Build by Alex Jolly
  • 726 Hits

Introduction

This is a simple project to demo the GPIO functionality of raspberry pi

Source code

import RPi.GPIO as gpio 
import os 
import time
gpio.setmode(gpio.BCM)
gpio.setwarnings(False)
gpio.setup(17,gpio.IN)
gpio.setup(4,gpio.OUT)
while 1:
      a =gpio.input(17)
     print(a)
    if(a==0):
        gpio.output(4,gpio.HIGH)
   else:
      gpio.output(4,gpio.LOW)

gpio.clear()