Can I ask why most of the examples of using an analogue in for multiple button presses, hold the value high and pull it low upon a button press?
My thought would be the other way around (held low and pulled high).
Just wondered

Can I ask why most of the examples of using an analogue in for multiple button presses, hold the value high and pull it low upon a button press?
My thought would be the other way around (held low and pulled high).
Just wondered

Both ways are equally valid in terms of the logic. It is humans that tend to think of on as HIGH or positive. What do you see as the advantage of doing it the other way round ?
Someone with more knowledge than me will no doubt be able to explain the electrical/electronic advantages of active LOW logic
I don't know Bob. I Googled the method (to find recommended resistor values) and just noted that nearly all the examples were held high by default.
I have always switched low to high. I suppose there is little difference?
I know that your question relates to analogue input, but when it comes to digital inputs it makes sense to use INPUT_PULLUP in pinMode() to activate the built in pullup resistors so that external components are not required
My understanding is that one reason pulling logical low is that n-type semiconductor is more conductive (more holes IIRC). So it was 'easier' to produce 'better' transistors (NPN or N-ch), these are easier to arrange to switch to a logical low state.
I think that you will find Nch FETs or NPNs tend to be used for higher power applications for this reason.
Caveat; I picked this nuggest up decades ago, so I am going from memory. I guess someone will correct if I'm wrong.
My understanding of the reason is much more mundane, practical, safety-related.
Frequently, buttons/switches are mounted on a control panel, a little way from the main circuit board. Often, and particularly before plastics became so cheap and commonplace, that panel is made of metal, maybe the whole case is metal, and grounded. The arrangement where a switch pulls the MCU input pin to HIGH would require a trailing 5V wire from the circuit board to the control panel. If this wire came loose or its insulation became damaged somehow, it could touch something grounded and there would be a high-current, damaging short circuit. But with the pull-up method, the wires going to the button cannot cause a damaging short, even if they come loose or the insulation gets damaged. There would be a malfunction, but not a damaging one. So it's safer.
Most ICs can sink (current through GND) more current then they can source (current through Vcc), which makes it safer to always sink current (always pull up passively and then connect to GND actively). You'll see this in protocols like I2C, in IC like GPIO expanders and analog switches, as well as most schematics like the one you mentioned.
We are talking about an input pin here, not an output pin. Input pins are high impedance: they will only source or sink a tiny current.
I have added your explanation to my "prompts" library as I apparently failed to do so with my last explanation posted to the (well, some) forum. Well put.
In addition to that, exposing the Vcc (5 V) outside of the precinct of the MCU itself may facilitate pickup of - or radiation of - interference and transients. The same is less likely to occur with the ground as it is more highly interconnected and thus a lower impedance.
But on the ATmegaxx8, A0 to A5 are in fact digital pins, and INPUT_PULLUP also functions on those analog inputs. ![]()
Since you use them in common-emitter mode. So actual TTL logic levels pulled down to ground, but only pulled up halfway to 5 V.
I also could be wrong, but understand that the epitaxial fabrication processes for ICs initially substantially favoured the production of NPN devices.
Except CMOS.
Nevertheless this is (part of) the reason for the preference for "negative logic".
Which indicates your "newbie" unfamiliarity with digital electronics. But that's OK, now you know. ![]()
You say newbie.... but been doing it like that for 15+ years ![]()
I am not building life support machines, so I think the world is safe
Just teasing. ![]()
Never too late to learn something. Well, sort of. ![]()
Hi,
In some industrial/commercial applications where an analog ladder, or in this case a pot, sends a voltage back to an MCU, say on a crane lanyard or long remote cable.
Extra resistors are added.
Should any wire fail, the analog input will fault to > 4.58V or <0.42V, software monitoring the analog input would then signify a fault.
Tom...
![]()
PS. Similar method in burglar alarm window or tamper switch circuits.