I'm trying to figure out how the button works with Arduino in detail. According to my tests, when an input pin is supported with 5V, it reads HIGH; when an input pin is supported with GND, it reads LOW. That's why we connect the input pin with GND, and we connect the 5V with the other side of the button. However, if we do this directly, a short circuit will occur. So, we put a 10k resistor between the input pin and GND. These are my observations. I hope I'm correct. I would like to ask a few questions:
-Connecting 5V with GND directly causes a short circuit, but why a 10k resistor prevents this? And why 10k?
-How could input pin reach GND through 10k resistor and read LOW, while the resistor can block 5V from reaching GND? Which is that resistor blocks 5V and so the short circuit but does not block the input pin so it can read LOW.
-Could you give me at least information about the operation of the button with Arduino?
I'm sorry for my type of using the language and the grammar. Hope you understand. Thanks.
See attached. Resistor isolates the pin from 5V to reduce current flow. Also protects the pin in case it is set to OUTPUT. Pin can handle High and Low current thru a resistor. Low output while connected to 5V will break the pin.
Additional to the sticky posts I recommend you investigate Ohms Law and Voltage Divider. Start with Wikipedia and then use a couple of resistors and a multi-meter to confirm your calculations. With 70 posts here you are ready.
aatabag:
-Connecting 5V with GND directly causes a short circuit, but why a 10k resistor prevents this?
Short circuit just means unintended path with low resistance causing an excessive current. If the circuit expects a 100k resistance a 10k resistor would be a short circuit. Both the wire and the 10k resistor close the circuit and cause a current.
aatabag:
And why 10k?
If the value of the resistor is low a large current will flow when the button is pressed. This will drain the battery, create heat and stress the power circuit.
If the value of the resistor is high (in extreme case, no resistor) and the button is open the internal circuit of the pin will create the voltage level at the input. We say the signal at the pin is floating its nether high or low. We do not want that.
10K is just a good starting point and a common resistor value.
aatabag:
-How could input pin reach GND through 10k resistor and read LOW, while the resistor can block 5V from reaching GND? Which is that resistor blocks 5V and so the short circuit but does not block the input pin so it can read LOW.
All the resistors in the input circuit (e.g., the physical resistor and the circuit inside the chip) will create a voltage divider. The voltage at the pin will be between GND and Vcc (not exactly GND or Vcc).
If the voltage is sufficiently close to GND the logic will be in the LOW state. In the datasheet the range is called Input Low Voltage.
If the voltage is sufficiently close to Vcc the logic will be in the HIGH state. In the datasheet the range is called Input High Voltage.