2
\$\begingroup\$

This question already has an answer here:

I just got my first Arduino and had a question about pull-up resistors.

I was trying to connect a push-button to the Arduino at pin 2, and if it's HIGH then I write HIGH to pin 13. Now, in the tutorial I watched, it said to have a resistor from the button to ground so if pin 2 asks what the voltage is, it gets ground, so it doesn't write HIGH to pin 13.

I tested this and it did, indeed, prevent the noise from pin 2. However, when I tried replacing the 10k resistor with a normal wire, it didn't work. So, my question is why do we have to use a resistor and why can't it just be any connection to ground?

In this diagram pin 2 reads whether it gets 5V (HIGH) or 0V (LOW) and returns a boolean value. Then, if the value is HIGH, pin 13 outputs HIGH. Also, it looks like the long wire on the Arduino is blocking out the labeling on a pin. The pin that the long wire connects to says "5V".

Thanks!enter image description here

\$\endgroup\$

marked as duplicate by Matt Young, PeterJ, Ricardo, Daniel Grillo, bitsmack Dec 18 '14 at 17:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    \$\begingroup\$ This question has a lot of problems. You say "arduino at pin 2" as if everybody has the schematic for arduino right at hand to check it out. We don't. I think I know what you are asking, but it is hard to be sure. In future, I suggest you don't assume everyone is familiar with the system you are working on. Provide a link or a schematic, or a sketch schematic for discussion purposes. \$\endgroup\$ – mkeith Dec 17 '14 at 3:08
  • 1
    \$\begingroup\$ this type of question has been already asked on EE.SE : here and here. \$\endgroup\$ – Nick Alexeev Dec 17 '14 at 3:57
  • \$\begingroup\$ @mkeith I added a diagram :) \$\endgroup\$ – Globmont Dec 17 '14 at 4:21
  • \$\begingroup\$ @Globmont, the second link provided by Nick Alexeev just above is quite good. Read the high-rated answer. It explains everything. \$\endgroup\$ – mkeith Dec 17 '14 at 6:33
2
\$\begingroup\$

You have to use a resistor so the pushbutton can overpower it. If you use a piece of wire, you get a short between Vcc and GND when you push the button - not so good for the button or the rest of the board. Using a resistor holds the pin at a specific level until something 'stronger' (lower resistance) comes along and changes it (in this case, the button).

\$\endgroup\$
0
\$\begingroup\$

Updating due to addition of diagram.

Generally, buttons are switches. A spring of some sort keeps them "off." When you push the button, you overcome the spring force and it shorts its two contacts together, and it is then "on."

In your case, you do not have a pullup, you have a pulldown. One side of the switch is connected to VCC (5V) and the other side is connected to the resistor which pulls down to GND. The IO pin is connected to the resistor side of the switch, too.

The reason you need a resistor, which has been explained by other responders is that if you use a wire, then every time you press the button, 5V will be shorted directly to GND. You mention that you tried this and it "didn't work." I am not sure what "didn't work" means in this context, but the whole board probably reboots every time you do that. I hope this answers all your questions. Have fun experimenting!

\$\endgroup\$
  • \$\begingroup\$ I added a diagram! I think I figured it out, but can you verify my understanding for me? My original question was why I needed to use a resistor to connect the button/pin 2 to ground instead of a wire. My understanding is that I need to use a resistor so that when I push the button and the 5V goes through, when pin 2 asks for the input, it will read the 5V and not the ground value of 0V since there will be resistance? And if I'm using any terminology wrong, please correct me. I'm entirely new to electrical stuff :) Thanks! \$\endgroup\$ – Globmont Dec 17 '14 at 4:25
  • \$\begingroup\$ @Globmont, I updated my answer. Thanks for adding the diagram. \$\endgroup\$ – mkeith Dec 17 '14 at 6:23
  • \$\begingroup\$ Awesome! Thanks! One last question: you were right about the board rebooting every time I used a wire instead of a resistor. Would you mind explaining why that happened? You said that the 5V would be shorted to GND but why would that cause the board to reboot? \$\endgroup\$ – Globmont Dec 17 '14 at 18:05
  • \$\begingroup\$ @Globmont, the power supply cannot supply 5V when it is shorted to GND. So the voltage drops very low (maybe close to zero, depending on resistance of wire and supply capability, etc). Either the chip will trigger an internal low voltage reset, or it will simply become completely de-energized. This is the same as disconnecting power, from the chip's perspective. When you release the button, that is like plugging the power back in. Many processors, when power is first applied, boot up automatically. \$\endgroup\$ – mkeith Dec 17 '14 at 18:14
0
\$\begingroup\$

Um .. here is my 2 cents ....

every microcontroller (including the one sitting in the Arduino) has a current limitation on their pins. So when you connect the pull-up (or pull-down) resistors you have to ensure that the current that they can draw is within the specs of the microcontroller). So you need a high-ish resistor for this, but you cannot keep too large a resistor so that even stray currents mess up your circuit. Typically about 10K to 20K is recommended.

FYI: I am a hobyist not an electronics engineer, so use my info at your own risk :-P

Abhishek

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.