# Pushbutton and Pull-Up Resistor

**URL:** <https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448>\
**Category:** General Guidance\
**Created:** [July 17, 2015, 9:31pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448 "2015-07-17T21:31:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BielMB](https://avatars.discourse-cdn.com/v4/letter/b/87869e/32.png) [@BielMB](https://forum.arduino.cc/u/BielMB)\
**Post date:** [July 17, 2015, 9:31pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/1 "2015-07-17T21:31:10Z")

</div>

Hi.

I have a doubt about if i should use a pullup resistor, when using the Default Button Exemple Code from Arduino IDE.

The idea is: to leave the pin13 LED ON and turn it off when i push the button. I wired as the pictures attached, both gave me the same result. But in the second one, i removed the pullup resistor.

The question, should i leave the pullup resistor or it's indifferent?

I need to understand the difference, because i'm working with this UnoJoy project, and to make the buttons work, i have to wire exactly as show in the pictures (not sure if it's correct, or if i should wire it another way)

Thanks guys!

Gabriel.

 ![model_1.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/2/e/f/2efb66b21826191bfc40d613b919cf8bc9dd484c.jpeg)

 ![model_2.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/1/d/3/1d3017f75fb7dfef165f4bfd8dcd52707f90196e.jpeg)

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [July 17, 2015, 9:34pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/2 "2015-07-17T21:34:37Z")

</div>

Not wired properly.  
The resistor should be on the blue wire (pin 2) then to +5V.

---

<div class="post-metadata">

**Author:** ![Hutkikz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hutkikz/32/218764_2.png) [@Hutkikz](https://forum.arduino.cc/u/Hutkikz)\
**Post date:** [July 17, 2015, 9:43pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/3 "2015-07-17T21:43:58Z")

</div>

As LarryD says the resistor should keep pin 2 pulled up to 5v when the button is not pushed otherwise it can float ( read either high or low at any time) .

Arduino has a built in pull up resistor on all I/o pins that can be activated by using INPUT\_PULLUP  
So the resistor is not really necessary .

---

<div class="post-metadata">

**Author:** ![BielMB](https://avatars.discourse-cdn.com/v4/letter/b/87869e/32.png) [@BielMB](https://forum.arduino.cc/u/BielMB)\
**Post date:** [July 17, 2015, 9:47pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/4 "2015-07-17T21:47:14Z")

</div>

I just copied the circuit on the Button Tutorial at Arduino.cc, the i wired GND and VCC on the opposite way to make the LED stays ON and turn OFF only the button is pressed.

But okay, i'll remake the circuit. Only question: WHY!?

I'm attaching a picture just to make sure. Is it correct?

 ![model_3.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/3/2/b/32bf26a32254146f431ae953dc4a2c210d6e2da6.jpeg)

---

<div class="post-metadata">

**Author:** ![DrAzzy](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@DrAzzy](https://forum.arduino.cc/u/DrAzzy)\
**Post date:** [July 17, 2015, 9:51pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/5 "2015-07-17T21:51:38Z")

</div>

Model 2 will work if you use INPUT\_PULLUP.

Model 1 will never work because it is wired improperly - the two pins each side of the switch are internally connected. That means that either: the pullup is trying to pull up the side of the switch that is grounded; the pullup would need to go to the side of the switch that has the digital pin connected to it - OR - the pin and ground are connected, and pressing the button connects the pullup.

Part of the problem is that in the stupid fritzing diagrams, it's not clear which way the button is oriented.

---

<div class="post-metadata">

**Author:** ![jboyton](https://avatars.discourse-cdn.com/v4/letter/j/e36b37/32.png) [@jboyton](https://forum.arduino.cc/u/jboyton)\
**Post date:** [July 17, 2015, 9:58pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/6 "2015-07-17T21:58:24Z")

</div>

The way the "Button" example is written pushing the button will drive pin 2 high. Here's what it says in the sketch:

```cpp
 The circuit:
 * LED attached from pin 13 to ground
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.

```

In practice it's simpler to leave the resistor out entirely and use the internal pull-up resistor. You'd just insert the button between pin 2 and ground. Then you'd change the code to set pin 2 to INPUT\_PULLUP and change the logic so that it turns the LED on when LOW:

```cpp
const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

void setup()
{
    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT_PULLUP);
}

void loop()
{
    digitalWrite(ledPin, !digitalRead(buttonPin));
}

```

---

<div class="post-metadata">

**Author:** ![DVDdoug](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dvddoug/32/671533_2.png) [@DVDdoug](https://forum.arduino.cc/u/DVDdoug)\
**Post date:** [July 17, 2015, 10:06pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/7 "2015-07-17T22:06:46Z")

</div>

> i wired GND and VCC on the opposite way to make the LED stays ON and turn OFF only the button is pressed.

You don't need to reverse the hardware. **You can reverse the logic in your software sketch.** 😉

You can use a pull-up or a pull-down resistor **as long as the switch "pulls" in the opposite direction.** The switch/button has lower resistance when it's on (essentially zero resistance) so it dominates the over resistor. (The switch has infinite resistance when off and no current flows through it.)

But if you use a pull-down resistor, of course you should not enable the internal pull-up resistor.

And, it's more traditional to use a pull-up resistor and there are some circuits that only work with pull-ups.

---

<div class="post-metadata">

**Author:** ![BielMB](https://avatars.discourse-cdn.com/v4/letter/b/87869e/32.png) [@BielMB](https://forum.arduino.cc/u/BielMB)\
**Post date:** [July 17, 2015, 10:33pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/8 "2015-07-17T22:33:20Z")

</div>

Aaahh...i think the Circuit image made with Fritzing in this page [https://www.arduino.cc/en/tutorial/button](https://www.arduino.cc/en/tutorial/button) is wrong, because the schematics shows exactly what **Hutkikz, DrAzzy and jboyton** said. Thanks guys!

> DVDdoug:  
> You don't need to reverse the hardware. **You can reverse the logic in your software sketch.** 😉
> 
> You can use a pull-up or a pull-down resistor **as long as the switch "pulls" in the opposite direction.** The switch/button has lower resistance when it's on (essentially zero resistance) so it dominates the over resistor. (The switch has infinite resistance when off and no current flows through it.)
> 
> But if you use a pull-down resistor, of course you should not enable the internal pull-up resistor.
> 
> And, it's more traditional to use a pull-up resistor and there are some circuits that only work with pull-ups.

I have no idea how to make this via software. If i wire as the sketch says, the 13 pin LED will be OFF until i press the button. It's no big deal, since it's just to see how the pushbutton works. The problem: when i upload one of the .INO exemples of UnoJoy, after change the for the UnoJoy.hex firmware, if i go to "Control Panel \> Devices and Printers \> UnoJoy Joystick \> Properties", it shows the "Button 3" pressed, and when i press the button, it shows as unpressed.

I know probably i'm not being very clear. If so, i'll make a small video of what is happening haha.

Thanks again guys.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [July 18, 2015, 12:23am UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/9 "2015-07-18T00:23:13Z")

</div>

You may find Mr. Gammon's discussion helpful:

> **[Gammon Forum : Electronics : Microprocessors : Switches tutorial](http://www.gammon.com.au/forum/?id=11955)**
>
> Gammon Forum : Electronics : Microprocessors : Switches tutorial

---

<div class="post-metadata">

**Author:** ![BielMB](https://avatars.discourse-cdn.com/v4/letter/b/87869e/32.png) [@BielMB](https://forum.arduino.cc/u/BielMB)\
**Post date:** [July 18, 2015, 6:08pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/10 "2015-07-18T18:08:35Z")

</div>

> LarryD:  
> You may find Mr. Gammon's discussion helpful:  
> [Gammon Forum : Electronics : Microprocessors : Switches tutorial](http://www.gammon.com.au/forum/?id=11955)

Thanks for the link! Thinks are pretty clear now 😉

---

<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:** [May 5, 2021, 5:33pm UTC](https://forum.arduino.cc/t/pushbutton-and-pull-up-resistor/324448/11 "2021-05-05T17:33:35Z")

</div>


