Hi! I would really appreciate some help with this. I'm looking at this tutorial:
There is one thing i just can't understand. I've read the text but still i just don't get it. It is this part:
"If you disconnect the digital I/O pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, not connected to either voltage or ground. It will more or less randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit."
I don't understand why the resistor is needed. If you look at the schematic the resistor comes after the switch, so when the switch is open no current will flow through the circiut (right?), and when the switch is closed the path of least resistance is to 5V. So why does it need to be there? I tried removing the resistor and i just get random reading like it says in the tutorial, but i still don't get why.
The left side of the resistor is always connected to the blue wire though the internals of the switch.
This means the blue wire is connected to GND thus the blue wire pin sits at essentially 0V.
When the switch closes, +5V goes to the left side of the resistor/blue wire/the input pin.
Therefore on a push, the input pin goes form 0v (LOW) to 5v(HIGH).
The input of the Arduino is a high impedance input. That is, the input required nearly 0 current to go from hi to low or low to hi. When left unconnected, the input has not definite direction (i.e. hi or low). So any electrical noise that might be picked up by the open pin could drive it hi or low and often bounces between the two states (i.e. Hi / low)
If you look at the schematic without the switch. The resistor being connected to ground forces the arduino input to ground.
Now adding in the switch:
When the switch is
open, the resistor (as stated above) forces the input pin to ground.
When the switch is
closed, the switch overcomes the effect of the resistor and forces the input pin high.
This entire circuit is about the principle of floating pins. I could start giving you a very complicated explanation, or you just look at the video below, where they explain the floating pin state very good.
and when the switch is closed the path of least resistance is to 5V
The path of least resistance is irrelevant as far as electricity is concerned. Electricity will always take or flow through ALL possible paths, it does not choose one path over another. The amount of current flowing in any path is determined by the resistance of that path.