Type Here to Get Search Results !

How To Pull Up Down Resistor In Arduino

Looking on this simple circuit scenario, on the left side we have pushbutton switch that is connected to the ground and then to some digital input pin on the other side connected to the arduino. Now while pressing the button we have a close circuit so the arduino will read 0v. As soon as we will release the pushbutton, something strange will happen.


The input pin we would to read is essentially connected to nothing. It's "floating", and because the pin is not physically connected to 0v or 5v reading it could cause unexpected results. So the solution for that is very simple, we will use a pullup or pulldown resistor, to set the “default state” of the input pin.

The main usage of a pulldown resistor is to set the default state of an input pin to 0v. Now, 10kω is a usually a common pulldown resistor valu, we will use that in our circuit.

Now to understand the logic, consider what happens when the button is not pressed with the pulldown resistor in the circuit, i am not pressing the pushbutton so it is not connected between the two points.

In this case the input pin will be connected through a 10kω resistor to ground. Now while the resistor will restrict the flow of current, there is still enough current flow to ensure. That the input pin will read a low logic value, meaing something that is close to 0v, looking on the same diagram, but here the button is pressed meaning the input pin is directly connected to 5v through the button. Now in this case the current has two options:


  1. It can flow through an almost zero resistance path to the 5v side or it can flow through a high resistance path to the ground side.
  2. If you remember, a little bit electronic background, ohm’s law and the power equation state that current will always flow the path of the minimum resistance in a circuit.
  3. In this scenario, the majority of the current flow will go through the button and a high logic level is generated on the input pin of the arduino, because that's the path of least resistance without big suprise we can also use "pullup" resistor instead of "pulldown" resistor by connecting the resistor to 5v and by connecting the other side of the button to ground.


I mean, switching between them the ground and 5v in this setup, the input pin reads a high-logic value when the button is not pressed and a low- logic value when the button is being pressed.
To summarize , pulldown and pullup resistors are important because they ensure that the button does not create a short circuit between 5v and ground and in addition when being pressed and that the input pin is never left in a floating state.



Post a Comment

0 Comments