Sebarahona
Posts: 19
Joined: Wed Jan 18, 2017 2:36 pm

Use a button on the input pin.

Wed Feb 15, 2017 9:24 pm

Hello everyone, I am trying to use the input pins of my RPi. I want to connect a button in one of them, and every time it is pressed, a led will be turned on (which will be connected to another pin, which will be configured as an output). I have seen three possible connections:

1: http://pitando.net/wp-content/uploads/2 ... lsador.png
2: The same as in option 1, but with the electronic components exchanged.
3: The same as in option 1, but with a resistance between the circuit and the input pin.

What is the difference between these and which is more advisable?
Thank!

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: Use a button on the input pin.

Wed Feb 15, 2017 9:53 pm

1: This circuit will work fine, but doesn't have any protection. Here, the input is pulled low when you press the button, so 0 (low) is pressed and 1 (high) is released.

2: This is the same as 1, but instead of being 1 (high) when released, it's 0 (low) and vice versa.

3: The extra resistor is for when you accidentally set the input pin as an output. When the output is 1 (3.3v) and you press the button, there won't be a short to GND cause of this resistor.

Laurens

pcmanbob
Posts: 6708
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Use a button on the input pin.

Wed Feb 15, 2017 9:57 pm

Hi.

That input circuit will work but its better to have a 1K ohm resistor on the input line to the GPIO like the examples shown here
https://www.raspberrypi.org/learning/ph ... l_up_down/
it gives your GPIO some protection should you accidentally set the GPIO to output with the button pressed.

The LED circuit is ok but I would change the resistor to 470 ohm to reduce the current drawn on the GPIO pin.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Sebarahona
Posts: 19
Joined: Wed Jan 18, 2017 2:36 pm

Re: Use a button on the input pin.

Thu Feb 16, 2017 4:43 pm

Laurens-wuyts wrote:1: This circuit will work fine, but doesn't have any protection. Here, the input is pulled low when you press the button, so 0 (low) is pressed and 1 (high) is released.

2: This is the same as 1, but instead of being 1 (high) when released, it's 0 (low) and vice versa.

3: The extra resistor is for when you accidentally set the input pin as an output. When the output is 1 (3.3v) and you press the button, there won't be a short to GND cause of this resistor.

Laurens
Thanks Laurens! Now I understand the difference between these options

Sebarahona
Posts: 19
Joined: Wed Jan 18, 2017 2:36 pm

Re: Use a button on the input pin.

Thu Feb 16, 2017 4:45 pm

Hi, Thanks for your help, this link has dispelled all my doubts about it!

Return to “General discussion”