0
\$\begingroup\$

I have seen some examples why we need to use pull up/down resistors, but do I need to use it if I use switch with common terminal?

If I have the schema like so, do I need to use the pull up/down resistor anyway? My schema

The input should either read high or low right?

\$\endgroup\$

3 Answers 3

4
\$\begingroup\$

Typically switches are non-shorting (just as well, or you'd short out your power supply). The switch contact thus spends some finite time "open" each time it is switched. During that time (which might be some milliseconds) the MCU input could drift around or pick up noise. If that's not an issue you don't need the pullup or pull down.

Generally though it's inconvenient to use SPDT switches because of cost and availability of switch designs (SPST N.O. are much more common and cheaper- tact switches and membrane, for example) and extra wiring and typically there are internal pullups and/or pulldowns (though perhaps of too high value to be optimal for noise considerations) so the pullup/pulldown is most often used, either internal or external.

There may also be situations where you want a defined state even if the switch fails or is partially or completely disconnected. Or maybe the 'switch' is a jumper block and you can't count on the user to place it correctly and don't want to deal with the consequences of a floating input.

There is one clear advantage of your circuit, and that is that there is only leakage current drawn in either position, which could be a consideration for battery power. That's also a subtle issue in that most switches require a minimum "wetting" current to be guaranteed to work, and your circuit will conduct only nA typically. Here, for example, is a tact switch from a reliable manufacturer:

enter image description here

If the minimum current is not stated by the manufacturer, you should assume it's in the mA, especially if the part does not have precious metal contact materials.

\$\endgroup\$
3
\$\begingroup\$

The input should either read high or low right?

Mechanical switches often have a gray area where it doesn't connect to either terminal. In this intermediate state the input would be left floating. Some switches can be forced and kept in such a position. If this is an issue for your application is something to consider.

I would often opt for a pull-up/-down resistor, where you can't have a floating state. All the better if it's connected to an MCU with internal pull-up/-down resistors.

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
1
\$\begingroup\$

As you noted correctly, when using a switch with the common terminal connected to your uC, your uC will always read either low or high. So imo your solution should work.

The reason pullups/pulldowns are often discussed is because pushbuttons are used most of the time, in which case you need them.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Except it is unknown what it reads while the switch is being switched so the terminal is floating at indeterminate voltage before it hits either GND or 3.3V terminal again. Depending on the switch and the program used to read the pin, it may take long enough to switch that the pin is read multiple times with values that wiggle randomly and the program thinks the switch is being rapidly switched. \$\endgroup\$
    – Justme
    Commented May 12, 2023 at 13:27
  • \$\begingroup\$ @Justme good point, genuinely didnt think of that. Good to know! \$\endgroup\$ Commented May 12, 2023 at 18:32

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.