Surely sometimes you have come across projects in which you need pushbuttons or buttons for a digital input, thus being able to press to make it open or closed. However, for this type of circuit to work properly, you need resistors configured as pull-down or as pull-up. It is precisely for this reason that we are going to show you what exactly these configurations are, how they work, and how you can use them in your projects with Arduino.
Note that the pull-up and pull-down resistor configurations allow set standby voltages for when the button is not pressed and thus ensure a good reading of the digital system, since otherwise, it might not be read as a 0 or 1 as it should.
What does a resistor do?

How should you know the resistance is a fundamental electronic component which is made of a material that opposes the passage of electric current, that is, the movement of electrons through it, making this movement difficult, electrical energy is converted into heat, since the friction of electrons will generate said heat.
Depending on type of material, and its section, it will take more or less work for the electrons to be able to move through this component. However, this does not mean that it is an insulating material, in which there would be no possibility of movement of electrons through it.
This effort to overcome the electrons when it comes to circulating is precisely the electric resistance. This magnitude is measured in Ohms (Ω) and is represented by the letter R. In the same way, according to the Ohm's Law formula, we have that the resistance is equal to:
R = V/I
That is, the resistance is equivalent to dividing the voltage by the intensity, that is, volts between amps. According to this, if we have a power source that provides a constant voltage, the intensity will be less the greater the resistance.
Pull Up Resistance

As you have seen, so that the voltage is not indefinite in a circuit with a pushbutton or a button, so that it always works with precise high or low voltage values, as a digital circuit needs, a pull up resistor, whose function is to polarize the voltage towards the source voltage (Vdd), which can be 5v, 3.3v, etc. In this way, when the button is open or at rest, the input voltage will always be high. That is, if for example we have a digital circuit that works at 5v, the input voltage of the digital circuit would always be 5v in this case.
When the button is pressed, then the current flows through the resistor and then through the button, diverting the voltage from the input to the digital circuit to ground or GND, that is, it would be 0v in this case. Therefore, with the pull-up resistor what we would do is that the input would be at a high value (1) as long as the button is not touched, and that it is at a low level (0) when it is pressed.
Pull Down Resistance

Similarly to the previous one, we have the pull down resistorThat is, it is just the opposite. In this case we have that when the button is at rest the voltage that enters the digital input is low (0V). While when the button is pressed a high voltage current will flow (1). For example, we could have 5v when pressing and 0v when leaving it at rest.
As you see, it is the opposite of the pull-up, and can be very practical in some cases where a high voltage is not intended to begin with. maybe this reminds you a lot of relays, when they are normally open or normally closed, as we have seen before. Well, this is something similar…
Frequently Asked Questions
Finally, let's see some frequent doubts About these pull-up and pull-down resistor setups:
Which one should I use?
Use a pull-up or pull-down configuration will depend on each case. It is true that the pull-down may be more popular in some cases, but it does not have to be the best, far from it. To sum it up:
- If, for example, you are using a logic gate with two pushbuttons connected to its inputs and you want the inputs to be zero while you are not pressing them, then use the pull-down.
- If, for example, you are using a logic gate with two pushbuttons connected to its inputs and you want the inputs to be one while you are not pressing them, then use a pull-up.
As you can see, there is no better or worse, it is just a matter of preference.
Enabling Internal Pull-up on Arduino
Some microcontrollers include internal pull-up resistors so that they can be activated. This is achieved by certain instructions embedded in the code. In case you want to activate the pull-up of the arduino microcontroller, the declaration that you have to put in the setup of your sketch is the following:
pinMode(pin, INPUT_PULLUP); //declare a pin as an input and activate the internal pullup resistor for that pin
This technique is widely used both for connecting push buttons and for I2C circuits.
What resistor value should I use?
Finally, it must also be said that they can be used various resistor values in pull-up and pull-down configurations. For example, it can be used from 1K to 10K depending on some factors such as the frequency of variation, the length of the cable used, etc.
The older the resistance for the pull-up, the slower the pin is to respond to voltage changes. This is because the system that feeds the input pin is essentially a capacitor together with the pull-up resistor, thus forming an RC circuit or filter, which takes time to charge and discharge as you already know. Therefore, if you want fast signals, it is best to use resistors between 1KΩ and 4.7KΩ.
As a rule, many pull-up and pull-down setups use resistors with 10KΩ values. And this is because it is recommended to use a resistance at least 10 times less than the impedance of the digital pin being used. When the digital pins are used as input, they have a variable impedance, depending on the chip manufacturing technology, but most commonly the impedance is 1MΩ.
It is also necessary to take into account the consumption and the current that is going to enter the digital circuit, the lower the resistance, the higher the current and therefore the higher the consumption and the current that will enter the chip. Nor can we put an excessively high resistance to have a low consumption, since if the current is very small it can happen that the chip is not so susceptible to such small changes and does not know if it is at high or low voltage at all times. For example, in a circuit with a 5V power supply, the resistance could be 10KΩ, knowing that the current that will enter the circuit is 0.5mA, something that in terms of consumption is negligible, since it supposes a power of 2.5 mW.