# Arduino Pushbutton methods

**URL:** <https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527>\
**Category:** Programming\
**Created:** [July 8, 2022, 11:15am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527 "2022-07-08T11:15:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![hksmonaro](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hksmonaro](https://forum.arduino.cc/u/hksmonaro)\
**Post date:** [July 8, 2022, 11:15am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/1 "2022-07-08T11:15:31Z")

</div>

Hi All,

Quick question, i'm looking at pushbuttons integration with current projects. Ive noticed there are two (2) different methods to people have been using.

1. [https://docs.arduino.cc/built-in-examples/digital/Button](https://docs.arduino.cc/built-in-examples/digital/Button)  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/b/c/6bc324e18d6eb0fa2d4bf840e246828b8244379e.png)

or  
2. [https://create.arduino.cc/projecthub/baqwas/push-nano-s-button-395872](https://create.arduino.cc/projecthub/baqwas/push-nano-s-button-395872)  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/9/2/292e64528361672c2f1ed07238e08cfdc34e4d0e.png)

What is the reasons for the different methods, or are they just simply alternative methods for the same outcome?

Cheers,

Nic

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [July 8, 2022, 11:17am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/2 "2022-07-08T11:17:21Z")

</div>

Hello Nic,  
I think you will find the answer here [Buttons and other electro-mechanical inputs (introduction)](https://forum.arduino.cc/t/buttons-and-other-electro-mechanical-inputs-introduction/688576)

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [July 8, 2022, 11:18am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/3 "2022-07-08T11:18:25Z")

</div>

the conventional approach is to connect the button between the pin and ground, configure the pin as INPUT\_PULLUP to use the internal pullup resistor which pulls the pin HIGH and for the button to pull the pin LOW.

---

<div class="post-metadata">

**Author:** ![hksmonaro](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hksmonaro](https://forum.arduino.cc/u/hksmonaro)\
**Post date:** [July 8, 2022, 11:27am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/4 "2022-07-08T11:27:47Z")

</div>

awesome, thanks heaps!

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [July 8, 2022, 11:33am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/5 "2022-07-08T11:33:11Z")

</div>

Note: Your second diagram is wrong. The pull-up resistor goes between the pin and +5V, not between the pin and button switch. The external pull-up can be replaced with the internal pull-up.

An INPUT pin connected to a switch must have a pull-up or pull-down resistor or the value will float randomly between LOW and HIGH when the switch is open.

---

<div class="post-metadata">

**Author:** ![hksmonaro](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hksmonaro](https://forum.arduino.cc/u/hksmonaro)\
**Post date:** [July 8, 2022, 11:46am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/6 "2022-07-08T11:46:33Z")

</div>

but not if you specify INPUT\_PULLUP for the PIN, as its pulled high untill button pressed?

Do you still need a 10k or so resistor between to limit AMPs between PIN and GND when button is pressed or does INPUT\_PULLUP resistor help there?

Cheers

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [July 8, 2022, 11:56am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/7 "2022-07-08T11:56:23Z")

</div>

The input pullup resistor limits the current, you don't need the external resistor at all. You can consider them to be around 50k Ohms, although the value is no accurately specified.

---

<div class="post-metadata">

**Author:** ![paulpaulson](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulpaulson/32/363643_2.png) [@paulpaulson](https://forum.arduino.cc/u/paulpaulson)\
**Post date:** [July 8, 2022, 12:06pm UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/8 "2022-07-08T12:06:39Z")

</div>

Hello  
Take a view to get some ideas how to integrate pushbuttons:

[![](https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0ee1e51f1df32e30893550c85f0dd33244fb0e.jpeg) ](https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0ee1e51f1df32e30893550c85f0dd33244fb0e.jpeg)

Many thanks to LarryD 👋

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [July 8, 2022, 12:23pm UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/9 "2022-07-08T12:23:39Z")

</div>

> [@hksmonaro](#):
>
> Do you still need a 10k or so resistor between to limit AMPs between PIN and GND when button is pressed

You only need a current-limiting resistor between the pin and a load if the pin is set to OUTPUT. For a pin that is INPUT or INPUT\_PULLUP you can connect it to Ground or +5V without a problem. If you fear that a bad sketch will set your pin to OUTPUT you can add a current-limiting resistor but 10k (0.5 mA) is excessively high resistance and may cause input problems. Use more like 240 Ohms. That will limit the current to a safe 21 mA and still allow your INPUT\_PULLUP pin to work reliably.

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [July 8, 2022, 12:59pm UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/10 "2022-07-08T12:59:12Z")

</div>

> [@hksmonaro](#):
>
> but not if you specify INPUT\_PULLUP for the PIN, as its pulled high untill button pressed?

but with the extra 10k resistor, the pin may only be pulled down to a couple volts, not groud

---

<div class="post-metadata">

**Author:** ![hksmonaro](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hksmonaro](https://forum.arduino.cc/u/hksmonaro)\
**Post date:** [July 10, 2022, 12:24am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/11 "2022-07-10T00:24:17Z")

</div>

awesome thanks for the info, just checked the PIN guidelines for the ESP32 and PINs 34/35 i'm going to use dont have internal pullup.

Based on what you said, and setting the PIN to INPUT + 240ohm resistor should still do the trick? Below as an example?

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/7/1/7/717615a1d0cf22d43e83df6e829d00985a317fb4.png)

cheers,

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [July 10, 2022, 12:32am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/12 "2022-07-10T00:32:09Z")

</div>

> [@hksmonaro](#):
>
> 240ohm resistor

why such a small resistor? 13.7 ma (3.3V / 240Ω). why not 10k?

---

<div class="post-metadata">

**Author:** ![hksmonaro](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hksmonaro](https://forum.arduino.cc/u/hksmonaro)\
**Post date:** [July 10, 2022, 5:57am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/13 "2022-07-10T05:57:12Z")

</div>

ok so a 10k resistor to 'act' as an internal pullup and because PIN 34 and 35 are set as anINPUT when the button is pressed the PINs wont draw excessive mA?

---

<div class="post-metadata">

**Author:** ![johnerrington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnerrington/32/340106_2.png) [@johnerrington](https://forum.arduino.cc/u/johnerrington)\
**Post date:** [July 10, 2022, 5:59am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/14 "2022-07-10T05:59:39Z")

</div>

In using a switch or push button to provide a digital input to the Arduino we basically have two options as shown here; to connect one side of the switch or button to the ground 0V rail - or to connect it to the +Vcc rail. The usual (MUCH better) choice is to use a ground connected "normally open" button or switch. This has many advantages - but the "active" (pressed) condition of the button results in a logic "0" and inactive or released condition gives a "1".

> **[skillbank: Experiments and projects with an Arduino microcontroller](https://skillbank.co.uk/arduino/switches.htm)**
>
> Using digital inputs: Switches and buttons

It explains why using method 1 is potentially unsafe, and the design choices in choosing input circuits.

You may also want to look at this if switch bounce will be an issue.

> **[skillbank: Experiments and projects with an Arduino microcontroller](https://skillbank.co.uk/arduino/switchbounce.htm)**
>
> Using digital inputs: Switch bounce and solutions to it

---

<div class="post-metadata">

**Author:** ![hksmonaro](https://avatars.discourse-cdn.com/v4/letter/h/7ba0ec/32.png) [@hksmonaro](https://forum.arduino.cc/u/hksmonaro)\
**Post date:** [July 10, 2022, 10:47am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/15 "2022-07-10T10:47:14Z")

</div>

awesome thanks for that, based on the second link I'm using Bounce2 library and and testing with stable interval or bounce-lockout method of coding.

Seems pretty good so far

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 6, 2023, 10:47am UTC](https://forum.arduino.cc/t/arduino-pushbutton-methods/1010527/16 "2023-01-06T10:47:18Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
