I wired a push button between a microcontroller input and ground. When the button is pressed the pin reads low as expected, but when it is released the reading flickers between high and low, and it changes when I move my hand near the wire.
I understand I need a pull-up resistor. Why does the pin not simply read a steady value when nothing is connected, and how do I choose between 1 kΩ, 10 kΩ and 100 kΩ, or the internal pull-up?




