Electronic – Arduino thinks I pressed a switch when I touch anything


So I have found something very strange and confusing, When I touch anything even my desk my arduino thinks I connected to the input of any pin I pick.

here is a video of what is happening

it even does it when connected directly to a battery

here is the video

Best Answer

Floating input is influenced by the charge on your body. Put a 10k resistor on that input (the switch input, that is) to GND or VCC and that behavior should largely go away. You can also probably get away with enabling the internal pull up / down on the pin in software (the second argument to the pinMode function in Arduino-speak).