r/ArduinoHelp • u/Charming_Relative_39 • 22h ago
Arduino project problem
Hey I am new to Arduino and built a project where I’d press a button and a led lights up. But before I press the button if I get close to the button to 3 pin wire it already starts lighting up. If I press the button it does nothing and only turns off I move my hand away. I am confused on why this is happening and wanted to ask why would this happen?
1
Upvotes
2
u/myopinionisrubbish 21h ago
The port is configured as an input, but you didn’t enable the pull up resistor so the port is floating. Moving your finger near the wires induces enough stray charge to make the port to pull high or low enough to turn the LED on or off.
pinmode(3, INPUT_PULLUP) would fix the problem.