Making LED High And Low Using Push Button In Raspberry Pi

Introduction

In this article, I am going to explain about making LED high and low, using push button In Raspberry Pi. It will operate with one push button, which acts as high and another push button, which can act as low.

Parts Of Lists

  • Raspberry Pi Board
  • Push Button-2
  • Led-1
  • Bread Board
  • Hook Up Wires
  • Resistor-2.

Parts Explanation

In the article, I have already explained about Raspberry Pi, LED, Bread Board, Resistor. Now, I am going to explain about the push button and its uses.

Push button

 Push Button

  • A push-button (also spelled pushbutton) or simply button is a simple switch mechanism to control some aspect of a machine or a process. Buttons are typically made out of hard material, usually plastic or metal.
  • The surface is usually flat or shaped to accommodate the human finger or hand, so as to easily press or push. Buttons are most often biased switches, though even many un-biased buttons (due to their physical nature) require a spring to return to their un-pushed state.
  • Different people use different terms for the "pushing" of the button, such as press, depress, mash, hit and punch.

Uses

  • In industrial and commercial Applications, push buttons can be connected together by a mechanical linkage, so that the act of pushing one button causes the other button to be released.
  • In this way, a stop button can "force" a start button to be released.
  • This method of linkage is used in simple manual operations in which the machine or process has no electrical circuits for control.

Let's Start Connecting the Parts with the RPI

  • First step is to connect the First push button to RPI
  • Second step is to connect the Second push button to RPI.

  • PUSH BUTTON GPIOPIN
    First Push Button 11
    Second Push Button 12

  • Connect the Resistor also on the positive side and connect the negative side with the 5V.
  • Connect the GND side to the GND of the GPIO.
  • Connect LED's positive pin to the 13 of the GPIO
  • Connect the negative pin to the GND side.

Programming Part

  1. import RPi.GPIO as GPIO  
  2. import time  
  3.   
  4. GPIO.setmode(GPIO.BCM)  
  5. GPIO.setup(13, GPIO.OUT)  
  6.   
  7. GPIO.setup(11, GPIO.IN, pull_up_down = GPIO.PUD_UP)  
  8. GPIO.setup(12, GPIO.IN, pull_up_down = GPIO.PUD_up)  
  9.   
  10. while True:  
  11.     input_state = GPIO.input(11)  
  12. GPIO.output(13, 0)## Turn ON HIGH  
  13. if input_state == True:  
  14.     input_state = GPIO.OUTUT(12)  
  15. GPIO.Output(13, 0)## Turn ON LOW  
  16. if input_state == False:  
  17.     print('Button Pressed')  
  18. time.sleep(0.2)  
Programming Explanation

In this program, I have simply explained about the brightness and dimness of the LED. It will operate when the First push button is pressed, it will be on the high and when the second Push button is pressed, it will be on the low.
  1. input_state = GPIO.input(11)  
  2. GPIO.output(13, 0)## Turn ON HIGH  
  3. if input_state == True:  
  4.     input_state = GPIO.OUTUT(12)  
  5. GPIO.Output(13, 0)## Turn ON LOW  
  6. if input_state == False:  
According to the connection, it will be high or low.

Output

button