# Digital Read Serial tutorial - calculating the resistor value

The Arduino Digital Read Serial tutorial guides you through the wiring of a simple button. My questions are centered around the resistor.

# Why is the resistor necessary?

I think I understand this, but correct me if I am wrong. To ensure that the input pin reads a low signal, and does not float, we should connect the pin to ground when the button is not pushed. When the button gets pushed, we will have a 5V signal flowing to both the pin and to ground. Kirchhoff's voltage law states that total voltage in closed loop must equal zero, so we have to deal with this 5V that is flowing directly to ground. That is why we put a resistor between the button and ground.

# How was the resistor value chosen?

This is what I am unclear on. Ohm's law states that...

``````resistance = voltage / current
``````

This is a 5V supply and the Arduino Uno spec says that the pin provides 40 mA of DC current. So..

``````resistance = 5V / 0.04A = 125 Ohms
``````

In the Digital Read Serial tutorial, why do we have a 10K Ohms resistor? That is way overkill, right? Which leads to another question: Can you ever put too much resistance in place, if your only goal is to obliterate voltage?

Thanks in advance for any feedback!

You're very close. The resistor is there to act as a pull down resistor; If the input pin is floating it is just an antenna picking up random static. The key is that when positive is supplied (by pressing the button) the positive source needs to "overwhelm" the pull down resistor so that the input pin reads positive.

If there were no resistance, than the input pin would be reading in the middle of a direct path that does not favor positive or negative. Asside from the direct short that would be occurring, Which state the arduino would read I suspect would either be random or some property of the power supply; It would probably still read ground.

With the resistor, the signal is read directly connected to positive, before the load resistance. This way it will be sure to get a HIGH signal.

The exact size of the resistor is of little consequence. Too small and you waste current, but too much resistance is effectively just disconnecting ground again. There is a very wide range of values that will work fine between those.

I would like to note that when an arduino pin is set to input mode, it will effectively supply no current. It can be moddeled is being in series with a 100 megaOhm resistor. see http://arduino.cc/en/Tutorial/DigitalPins for details.

• The key thing here is that if you don't use a resistor, when the switch is closed, you have shorted the +5 volt to ground. A direct short will overload the power supply and trip the protection circuit on the power supply, causing the whole Arduino to shut down. You want a resistor of high enough impedance to keep the current flow low. I usually use a 100k resistor, which is plenty to pull the input signal to 0 volts when the switch is open, and only allows .00005 pas to flow, a trivial amount of current. A 10k resistor works too, but that allows 10 times as much current to flow. Jul 6, 2014 at 20:09

Why is the resistor necessary?

The Arduino inputs have very high resistance. The datasheed of the Atmega328 says 100 MOhm for ADC, Such high values are good, but have also the drawback to deal with parasitic effects (resistance, inductance, capacitance). Such effects can also be used as Capacitance Sensors.

How was the resistor value chosen?

The resistor needs to have an arbitrary value, that is smaller than the input resistance. 10k and above are good for disabling the input leakage.

However you can also leave out the resistor when you use the internal pull-up resitors. In this case you deal with negative logic:

``````pinMode(3, INPUT);
digitalWrite(3, HIGH);
``````

On pin 3 you'll measure `HIGH` and the button needs to be connected to the pin and the ground. The internal I/0 pull-up resistor has the value of 50k.

You've already gotten a couple of good answers on why a pull-down resistor is needed.

To summarize, you need to connect the input to ground to keep the input from floating semi-randomly between high and low. You use a resistor so that when you close the switch, you don't create a short circuit between the +5V supply and ground.

Another point, though. The Arduino's inputs include an optional internal, software-controlled pull-up resistor. If you first set up the pin as an input, then write a HIGH value to that port, it activates the pull-up resistor. That causes the pin to read as HIGH when nothing is connected to it.

You can then connect your switch to ground instead of +5V. You then need to change your code logic to treat a HIGH value as not pressed, and a LOW value as pressed. This lets you simplify your wiring a little, since you don't need an external resistor.