Question about pinMode(LED_BUILTIN,INPUT)

Hello. I've finally received my UNO and am just doing some really basic tests of its functionality with LED blink and simple programs. This is my first experience with the hardware.

The basic blink function works exactly as expected, but one question that came to mind was what would happen to the builtin LED if I set pin13 to an input instead of an output. Surprisingly the inbuilt LED shows full brightness when the pin is set to an input, and it makes no difference if I enable pullup of not. I wasn't expecting that.

So is this normal behavior or am I doing something wrong?

BTW. All I did was take the simple "Blink" example and edit the init() setup() procedure such that it has pinMode(LED_BUILTIN, INPUT); instead of output. I was expecting to see the LED glow (perhaps a little less bright) when the pullup was enabled, but I not with pullup disabled.

lets see the code

backwoodsjack:
lets see the code

Sorry, I think this is more of a hardware question than a code question, perhaps I posted in the wrong forum.

To see the code simply look at the IDE inbuilt example "01.Basics -> Blink" and edit the one line as indicated in my original post (to make the pin an input). That's the code in its entirety.

Ok I think I've answered my question. I just found the board schematic and I now see that the LED is buffered with an op-amp, so even as a floating input it can do whatever with the LED. It makes sense now.

I just connected my voltmeter from pin13 to gnd and the meter 20Meg impedance was enough to pull it low and turn the LED off (while pullup is disabled). The pullup can of course override the meter impedance and turn the LED on.

Everything is acting as expected. :slight_smile:

backwoodsjack:
lets see the code

This is all it is. With the pin set to an input then writing to it should simply enable or disable to the (internal) pullup. However the LED stays on at full brightness all the time, regardless of the state of the pullup.

However a 100k pull down resistor (external from pin13 to gnd) fixes the issue (input floating) and makes it behave as expected. :slight_smile:

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, INPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

This is going to sound picky, but did you really

take the simple "Blink" example and edit the init() procedure

Whilst it may be obvious that it was the setup() function that you changed, if you are not precise in what you do and say when programming it will end in tears. As an example, the Arduino environment includes an init() function that is included behind the scenes when your code is compiled. Can you see how confusing a simple mistake in a function name could be ?

UKHeliBob:
This is going to sound picky, but did you really
Whilst it may be obvious that it was the setup() function that you changed, if you are not precise in what you do and say when programming it will end in tears.

Ok gotya Bob. I just reread my original post and notice that I said "init()" instead of "setup()". Sorry, that was a typo. :slight_smile: