2

enter image description here

So I've recently started Arduino and I just had a question about the digitalRead() function.

Does the IO Pins read Voltage or Current?

The reason I'm asking is because of the attached circuit.

So IO pin 7 is HIGH when the button is not pressed because the resistor is connected to 5V through the resistor. When the button is pressed the button is shorted to ground and is LOW. Why does it read LOW? Surely it would still read 5v because it is still connected to 5V through the resistor?

  • you do not need a pullup resistor on the switch ... just enable the internal pullups – jsotola Nov 21 '20 at 2:38
  • Surely it would still read 5v because it is still connected to 5V through the resistor? Equally you might argue it will read 0v because it is connected to Gnd via a direct short. The short will take precedence over the resistor. – Nick Gammon Nov 21 '20 at 4:52
5

They read voltage. When you close the pushbutton switch the input should have a 0V or digital "0" on it. When you open the pushbutton the resistor should pull the input to 5V or digital "1".

Yes, it is still connected to +5V via the resistor but the nearly 0 Ohm switch pulls the line all the way (or very close) to 0V.

  • For digital pins, it's more of a voltage comparison. They only measure if the voltage is above of below a certain threshold. So they only check whether it's HIGH of LOW. For the ATMega328p on the UNO, any voltage below 1.5V will return a LOW / 0, and anything above 3.5V will return a HIGH / 1. (Any voltage in between don't have a guaranteed outcome). – Gerben Nov 21 '20 at 14:12
  • @Gerben If we're aiming to be absolutely accurate here, then the actual specification for Vil(max) is 0.3 * Vcc and Vih (min) is 0.5 * (0.6 * Vcc). So if you are running at Vcc = 5.0V that comes out to be 1.5V and 3.5V. If your Vcc is different from 5.0V, then these values also vary. See the Atmel/Microchip ATMega328P datasheet on page 258. ww1.microchip.com/downloads/en/DeviceDoc/… – jwh20 Nov 21 '20 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.