Difference between INPUT, INPUT_PULLUP & INPUT_PULLDOWN

Hello All

This is mainly a noob question. what I understood from the documentation ,to set a pin as input we will use pinMode(D1, INPUT). What I dont understand is the what is the use of INPUT_PULLUP & INPUT_PULLDOWN ??

1 Like

When in any `INPUT´ mode the pin goes in a high impedance state which means that it should (almost) not influence the external circuitry and for this the signal to read.

If there is no ext circuitry attached INPUT will not give you any predictable reading (floating signal).

To prevent this floating you can instruct the µP to internally attach a somewhat lower (but still high) resistance either towards GND (INPUT_PULLDOWN) or towards Vcc (INPUT_PULLUP).
This will give you predictable readings e.g. when an attached switch is not pressed.

3 Likes

@bijay When you are using a pin as an input pinMode(D1, INPUT) It will have an high impedance. This means that the pin will not source or sink current and basically ‘listens’ to what ever voltage is connected to the pin. It will be up to the external circuitry to set the voltage. When you use INPUT_PULLUP the pin is effectively connected thru an internal resistor to the +Vcc power rail. For the STM32 CPU on the Spark Core this internal PULLUP resistance is 40k ohms

If you don’t set the input to INPUT_PULLUP and don’t drive the voltage using an external circuit the voltage will float to one rail (3.3v) or the other (GND).

There are cases when you would not want to use the INPUT_PULLUP setting, 40K ohms is a lot of resistance, say you want to listen to a high frequency clock, with this high resistance and the inherent capacitance of the connected circuit you may not get clean edges on the clock. In this case you may want to use a lower value external pull-up resistor to ‘sharpen’ the edges

8 Likes

Thanks @ScruffR & @mtnscott