Switch to Microcontroller digital input: default ground or Vref? - Page 1
Forum section: electronics / beginners

author: Watth
author_rank: Frequent Contributor
timestamp: January 03, 2025, 05:49:08 pm
content: Hey everyone !When designing a circuit where a tactile switch is connected to a microcontroller GPIO, is it preferable to have the signal compared- to ground (with pulldown resist and the switch activation detected as HIGH) or- to Vref (with pullup resistor and activation of the switch read as LOW)?Is this choice in consideration to the µC or PCB design, or other?Thanks for reading!

author: PGPG
author_rank: Frequent Contributor
timestamp: January 03, 2025, 07:04:52 pm
content: I had to position such switch under one of holes destined for terminal blocks in DIN-rail case.I connected its one pin (it was 2 pin tact-switch) with GND and rotated it such that this pin was first from the PCB border assuming that if someone will be doing something near terminal blocks and ESD could happen to be it to that GND connected pad and not the opposite one.

author: SteveThackery
author_rank: Super Contributor
timestamp: January 03, 2025, 07:10:25 pm
content: Most of the circuits I've come across have a pull-up resistor on the pin, and the switch - when operated - connects the pin to ground. So it's an active low input.I've been told it is considered bad to have Vcc connected directly to the switch, which is how it would be if the switch operated as a pull-up. Something to do with reducing the amount of wiring and exposed connections with Vcc on them, to reduce the chance of accidental shorts.

author: golden_labels
author_rank: Super Contributor
timestamp: January 03, 2025, 07:50:14 pm
content: I don’t know, but consider it may be “inherited” from other situations:Pull-up and active ground is the only option for open collector outputs.The input pin uses ground as the reference. So the active signal is unaffected by noise at all, while inactive signal noise is a bit limited by the resistor and notably above the threshold level. This would be a thing to consider in the past.

author: prints-f-darkness
author_rank: Contributor
timestamp: January 03, 2025, 08:17:05 pm
content: Hi,In the microcontroller world, VREF is typically used internally for the ADC, DAC or OPAMP peripheral (it serves as a known reference voltage).The GPIO only sees anything above like .7v or 1.2v (threshold will very) depending on the IC, so it would make the most since to use VCC not VREF.Some MCU's actually have an internal pull up or pull down on the GPIO.What I use is a simple circuit found on hackaday (https://hackaday.com/2015/12/09/embed-with-elliot-debounce-your-noisy-buttons-part-i/)I really like this circuit for 3 reasons, its got hardware debounce (less code), its simple, and there is a series resistor on the switch, so any HV transients will be reduced before hitting the GPIO.(Some MCU's can have ESD protection built into the IC's GPIO)See page 1https://www.st.com/resource/en/application_note/an5612-esd-protection-of-stm32-mcus-and-mpus-stmicroelectronics.pdf

author: DavidAlfa
author_rank: Super Contributor
timestamp: January 03, 2025, 09:14:24 pm
content: Generally it's more common to pull to ground, most mcus can enable weak pullups, this way the only required part is the button itself.