# Project 2 - Spaceship Interface - Digital Input Confusion...

Hi Peoples,

I googled and searched in here but I couldn’t find an explanation that I understood on the digital input 2 and why it is wired the way it is.

A circuit diagram is attached. My confusion is around the positioning of the resistor and the line going from between the switch/resistor to the 2nd digital io pin on the Arduino. Alas the Arduino Projects Book doesn’t explain clearly why this is, just that it must be so. All the book states is:

Place the switch on the breadboard just as you did in the previous project. Attach one side to power, and the other side to digital pin 2 on the Arduino. You’ll also need to add a 10k-Ohm resistor from ground to the switch pin that connects to the Arduino. That pull-down resistor connects the pin to ground when the switch is open, so it reads LOW when there is no voltage coming in through the switch.

This implies to me that when the switch is open, a circuit is made between pin 2 and the GND via the ‘pull down resistor’. That kinda makes sense to me (but doesn’t explain the need for the resistor). My confusion is around what happens when the switch is closed? We have a circuit that includes 5V, GND and pin 2 afaict, which I don’t understand…

Any help would be appreciated.

digitalRead of pin 2 will return LOW when the switch is open, and HIGH when closed.

Any miswiring tho and you end up shorting 5V to who know what.

A better design is to use the internal pullup resistor:

pinMode (2, INPUT_PULLUP);

to hold the pin in a high state. Then wire the switch to connect the pin to Gnd. Current is then limited to a fraction of a mA internally (internal pullup is 20K to 50K) and connecting the pin to Gnd will not hurt anything.

Your code will then look for a LOW to signal the switch is closed:

if (digitalRead(2) == LOW){ // perform switch is closed action } else { // perform switch is open action if needed }

“Any miswiring tho and you end up shorting 5V to who know what.”

So is this basically a safety precaution in the book, for instance in case you setup pinmode(2, OUTPUT) instead of INPUT, then it won’t short?

So is this basically a safety precaution in the book

Nasa has certainly had a lot of budget cuts :astonished:

Grumpy_Mike:

So is this basically a safety precaution in the book

Re-reading didn't help me. In fact re-re-rereading still made it sound like a precaution... HOWEVER... the link you provided clarified a lot. That was a great help for me, so thanks for that resource.

I registered to ask a similar question, so I decided to try it in this thread. I've read the above links and, as someone who is tinkering with resistors for the first time since my 1980's Radio Shack kits, I feel like I haven't quite wrapped my head around the pull down resistor concept yet.

I'd appreciate a kick in the head from someone who can explain the theory behind it. :~

I understand the need for pin 2 (in the Arduino example above) to read a steady LOW rather than "floating," electrically connected to nothing and possibly picking up environmental interference. Hypothetically, if the circuit were never going to be closed by the switch, pin 2 could just be connected by to GND and it would read LOW ... right? And the 10K resistor is doing exactly that when the switch is open?

Obviously, closing the switch with a direct connection instead of a resistor would short 5V to GND. Using the 10K resistor makes the path to ground "less interesting" when the switch is closed and the current goes for pin 2 instead ... right?

For some reason, I keep focusing on the resistor's role in the closed circuit (protecting from short) while all of the online explanations (and the very name "pull down resistor") focus on its role in pulling the voltage to a steady LOW when the circuit's open. Basically, I'm seeing it as a "short protection resistor" instead of a "pull down resistor." What am I missing that's causing me to think backwards?

You can certainly think of it that way.

Preferred method is to use the internal pullup resistor, then use the external switch to connect the pin to Gnd. We have seen lots of questions where the 5V was shorted out causing resets and damage to components due to miswiring of switches. With internal pullup and switch to Gnd, 5V short is removed as a possibility. Internal pullup holds the pin High, no external resistor is needed. The resistor is easily overcome by other devices if left connected; also by the chip's own output drivers if left connected.

Dear all,

I don't know whether my problem is related to this but it is also concerning interference for the spaceship interface.

I have built the circuit according to the book and the funny part is that if I come close with my hand to the set up to push the button, it triggers the digital pin 2 before I have even pushed the button. Is it possible that my hand causes interference with the wires? Should I keep the wires as short as possible (currently they are a bit long)?

Best Regards,

Jan