Ivan219
Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Connect button to raspberry pi and choose resistors

Sat Jan 02, 2016 5:16 pm

Good afternoon, studying the connection button to raspberry pi through gpio. I watched this video: http://www.youtube.com/watch?v=Bqk6M_XdIC0
Can I use a resistor instead of 10kOm 2,2kOm, and what will drive current? Correctly calculated as: I = 3,3 / 2200 = 1.5 mA = 0.0015A
I = 3,3 / 10,000 = 0.33 = 0.00033A mA or not?
And instead of 1 kW use the same 2.2 ohms?
I = 3,3 / 2200 = 1.5 mA = 0.0015A
I = 3,3 / 1000 = 3.3 mA = 0.0033A
Image

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Connect button to raspberry pi and choose resistors

Sat Jan 02, 2016 6:16 pm

Short answer:
yes.

Longer answer:
Your first two calculations are correct - 2.2kΩ will take 1.5mA, 10kΩ will take 330μA from the supply when the switch is pressed.

You could use a smaller resistor - 1kΩ, or if you're daring, 330Ω - the only effect will be to waste power, so long as the supply can provide the current.
You could go higher - 50kΩ, 100kΩ - but you may find the Pi suffers from false triggering from interference
I tend to use 1kΩ, not because that's the best value, but because I got a reel of a thousand of them just before I retired. When those are all used up, I'll swap to 10kΩ, of which I've only got 500

The second pair of calculations, while correct in themselves, don't really apply in this situation.
R2 is only there for protection, in case your program sets the GPIO as an output.
As an input, no current flows through it, so its value is unimportant.
Too low a value will provide no protection (you don't want more than, say, 8mA to flow out of a GPIO in a fault situation), and too high will allow false triggering. Anywhere between 300Ω and 10kΩ would work.

Ivan219
Posts: 118
Joined: Sun Jul 05, 2015 10:01 pm

Re: Connect button to raspberry pi and choose resistors

Sat Jan 02, 2016 7:38 pm

Thank for reply! Can I connect to any GPIO-digital-port? And for 3 or 4 or 14 or 11 gpios?

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Connect button to raspberry pi and choose resistors

Sun Jan 03, 2016 11:00 am

Almost any GPIO (some are defined as UART or SPI or other interface, so extra programming is required)

Image
GPIO-3 is the clock for I2c. I'd keep away from that for the moment, though you can use it if you want.
GPIO-4 is ok
GPIO-14 is TXD. I'd keep away from that for the moment, though you can use it if you want.
GPIO-11 is SPI clock. I'd keep away from that for the moment, though you can use it if you want.

User avatar
lalberry
Posts: 1
Joined: Fri Mar 29, 2019 4:15 am

Re: Connect button to raspberry pi and choose resistors

Fri Mar 29, 2019 5:29 am

hi everybody,
Today I joined Raspberry community migrated from Arduino, the subject is very interesting for the beginners I request to post a C program to print "Button pressed" on pressing the switch connected to GPIO for both the conditions either pull up or pull down.
Regards
Lalit

Return to “Beginners”