Minimum current needed to activate pin?

I am seeing multiple people that recommend using the following type of setup for a NC switch:

image

However this configuration results in a constant current draw of approximately 300uA.

Whereas omitting the third wire such as this setup:

results in a constant draw of only ~70uA

I am seeing more people recommend the first configuration despite it using so much more current. I'm not sure why.

Also, what is the minimum current that can be used to accomplish this task, while saving battery power?

Because most applications don't put the processor into sleep modes, the extra current is then a miniscule fraction of the operating current.

You could use a very high impedance like 1M ohm, but noise would be a problem and you would have to put a filter capacitor on the input, this would also have to stay small because the time constant of an RC circuit is proportional to the resistance.

The digital input itself has almost no current, it's in the nanoAmps when the internal pull up resistor is disabled.

The difference is surely value of the pull-up or pull-down resistor. The internal pull-up is probably substantially higher than the 10k pull-down resistor illustrated.

Comment on the 2nd case (with no resistor)........

Assuming the the switch is normally closed. Without a resistor, when it opened there would be no voltage / energy to change the state of the digital input.

As stated above, the internal pullup will draw less current that your 10K resistor.

If you wanted to go to 1 MΩ it would work fine IF no noise was picked up on the Reed Switch to NodeMCU input are short.

If they are long you might be able to have a reliable signal if you put a 0.1µF capacitor at the input of the NodeMCU digital pin and twist the wires.

The reason you need pull-down resistor is simple: if a input pin is not connected to anything, is the voltage High? Low?
In that case the voltage is undefined and thus will vary greatly due to electric noise.
You don't want that to happen, so you connect a resistor so those stray current have a place to go to. That resistor can either pull it High (pull-up), or pull it low (pull-down).

It have more to do with the location of the pull-down resistors.

In the first case the pull-down resistor is external while on the second case you are relying on the ability for the processor to pull it low internally
Some processors (or chips) might not have this ability, and so in those cases you will need to add a pull-down resistor externally.

A example of when you need to use this:
Imagine I have a chip that convert 8 parallel input to a single output of a byte when clocked. That chip is a simple 74HC165D.
And because that chip do not have pull-down resistors, I have to add them externally.

The value of the resistor can be anything from 100 ohm to 100K ohm (or 1 million ohm). The lower the value is, the greater the current. The higher the value is, the lesser the current. However, as the value increase the voltage decrease (once the switch return to the open state) will decrease. As a typical rule of thumb the average value is 10K. In my design I use 20K (which in theory halfs the current). Does it work well? Of course. I can't see any problem when polling them at 60Hz.

But as mentioned, the current draw of the microcontroller is far more (10 to 100 times more, depend on load and the size of chip) and thus this is usually not a concern.

Basic engineering inexperience. :roll_eyes:

Indeed - once you have wires going off to some remote switch you've got (capacitive) noise pickup to deal with - that needs a low impedance to AC ground, and depending on the length and style of the cabling that might be anywhere from 1k to 20k or so. Internal pullups are generally too weak for off-board signals, they are provided as a convenience for on-board signalling without too big a power penalty.

Some CMOS chips have keeper circuits on their inputs which lock a floating input to the current state (by small current sources of a few microamps). To overcome these you won't get away using 1M pullups for instance, so there are practical
limits to the values of pullups in various situations.

For micro-power situations you would simply arrange that any switch was normally open to avoid this power drain, or else just switch off the pullups during power-down (you would need this for a quadrature encoder for instance). You wire a physical pullup from an output pin, not Vcc, and have the pin HIGH during operation and LOW during sleep.

Which is freely passed around on the web, to be accepted and trusted by other inexperienced people.

@aarg Yes, I found that trying to increase the resistor value to even 100k resulted in the state change no longer registering. I did not try a filter cap however.

@MarkT Obviously most reed switches are NC for security reasons, and I did not have any of the other style on hand. I suppose I should just use a NO switch. My application is not a security system, and only cares about battery efficiency in case of a power loss anyway, as it will be mains powered otherwise.

Highly suspicious! I want to see a complete schematic and photos. It really should have worked - even if not very well.

I noticed a few days ago when you posted the original 2 diagrams there, that the first one is susceptible to misinterpretation. So it's possible you have miswired things.

Another dangerous thing is that some ESP boards have on board resistors attached to some of the I/O pins... so exactly which board are you using, and which pins?

I must assume it is wired correctly; it works perfectly when using the 10k resistor, and then stops working when I substitute the 100k.

(Mini-grabbers go to reed switch)

This is why I had assumed the board has a minimum current requirement for the pins, although I could not find it in the documentation.

Originally I was using a D1 mini ESP-12F, but I have reproduced the circuit on a NodeMCU ESP-12E and the results are the same.

image



(Also, generally I always use colored wires to represent polarity. However the wires going to the RGB LED do not conform)

What I'm saying, with the ESP boards especially, you have to pay close attention to the characteristics of each pin, also true of UNO and so on, but more so with the ESP. As I mentioned, some I/O pins have special meanings at boot and for that reason may be tied high or low with a resistor. This would battle an external resistor like yours. So you have to consult the pin reference for not only the type of ESP, but the type of specific board that you are using.

Another thing, if the inputs that you enabled with INPUT_PULLUP are the same ones that you want to minimize the current on with the high valued resistor, that would be a mistake because the INPUT option leaves it in high impedance like it should be for this application.

You could try swapping your input pin choices around with the others, if you can't find the information on the board pins.

I just went with INPUT_PULLUP because that's what the original guy went with. How would you recommend I change it?

Given the number of GPIO pins I needed; specifically: 2 OLED, 2 Buttons, 3 LEDs, 1 Switch; I picked those specific pins because of that exact thing you mention. I found the following information regarding which pins should be used:

While I mull over the rest of your post, consider, I already answered this one.

You can not put your switch with your 1M or 100k resistor on any pin that is designated with "pulled up" or "pulled" anything, in the Input column of the chart you posted above. I suspect you have used D4 which does have a pull up (for I2C).

There is only one "original guy" ever, for any technology. It's the design team. Don't depend on uninformed, second hand information to learn and build with. If you do, figure out who the reliable sources are, and double check them if things go wrong.

Right, that's why I picked D5 for that switch, because it had no such notation on the chart.

I used the aforementioned "pulled" pins for the LEDs

image

Regarding this previous statement:

"Another thing, if the inputs that you enabled with INPUT_PULLUP are the same ones that you want to minimize the current on with the high valued resistor, that would be a mistake because the INPUT option leaves it in high impedance like it should be for this application."

It sounds like you were saying there is some way to use a pin as an input without defining it with INPUT in the code. Did I misunderstand?

Yes, it should be INPUT:

pinmode(14, INPUT);