Getting positive charge

When I extend the green wire with plain speaker wire (about 2m) it sets it. If you touch it with your finger it also sets it off.
Someone at core suggested a resistor somewhere to prevent it.
If anyone has any ideas that would be amazingly helpful

1 Like

Hi Justin,

Welcome to the forum and thanks for including such a thorough diagram of your circuit :slight_smile:

I think you’ve narrowed down the problem pretty well to that 2 meter long green wire. What is likely happening is that the logic at the input of Pin 6 is tied to ground when the switch is pressed and “floating” when the switch is released, or the wire is unplugged. That is there is nothing that is making the pin read a 0 or a 1, so it’s dithering back and forth between them, or when you touch the wire you provide a high resistance to ground and it toggles as you’ve completed the circuit.

The fix for this is either a Pull-up or Pull-down resistor. If your circuit uses ACTIVE LOW logic and is triggered when the button connects to ground, you need a moderate value resistor that means that everytime the button isn’t pressed, there is a path to VCC with some moderate resistance. I’ve linked a couple of guides below that explain this phenomenon at varying levels of technical jargon just in case it doesn’t click from my quick explanation.

The important takeaway for digital inputs is to remember that an input pin connected to nothing will not read zero, it will read random voltage levels.

Hi @justin249930
Another useful bit of info that talks a bit more about the resistor value for a pullup

Murray

1 Like

The Mega has an internal pullup resistor that can be configured when the status of the pin is set (“INPUT_PULLUP”). So an external pullup resistor is not required.

1 Like