INPUT_PULLUP QUESTION

You want to turn on the built-in LED on the Arduino Uno (pin 13). When the code
(below) is running, the LED does light up, but very dimly. What is the problem, and how to correct it?

void setup() {
}
void loop() {
digitalWrite(13, HIGH);
}

Thanks!

you have not defined the pin as an output would be my first thought

When the pin is in INPUT mode (which is the default), digitalWrite(13, HIGH) turns on the internal pull-up resistor, just the same as pinMode(13, INPUT_PULLUP). The internal pull-up resistor allows enough current to flow to turn on the LED dimly.

pert:
When the pin is in INPUT mode (which is the default), digitalWrite(13, HIGH) turns on the internal pull-up resistor, just the same as pinMode(13, INPUT_PULLUP). The internal pull-up resistor allows enough current to flow to turn on the LED dimly.

So will setting the pin as OUTPUT resolve the issue?

Have you tried it? Have you looked at the File > Examples > 01.Basics > Blink example sketch that is what almost every Arduino user starts with? There is even a tutorial that goes along with it:

dieselguy65:
you have not defined the pin as an output would be my first thought

My first thought was that this was homework.

Right!? They didn't even paraphrase the question.

@OP

1. Internal structure of 1-bit IO port showing the internal pull-up resistor (Rp).
internalPullup51.png
Figure-1: Internal structure of 1-bit IO line

2. Let us see (with the help of Fig-1) why the L (built-in LED of UNO) glows dimly even though the digitalWrite(13, HIGH); is executed.
(a) By default, the Pin-13 is an input line; this means that the Logic value of Q-pin of FF1 is LOW. FF1 is the 'Data Direction Register for Port-B (DDRB)'. An IO lone (in this case, it is DPin-13 = PB5) becomes an input line when Logic-L is written at the corresponding bit of DDRB. (DDRB = 0b011111.) Note: DDRxn ----> DDRB3 (DD ---> DDR; x = name of the port: B/C/D; n = bit number of the port = 0 to 7.

(b) By default, the PUD (pull-up disable) bit of MCUCR Register is at LOW-state.
mcucr.png
Figure-2: Bit layout of MCUCR Register

(c) The execution of digitalWrite(13, HIGH); instruction puts Logic High at Q-pin of FF2. FF2 is the PORTB Register. Q-pin corresponds to DPin-13 (PB5). Data can always be written into this latcah regardless of the direction of the corresponding IO line (the pd5 line).

(d) Now, PUD = LOW, Q-pin of FF1 = LOW, and Q-pin of FF2 = HIGH; as a result, G1 is active (its output is HIGH) and T1 is ON. The LED (L) circuit is: Vcc(5V), Rp ((20k+50k/2)), 1k, L, GND

(e) The current passing through L is: 5/((20+50)/2+1) = 0.14 mA which is very very low compare to 15 mA that is required to get acceptable brightness from L.

3. To see that L glows with good brightness, we need to disconnect Rp from the LED circuit. This can be done by executing the following codes:
A:

bitSet(MCUCR, 4);  //PUD-bit is HIGH; G1 is OFF; T1 is OFF; Rp is disconnected

OR

B:

pinMode(13, OUTPUT);  //Q-pin of FF1 becomes LH; G1 is OFF; T1 is OFF; Rp is disconnected

internalPullup51.png

mcucr.png