I have digital pin 7 when set to High it does and when set to low it does not.

The only way I can get consistent High or Low is to use a 2 position 3 pin switch with my pin 7 in the middle and ground on one side and 5v on the other.

Is there a way I can use an simple Open/Close switch and still get the same function?

As of not if I dont "pull" pin 7 to ground I get both open and close randomly.

  • 1
    Have you configured the pin as input? Please provide the code and your wiring diagram. A not connected pin, that is set as input, catches random noise, thus changes state rapidly.
    – chrisl
    Mar 3, 2020 at 19:29
  • Yes the pin is set to input, is there a way I can remake the circuit were it does not catch noise when it is open?
    – Sharpie15
    Mar 3, 2020 at 19:44
  • output+dwrite(low) doesn't ground it?
    – dandavis
    Mar 3, 2020 at 22:08

1 Answer 1


Seems like you already found the solution. Without a pull-down of pull-up resistor, the voltage at pin 7 will float to some random voltage, when the switch is open.

Either add an (external) pull-down resistor. Or flip things around and use the internal pull-up resistor inside the ATMega328p. Then connect the other side of the switch to GND. Whenever the switch is pressed, your digitalWrite gives you a LOW.

To use the internal pull-up use pinMode(7, INPUT_PULLUP);

  • 1
    This worked perfectly thanks for the advice it was super helpful.
    – Sharpie15
    Mar 4, 2020 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.