1

I understand how pullup and pulldown resistors work with push buttons and I also understand that an analogous idea can be applied to slide switches. Furthermore, I know that some versions of Arduino have an internal pullup resistor that can be used, if you adjust the code properly.

I was wondering, if I can, without using the internal pullup resistor, wire a slide switch without any kind of resistor like so:

enter image description here

As I understand, this should behave exactly the same as using a pull-down resistor. If the switch is on the left side, pin 7 would read LOW and if the switch is on the right side, it would read HIGH.

Is that a problem with wiring the switch like this? Is there a reason why using a resistor would be better?

In my final project I intend to use a Digispark board and I would not like to rely on its internal resistor and I also would like to avoid using an external resistor if I can.

1
  • 2
    Whats wrong about using the internal pullups? Thats easier than your circuit because you don't need the 5V connection. And for the code its just a pinMode(pin, INPUT_PULLUP) instead of pinMode(pin, INPUT). And a real life switch might have a short time where nothing connected during thr switching action. For handling that you might need to increase the debounce time with your setup.
    – chrisl
    Oct 15, 2021 at 23:28

1 Answer 1

2

You may be able to do it, or you may not. It depends on the switch.

There are two classes of slide switch:

  • Make-before-break
  • Break-before-make

In the former the contact you are sliding to is connected before the one you are sliding away from is disconnected. This can cause untold problems as you will basically create a short circuit between 5V and GND. Everything will die.

In the latter the contact you are sliding away from is disconnected first, and then the new contact you are sliding towards is connected. That is safer, but it does mean that there is a short period while you're sliding the switch where neither contact is connected. At this time the input pin is floating - just as if you had nothing connected at all (which is in fact the case).

That is of course not a desirable scenario as it's probably the most amount of bounce you will ever see in a switch - bounce you need to eliminate in software to give you a clean signal.

That period of uncertainty is eliminated if you have a pullup or pulldown resistor, since there is never a period where there is no connection, and there's never a period where you risk shorting out power and ground. All you have to content with then is the natural bounce of the contacts as they close.

4
  • Now I understand the importance of a resistor. One last question, though. Is there a difference between using a pullup or a pulldown resistor? Or can I use either? Oct 16, 2021 at 4:25
  • 1
    It makes no difference, you can use either.
    – Majenko
    Oct 16, 2021 at 7:32
  • I'm not sure how common they are, but a Make-before-break switch will still be a problem, even if there's a pullup or pulldown on the center wire.
    – PMF
    Oct 18, 2021 at 8:49
  • 1
    @PMF only if you continue with the (now pointless) connecting of both power and ground.
    – Majenko
    Oct 18, 2021 at 8:59

Your Answer

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

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