I think I've grasped the concept of pull down resistor, but not pull up resistor...
Why does current flows to ground, rather than input pin when the switch is closed?
Are potential differences between Vcc and input pin when switch is open; Vcc and ground when switch is closed the same?
PinMode() instruction activates built-in pull up resistor is there a link with that high impedance and the lazy current?
If you think of the input pin as a very high value resistor, the pull-up resistor arrangement would look like this:
Think about what is happening in this circuit when the button is open or closed. What would the voltage at Vin be in both circuits, given Vin is 5V? Hint: use Ohms Law or the voltage divider rules, or just common sense.
I'm afraid I don't understand your first question.
Anyway, a pull-up resistor puts an high-impedance input, at Vcc . As there is no current passing through, the voltage at the input is the same as Vcc. When the input is LOW, the voltage on this pin is 0V (GND), and there is now a current through the pull-up resistor ( i = Vcc/Rpull-up) . This current is low, because the resistor value is about 20k
So , you put a pull-up resistor if you want your input to be HIGH without input signal, and you put a pull-down resistor if you want it to be LOW without signal. Don't put both, you'll just make a voltage divider
Without pull-up or pull-down, the input is in an inderteminate state when no signal comes.
Yes, you could put a pull up resistor, OR a pull down resistor (not both). Just so happens the CPU has decided to provide pull up resistors, So unless you want to add external resistors, go with the flow, and allow the internal pull up resistors when needed.
What matters with an input is not the current that flows (an input is so high impedance hardly any current flows into it), but the voltage at the input. In the two circuits the voltage at Vin is, when the button is closed: 0V (it is connected direct to ground, so it will always be 0v regardless of any resistors), and when the button is open: 4.95V. This can be proved a number of ways.
Ohms law:
The current flowing through the circuit is the voltage (5v) divided by the total resistance (1010000?), which is 0.00000495A. The voltage drop across the top resistor is the resistance (10000) multiplied by the current flowing through it (0.00000495A), which is 0.04950495. Subtract that from the total voltage (5V) and you have 4.95049505V.
So with the button open the voltage is above the threshold for a high input, and so a high is registered. With the button closed the voltage is below the threshold for a low input, and so a low is registered.
There are several good web sites that explain basic electronics. If you don't yet have a grasp of basic electronics, maybe you would benefit from some of those sites.
Vin is 0V ; and ground is 0V too.
They are both connected to ground, that's why I don't understand why the microcontroller sees a potential difference.
When switch S1 is open (off), pin 1 is tied to Vcc through the resistor. Since pin1 is a high impedance input, a voltage meter or logic probe placed on pin 1 will show Vcc (+5v) if connected to pin 1.
When switch S1 is closed (on), pin 1 has a direct connection to GND, which takes it to the low state. The pin1 side of R1 also has a direct connection to ground. Current will flow from Vcc, through R1, and to ground. It isn't considered a short, however, because R1 will limit the amount of current that can flow to a very small amount.
At 5:29, it exposes my problem; I figured out that arduino's internal resistance helps to push the current into ground.(Current takes the path of less impedance)
"The reason it decides to flows to ground as rather into the microcontroller."
The current is split between paths according to the ratio of two resistances. If one of those paths is a dead short then the ratio is 1:0. If the resistances are the same the ratio is 0.5:0.5
actually, afaik, the impedance of an I/O atmega328 configured as input is about 100MOhm, no current actually goes through it . Which means that, without a pull-up or a pull-down resistor, Vin is at a floating value, depending on the environment... if you touch it etc.... that's why you need either a pull-up or a pull-down resistor.
alnath:
actually, afaik, the impedance of an I/O atmega328 configured as input is about 100MOhm, no current actually goes through it . Which means that, without a pull-up or a pull-down resistor, Vin is at a floating value, depending on the environment... if you touch it etc.... that's why you need either a pull-up or a pull-down resistor.
I'm not sure what it is, but it's certainly very high. I chose 1M? purely as an illustration and to keep the numbers reasonable.