0

I am designing a circuit connected to a simple open-close sensor, like a switch. For ease of construction, the circuit with the sensor switch closes to ground, and uses a 1 MΩ pullup resistor to Vcc to signal HIGH when the switch is open.

I realize that power is flowing the entire time the switch is open, which may (or may not) drain the battery. Would it be more efficient to use a pulldown resistor to ground, and have the switch open to Vcc?

Tangentially, should there be a resistor on the connection to Vcc as well? Either to reduce current (save battery power) or prevent damage to the ATmega328?

Thank you!

2

The input current does not depend on the pin level. Have a look at this discussion from avrfreaks. The input impedance of a digital pin is extremely high. The leakage current of the Atmega328P (here as example chip) is mentioned to be 1uA for both pin states. So this current is both unavoidable and neglectable from a normal view.

But the input impedance of a digital input pin is not only dependent on this leakage current. There is also a capacitance, which will lower the impedance for higher frequencies. So, if you drive the input with higher frequencies, the input will draw more current. But you only have a switch connected to it, which is very very low frequency.

So it doesn't matter, if you pullup or pulldown. The main current consumption will result from the moments, where the switch is activated, since then a current flows through the pullup/pulldown resistor to ground.

Tangentially, should there be a resistor on the connection to Vcc as well?

No need for a resistor there. The input impedance of the pin is already high enough and you don't want to create a voltage divider with your pulldown resistor (which would change the voltage levels at the pin).

  • A pullup or pulldown resistor causes a current flow additionally to the neglectable current into a input pin. and the voltage level matters, of course. – DataFiddler Nov 4 at 13:08
  • The additional current only flows, if the switch is activated, so with a pullup resistor, when the switch connects the pin to ground. Otherwise you have the pullup resistance plus the input impedance in series, which is also very neglectable. Normally the pullup resistor for a switch is big enough, so that the current is also neglectable. – chrisl Nov 4 at 14:54
2

I realize that power is flowing the entire time the switch is open, which may (or may not) drain the battery.

No, it doesn't. You get a small spike as the switch is opened or closed, as the gate capacitance is charged or discharged, but other than that there is negligible current draw by a pin, which remains static regardless of the direction of the biasing resistor.

Tangentially, should there be a resistor on the connection to Vcc as well? Either to reduce current (save battery power) or prevent damage to the ATmega328?

Absolutely not. The current draw of the MCU is not static. That means that the current through such a resistor would not be static, and so the voltage dropped across that resistor would fluctuate too - meaning if the current draw rises above a certain point the chip will be starved of power and will "brown out".

You only need a resistor to limit current when you have a device that cannot control the current by itself, such as an LED or other "non-linear" device.

  • Thank you. Does this mean that the Pushbutton tutorial on the official Arduino site is wrong in having a resistor between Vcc and the input pin? – dotancohen Nov 4 at 20:57
  • @dotancohen No, because that is a pullup resistor. You are on about a resistor between the power supply and the VCC pin (I assume), which is completely different to what that tutorial has. – Majenko Nov 4 at 21:26
  • Ah, I see where the confusion is. When I said "on the connection to Vcc" I was referring to the connection between the input pin and Vcc. I was not referring to the power to the ATmega 328. How should I reword that so that it is clear? Thank you very much for your help, both in teaching the proper wiring and in helping improve my question phrasing. – dotancohen Nov 4 at 21:55
  • I am not really sure what you are asking in that question now. If you have a pullup resistor then you have a pullup resistor. If you have a pulldown resistor then you have a pulldown resistor. What actually are you asking about when you ask about a resistor to vcc? That is a pullup resistor. If you have one then you have one. What are you asking "As well?"...? – Majenko Nov 4 at 22:30
2

If the sensor does provide two defined voltage levels, you do not need a pullup or pulldown resistor, but if it's only a switch: either (closed) connected to Vcc or GND, or (open) not connected, you need a pullup or pulldown resistor to get a defined voltage level in case there's "nothing else" (except the wire to the switch catching noise out of the air) connected to the digital input pin.

When the switch is open, the pullup/pulldown resistor is connected to the input pin and nothing but that neglectable leakage current is flowing.

When that switch is closed, some current will flow through that resistor, according to Ohm's law. You have to optimize between that current and the risk of catching some noise signal. Typically, µControllers like the Arduino atmel atmega328p have builtin pullup resistors of ~30k..50k, which should be fine for standard situations.

If you fear the battery drain, you can experiment with bigger resistors, but first make sure to build a scenario where the usual situation is "switch open". e.g. A fridge's door switch should be NC, but pressed while the door is closed. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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