Hi everyone, i'm a newbie so i am having a lot of problems with these stuff. My problem is with the INPUT_PULLUP function. Firstly, here is a simple code:

void setup() {


void loop() {


From what i learned from the internet, the pin 8 now is equilavent to connecting a ~20k ohm resistor between the pin and +5V. So i try if this is true. When i connect pin 8 and 5v pin to the LED, and it worked out well as i expected( the LED isnt bright,but the digitalRead here show 1), but when i connect pin 8 and ground pin to the LED, the LED is still bright, but the digitalRead show that the voltage here is 0. What?? If both pin are 0, then how can the LED bright? I am currently stuck here and really need your help. Thank you!
P.S: Sorry for my bad english

I guess you have mixed up the input and output functionality of the Arduino.

The forward voltage of the LED is probably not high enough to cross the digital high voltage threshold, which is why the LED can still illuminate (driven by the internal pullup resistance) while the digital input still reads LOW (0).

LEDs expect to be connected to an OUTPUT pin and controlled with digitalWrite(). Not an INPUT or INPUT_PULLUP pin and digitalRead().

I have also thought of that, but the LED i'm using here is green LED which requires more than 1,9 v to light up( i read this from the internet) so the voltage at pin 8 must be more than 1,9v which is higher then the digital high voltage threshold.

Hi. Where did i mess up, can you say it more precisely? Thanks al ot.

An LED is an INDICATOR - and you connect it to an arduino OUTPUT to show if the output is high or low.
INPUTs are for connecting devices that give a SIGNAL to the Arduino; such as a switch.
You can read about INPUTS here

and OUTPUTS here


Can you raw a diagram of each of your configurations that you talk about?
A hand drawn picture is fine.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

see post 7 and post 8.

If you have a good multimeter (DMM, high impedance), measure the voltage over the LED once connected to the Input pin. Then you will know what the voltage divider made by +5V --- 20K -- LED – GND ground is doing. You can also decide to measure the current in the circuit to se what is going on.
In this kind of topics to measure is to know, but beware, your multimeter also has an internal resistance that can play a role when measuring.

Well, i dont have one, but i change the pin 8 to pin A0 and do the analogRead here, and it shows about 450 (440-460) which is about 2,19 voltage

So do you think 2,19 voltage is low enough for the device to digitalread it low?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

We would be happy to help you but first, for the sake of the efficiency of the discussion, follow the advice of @TomGeorge.

(The courses for clairvoyance I skipped during my time at school, and I am afraid that other forum members also did the same. :slight_smile: )

A good drawing is in may cases the key to the solution of a problem because it makes you think about the problem.

Let us investigate the issue with the help of the following diagram of Fig-1.


1. Remove JI (jumpre J1) and execute the following code:

pinMode(8, INPUT_PULLUP);

(1) Switch S1 is closed. Internal pull-up resistor Rip gets connected. HIGH (5V) virtually appears at the input of GOIB gate. The execution of the following codes shows 1 on the Serial Monitor.

bool n = digitalRead(8);
Serial.print(n, BIN); //shows: 1

2. Place J1 and connect GND signal at the negative side of LED. The LED receives about 5/20k = 0.25 mA current which is not enough for the LED to be bright. (A LED needs about 10-15 mA current (with 2.5V drop across it) to emit light with good brightness.). At this setup, the DPin-8 is essentially at GND potention. Now, we will see 0 to appear on the Serial Monitor when the following codes are executed. (LED is providing a circuit to GND with an effective resistance of about 250R (2.5V/10mA)).

bool n = digitalRead(8);
Serial.print(n, BIN); //shows: 0

YMMD :sweat_smile: :rofl: :joy:

1 Like

Looks like the high level threshold (VIH) is actually about 2.6V when VCC is 5V.

If you're trying to visually monitor input status (if INPUT_PULLUP is enabled or not) and have this match your digitalRead status, go with blue LED.

When the pin is operated as "output pin", then VIH can go as low as 3.0 V (as per data sheets); but, the @quanny is operating the said pin as "input pin with internal pull-up resistor"; so, there is no way to get enough volatge at the pin to turn on the LED.

Depends on the LED, some will light with very little current, I used to use 10K resistors with LEDs when I wanted an indicator with a small current draw.

Here is the picture. Sorry for not responding soon, i didnt see your reply