Pull-up / Pull-down resistors

pushbutton-simple-diagram

You need to read a digital signal from the input on a button;
Note: A digital signal for arduino is +5V (HIGH) or 0V (LOW).
The main problem is that if you simply link the digital pin to the pushbutton and the pushbutton to +5V, you will only get a clear signal when the button is pressed. The circuit will be closed (electricity flows from the digital Pin to ground). When the button isn't pressed, the circuit is open, and the digital pin isn't connected to anything, not even to ground. This means that the signal it will get won't be clean. This is for this purpose that we need to connect the Digital Pin to ground. This way, we conect the digital pin to a resistor connected to Ground (the "pull down resistor"), which will provide a path for the current to flow when the button is not pressed.
in this case the Arduino Pin is always Down and becomes HIGH when the button is pressed.
==> We can conversely use a resistor inbetween the Input pin and +5V, this way the current will always flow when the button is not pressed and will be instead sent to ground when pressed. This resistor is a PullUp resistor (linking the Pin to +5V). And the state of the button when pressed will be "LOW". ==> Interestingly the MCU has an embedded "INPUT PULLUP" resistor, so that we don't need to add a resistor and can simply place the button between the digital Pin and Ground, while specifying :
pinMode(button, INPUT_PULLUP); // during the setup procedure.
This action will connect the digital pin to +5V through an internal PULL_UP resistor. In this case the default state (when the button isn't pressed) is HIGH. Intersting links: http://blog.kennyrasschaert.be/blog/2014/04/01/digital-input-on-an-arduino-using-a-push-button/ https://learn.sparkfun.com/tutorials/pull-up-resistors    

Commentaires