INPUT and INPUT_PULLUP

Hello World!

I have seen people use INPUT and INPUT_PULLUP. What is the difference between them both and where are they supposed to be used?

Any replies will be appreciated! Thank you! :slight_smile:

INPUT makes the pin an input, as you would expect, but if nothing is connected to it, such as when a switch that takes it HIGH when closed, is currently open it could be floating at any voltage (even HIGH)

INPUT_PULLUP makes the pin an input but activates an internal resistor that keeps the input HIGH unless it is explicitly taken LOW by the circuit. That way the input is always in a known state

It makes sense to use INPUT_PULLUP unless you use external pullup or pulldown resistors to achieve the same effect

Thank you so much!

So is it sensible to use INPUT_PULLUP while using a touch sensor cause I use INPUT there.

So is it sensible to use INPUT_PULLUP while using a touch sensor cause I use INPUT there.

Only the information from the datasheet for the touch sensor in question can answer that question.

How is the sensor wired to the Arduino and how are you testing that a touch has occurred ?

Can you provide a link to the sensor that you are using ?

I am using the touch sensor mentioned in this Project:

There are 3 pins for the touch sensor:

Vcc - 5V
Gnd - Gnd
SIG - Any digital pin

I am using digitalRead() for reading the value of the sensor. If someone is touching it, it returns 1 ( true ) or it returns 0 ( false ).

A sensor like that has an output designed to drive a typical digital input. So you can use INPUT.

There are two common types of digital outputs: 'totem-pole' and 'open collector / open drain'.

A totem-pole output can drive the output both HIGH and LOW using two transistors. You can connect that to an INPUT pin and it will also work with an INPUT_PULLUP pin.

With an open collector ("open drain" for MOSFET) there is only one transistor that pulls the output down to LOW. The output is only ever HIGH because there is a pull-up resistor somewhere. This kind of input won't work on an INPUT pin unless there is an external pull-up resistor. It WILL work on an INPUT_PULLUP input.

Switches and buttons need either a pull-up or pull-down resistor. Because the creators of Arduino and most beginners associate 1/HIGH with a closed switch / pressed button and 0/LOW with an open switch / unpressed button, the Arduino examples typically connect the switch/button between a pin and +5V and require a pull-down resistor. Since the basic Arduinos only have internal pull-up resistors this requires an external resistor (additional part). To eliminate that extra hardware it is better to associate 0/LOW with a closed switch / pressed button and 1/HIGH with an open switch / unpressed button. Then the switch/button can be connected between a pin and Ground and the internal pull-up can be used.

I like to read the button state with:

 boolean buttonPressed = digitalRead(ButtonPin) == LOW;

This lets you use "if (buttonPressed)" in an intuitive way.

johnwasser:
There are two common types of digital outputs: 'totem-pole' and 'open collector / open drain'.

A totem-pole output can drive the output both HIGH and LOW using two transistors. You can connect that to an INPUT pin and it will also work with an INPUT_PULLUP pin.

With an open collector ("open drain" for MOSFET) there is only one transistor that pulls the output down to LOW. The output is only ever HIGH because there is a pull-up resistor somewhere. This kind of input won't work on an INPUT pin unless there is an external pull-up resistor. It WILL work on an INPUT_PULLUP input.

I like to read the button state with:

 boolean buttonPressed = digitalRead(ButtonPin) == LOW;

This lets you use "if (buttonPressed)" in an intuitive way.

Ok got it! Thank you!

One other use of pullup resistors, is a wired logical "or" function. So for example you could connect two pushbutton switches in parallel and to the input with a pull up resistor attached or enabled. Then either one or the other switch can safely produce a LOW state on the input. The same thing works with open-collector sensors.

aarg:
A sensor like that has an output designed to drive a typical digital input. So you can use INPUT.

Ok I guess that is the Final answer! Thank you all for your help! :slight_smile:

aarg:
One other use of pullup resistors, is a wired logical "or" function. So for example you could connect two pushbutton switches in parallel and to the input with a pull up resistor attached or enabled. Then either one or the other switch can safely produce a LOW state on the input. The same thing works with open-collector sensors.

Yes I know that. But thanks to everyone who helped me +1 karma :)!