Go Down

Topic: why INPUT detects HIGH/LOW without power ? (Read 1 time) previous topic - next topic

_AZZ_

hello,
 it appears that when a digital pin set into INPUT mode it detects HIGH/LOW even without additional +5V applied. Is this right or i'm seeing things? And it is true, then why?

Sketch:
Code: [Select]


int pin9 = 9 ;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(pin9,INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println(digitalRead(pin9));
delay(1000);
}


the schema is :
pin9 -> J27
f27 -resistor(200Om) -i18
h18 -push button - h16
j16- "-" rail -GND on UNO.

output - when button is pushed - "1", when button is not pushed "0".

PaulS

#1
Oct 10, 2015, 08:04 pm Last Edit: Oct 10, 2015, 08:06 pm by PaulS
When a pin is set to INPUT it MUST be pulled to HIGH or LOW by some external source before it makes sense to read the pin.

Whatever you have connected to the pin is NOT forcing the pin to be HIGH or LOW in a consistent fashion. If you have nothing connected to the pin, then the behavior you are seeing is perfectly understandable.

Use INPUT_PULLUP to ensure that the pin is in a known state even with nothing connected.
The art of getting good answers lies in asking good questions.

Martin-X

By using INPUT_PULLUP in the pinMode() function, the micro-controller has connected 5v (through a resistor) to the pin.  This is all done internally on-chip, so no external supply is needed.  With no external circuit connected the pin will always read HIGH, so a connection to ground through the push button is all that's needed to change it to LOW.

Have a look at https://www.arduino.cc/en/Tutorial/DigitalPins

_AZZ_

By using INPUT_PULLUP in the pinMode() function, the micro-controller has connected 5v (through a resistor) to the pin.  This is all done internally on-chip, so no external supply is needed.  With no external circuit connected the pin will always read HIGH, so a connection to ground through the push button is all that's needed to change it to LOW.

Have a look at https://www.arduino.cc/en/Tutorial/DigitalPins
Martin,
 thank you for explanation - it makes sense. I could not ( and still can't ) find a direct explanation in the documentation.
But, does the following quote implicitly states that INPUT_PULLUP provides +5V?:
"Properties of Pins Configured as OUTPUT

Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. "

At the same time :
"The pullup resistors provide enough current to dimly light an LED connected to a pin that has been configured as an input.", but for OUPUT:
"This is enough current to brightly light up an LED (don't forget the series resistor),..."
The way i read these - the V in INPUT is lower than in OUTPUT mode.

what am i missing?

MarkT

The pin is connected to output driver transistors which are about 30 to 40 ohms when on, hence
in output mode the pin can drive to its 40 mA limit quite easily.

The internal pull-up is quoted as 20k to 50k, far higher impedance, and is only powerful enough to
hold the pin high if nothing else is trying to drive it.

Both the pull up and the output HIGH drive transistor can pull the pin towards 5V, but they have 3 orders
of magnitude difference in their resistance....

There's a lot of circuitry attached to each pin internally, not just the pullups and the output transistors,
doing such things as glitch-suppression, hysteresis, auto-toggle, latching the output state, but from
a software point of view all you need to know is that there are 3 modes, INPUT, INPUT_PULLUP, OUTPUT,
and when an OUTPUT the pin can be HIGH or LOW.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

_AZZ_

Thank you Mark.

would it be correct ot say , that the voltage in INPUT_PULLUP mode is sufficient enough for pin to register HIGH, but it is not sufficient to reliably perform any complex ( more complex than in switch example of mine) operations. As such the +5V should be used.

is this accurate or i'm oversimplifying reality?

Martin-X

would it be correct ot say , that the voltage in INPUT_PULLUP mode is sufficient enough for pin to register HIGH, but it is not sufficient to reliably perform any complex ( more complex than in switch example of mine) operations. As such the +5V should be used.

is this accurate or i'm oversimplifying reality?
That's pretty much how I see it.  The key term is High impedance.

MarkT

The voltage is 5V both ways, its the ability to follow up with actual current when a
real load is connected that matters.  An Arduino input is no load, its almost infinite
resistance...  This is true of all CMOS logic.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

_AZZ_

Mark, Martin - thank you it is making sense to me now.


Go Up