# Arduino - pin resistor not needed?

Reading J Blum's book Exploring Arduino I came across the following code and schematic. Can anyone explain why
a resistor between pin 2 and +5V is not needed?

const int LED = 9;
const int button = 2;

void setup()
{ pinMode(LED, OUTPUT);
pinMode (button, INPUT);
}

void loop()
{ digitalWrite(LED, LOW);
}
else
{digitalWrite(LED, HIGH);
}
}

Presentation1.pptx (55.6 KB)

The book is wrong...?

R1 pulls pin 2 to ground, so it does not float and reads LOW. When the switch is pressed, pin 2 is pulled up to HIGH.

Seems obvious. Am I missing something?

Paul

Paul,
I am a newbie, so bear with me.
When the switch is closed and the pin2 is low, the 5V pin is connected to pin2 by a piece of wire. There is
nothing to limit the current flow between these two pins. I am assuming that low = 0 V. It looks like a short to me.

It looks like a short to me.

It could be if pin 2 was an output, but it's an input with an impedance of ~1 gazillion ohms.

There is nothing to limit the current flow between these two pins.

Yes there is, the impedance (resistance) of the input circuitry on pin 2.

As I said though, if you made pin 2 an output and set it LOW then closed the switch you would have a problem.

Rob

Rob, thanks for the explanation and thanks to all that replied.
Les

x50505:
Paul,
I am a newbie, so bear with me.
When the switch is closed and the pin2 is low, the 5V pin is connected to pin2 by a piece of wire. There is
nothing to limit the current flow between these two pins. I am assuming that low = 0 V. It looks like a short to me.

I didn't see the image in your first post because it was in powerpoint format (I think).

When a pin is set as INPUT it has a big resistor in there. Megaohms so it's not a short.

But...using external pulldown resistor is just silly. AVR chips have internal pullups for this, you don't need extra external components.

Using external pulldowns is also bad design. Your feeling is correct - it can lead to short circuits if you're not paying attention or something goes wrong. Internal pullups and switches that go to GND are a much safer way to do it.