- Joined
- May 10, 2009
1) That is a large part of what setting the pinMode to INPUT does, yes. What it does is tell the Arduino that it should look at pin2 rather than trying to change what pin2 is doing. It can still source some voltage, but very little actual current.
In the fritzing diagram, the button's two pins on the right are connected internally, as are the two on the left.
In that diagram voltage goes to the button and stops there.
The resistor to ground makes sure that anything that leaks out the Arduino pin and/or is captured from the general magnetic fields is sent to ground so the Arduino pin cannot see it.
When the Arduino looks at the pin (digitalRead,2) it sees no voltage, and returns 0.
If you press the button voltage goes through the switch to the Arduino pin side, enough to overwhelm the resistor (if it's a high resistance, don't do that circuit with a 1 ohm resistor or something!), so when the Arduino looks at the pin it sees 5v and returns 1.
The two lines on the right connect the power rails on each side of the breadboard to each other, so that both 5v lines are connected and both ground lines are connected.
In the fritzing diagram, the button's two pins on the right are connected internally, as are the two on the left.
In that diagram voltage goes to the button and stops there.
The resistor to ground makes sure that anything that leaks out the Arduino pin and/or is captured from the general magnetic fields is sent to ground so the Arduino pin cannot see it.
When the Arduino looks at the pin (digitalRead,2) it sees no voltage, and returns 0.
If you press the button voltage goes through the switch to the Arduino pin side, enough to overwhelm the resistor (if it's a high resistance, don't do that circuit with a 1 ohm resistor or something!), so when the Arduino looks at the pin it sees 5v and returns 1.
The two lines on the right connect the power rails on each side of the breadboard to each other, so that both 5v lines are connected and both ground lines are connected.