0

I have a "normally closed" magnetic door sensor, that I'd like to use with an ATtiny microcontroller.

Does a "normally closed" switch use more power than a "normally open" switch?

i.e. since the switch will be closed 99.9% of the time, will some current flow through the switch, thus wasting battery?

Or is there a way to make a "normally closed" switch not use more than a "normally open" one?


Note: This is a low-power project (goal: 1 year with a set of batteries):

  • ATtiny powered with 2 or 3 AA batteries, I'm thinking about using ATtiny85 "V" for powering with as low as 1.8V

  • I'll use "deep sleep" features to use very few power (see https://jeelabs.org)

Basj
  • 1,856
  • 4
  • 27
  • 48
  • Look at https://electronics.stackexchange.com/questions/344574/smart-ways-to-detect-a-button-less-power-consuming/344576#344576 – TonyM Nov 14 '19 at 10:50
  • 1
    You have already accepted an answer, but check the datasheet for your processor and look for the **maximum** input leakage current. For reliable operation the current through your pullup/pulldown resistor should be **at least** 5X that value. For the ATtiny you should plan to draw at least 5\$\mu\$A through your pullup/pulldown. That's why you never see really large pullup/pulldown resistor values in well-designed systems. – Elliot Alderson Nov 14 '19 at 13:07
  • @ElliotAlderson given this information, which max resistor value would you use? (just to be sure) – Basj Nov 14 '19 at 13:39
  • That 1uA is a **maximum value**, I challenge anyone to find a working chip that actually has such a high input current. OK, if you're going to produce millions of your gadget then this is an issue to consider. If this is a one-off for a hobby project, try 3.3 Mohm and see how that works. If that appears unreliable, go lower to 1 Mohm or less. – Bimpelrekkie Nov 14 '19 at 14:33
  • @Bimpelrekkie So what **is** the actual maximum current? Do you have data to support a design decision based on a lower value? Over temperature? Over voltage? If you have data that is useful here, provide it and back up your claim. – Elliot Alderson Nov 14 '19 at 15:27
  • If you are operating at 5V then a maximum resistor value of 500k\$\Omega\$ would be prudent, in my opinion. Please note however that this resistor may not be the only cause of wasted power...we really need to have a look at the entire circuit. – Elliot Alderson Nov 14 '19 at 15:30

2 Answers2

3

Indeed a normally closed switch means that a current must flow otherwise you cannot detect when the switch opens (and there is no more current flow).

Fortunately there are several ways to minimize the current consumption.

The simplest way is to use a very high value pull-up (or pull down if you prefer) resistor, a value of a couple of Mega-ohms will reduce the current to a few uA which should not affect battery life much as a microcontroller will also consume a few uA on average when it is in deep sleep mode and only wakes up occasionally to check if it needs to do something.

This is an example schematic:

schematic

simulate this circuit – Schematic created using CircuitLab

It could be that you're using long wires to the switch and then using Mega-ohm pull up/down resistors might not work reliably.

Then another option might be better if it is OK to "poll" the state of the switch, check it every second for example instead of continuously. For that, configure an output of the micro to become high for a short time every second, connect the switch + pull up resistor to that output. Monitor the voltage across the switch as you would normally do. Then when the output is high, monitor the input.

Here's an example schematic:

schematic

simulate this circuit

If this circuit would run on 3.3 V, only 1uA would flow during the polling of the switch. Suppose I poll the switch for 10 ms every second then my duty cycle is only 1% so that would make the average current only 0.01 uA !

Obviously this only works if you do not need to know the state of the switch immediately.

In conclusion I do not think that there is a way to make a normally closed switch use less current than a normally open switch!

However, that isn't really an issue as we can make the design such that the impact of the additional current is negligible.

Bimpelrekkie
  • 80,139
  • 2
  • 93
  • 183
  • Thank you very much for your answer! PS: can you add a schematic for the first case too (just the simple pull up): "The simplest way is to use a very high value pull-up" to make sure I'm doing the same way. – Basj Nov 14 '19 at 08:49
  • 1
    Done but note how similar both schematics are! The only difference is that the resistor connects to Vdd or to an output. In the second schematic you do need to add code to toggle that output though. – Bimpelrekkie Nov 14 '19 at 08:54
  • Thanks a lot for your update! PS: of course, I'll disable the internal `PULL_UP` of the ATtiny, is that right? – Basj Nov 14 '19 at 08:55
  • I suggest that you read some tutorial on using switches with a microcontroller. In the program you first make the output high, wait 5 ms, then use digitalRead on the input, wait 5 ms, make the output low. Repeat that every second. Yes you **must** disable the internal pull up/down as that would overrule the high value resistor. – Bimpelrekkie Nov 14 '19 at 08:57
  • Last thing @Bimpelrekkie: would a megaohm resistor work with an [ILS magnetic door switch](https://www.ebay.fr/itm/Capteur-magnetique-de-porte-blanc-Arduino-interrupteur-ILS-detecteur-DIY/323567009088)? – Basj Nov 14 '19 at 10:12
  • @Basj Yes it should work with such a switch. Inside that magnetic door switch is a "reed switch", see: https://en.wikipedia.org/wiki/Reed_switch which closes when a magnet is nearby. – Bimpelrekkie Nov 14 '19 at 11:09
  • Given that microcontroller inputs may specify a maximum leakage current of 1\$\mu\$A your 3.3M\$\Omega\$ sounds dangerously high to me. – Elliot Alderson Nov 14 '19 at 12:59
  • @ElliotAlderson Then use 1 Mohm :-) The chance that you will actually run into a uC which will actually have that 1uA input current is **very small indeed**. That 1uA is, I think, the decision point at which, during production testing, the manufacturer decides if the chip is OK ( I < 1 uA ) or not OK ( I > 1 uA ). – Bimpelrekkie Nov 14 '19 at 14:28
  • @Bimpelrekkie The data on actual leakage current would really be helpful for the readers here; I wish you would share it. Does "very small indeed" mean a 1% chance, a 0.000001% chance, or something in between? – Elliot Alderson Nov 14 '19 at 15:51
  • @ElliotAlderson Only the manufacturer might know but I doubt that they keep that data as they do not care what that input current is as long as it is low enough. Note that this current is mainly caused by leakage currents of the ESD protection diodes. This leakage current isn't predictable (there is no step in the manufacturing process to tweak it to a certain value) so that's why the specification is set quite high, the manufacturer knows 1uA or less is nearly always achievable and "good enough" for most practical needs. – Bimpelrekkie Nov 14 '19 at 18:28
  • +1 on using polling to only activate the pull up (and the power path) periodically to check the state of the switch. The ATTINY is particularly well suited for this because you can (1) use an internal pull-up which can be activated and deactivated very quickly in the pooling code, and (2) you can use the WDT to sleep at very low power between polls. – bigjosh Nov 23 '19 at 00:06
1

Yes, but the signal will be primarily voltage on a MOSFET gate, not current flowing. Each pin on the microcontroller also has some protection diodes. All in all, you will have some leakage here, but the impact will be absolutely minimal.

In the datasheet of the ATtiny85, in section "Electrical Characteristics" you can find all relevant values. Input leakage at 5.5V in high-state is <50nA. This is around ~0.438mAh per year!

If you need a pull-down resistor, you have to calculate this cost as well. The value depends on the length of the cable, insulation or shielding and the amount of inference you get.

Let us assume a 5MΩ resistor is working, I = U/R, so at 5V there is 1µA flowing through this resistor. This is a cost of ~1mAh per year.

If you use two 2850mAh batteries, you can ignore this cost completely. The microcontroller itself will use more current.

Polling using just one pin

As mentioned in my comment, there is also the possibility to implement polling with just a single pin, using a capacitor.

schematic

simulate this circuit – Schematic created using CircuitLab

The 100Ω and 1µF are just examples. Also, the parts in the dashed rectangle are just for the simulation.

The idea is, first set the pin as output and set it to high for e.g. 1ms, switch it back to input, wait 1ms and read the value.

If the switch is closed, a short time (depending on the values of the resistor and capacitor) are back to GND levels.

closed

If the switch is open, the voltage stays high for a longer time.

enter image description here

Flovdis
  • 561
  • 1
  • 6
  • 21
  • Thank you for your answer!! PS: it's mAh (electric charge) and not mA/h, can you edit (I can't because it asks to update more than 6 characters ;))? – Basj Nov 14 '19 at 09:10
  • Indeed, thank you! I fixed it. – Flovdis Nov 14 '19 at 09:12
  • Do you think a megaohm resistor work with an [ILS magnetic door switch](https://www.ebay.fr/itm/Capteur-magnetique-de-porte-blanc-Arduino-interrupteur-ILS-detecteur-DIY/323567009088)? – Basj Nov 14 '19 at 10:12
  • It looks like a mechanical switch. The length of the cable and inferences are more critical. Your question was if you should use this switch because of the current loss. The answer was, don't worry. So I suggest, buy the switch and experiment with a prototype and different resistor values. Also, the polling method is a great way to save energy if you have an output left. Using a capacitor, you can implement polling even with the same pin you use as input. – Flovdis Nov 14 '19 at 12:12
  • No, the datasheet for the ATtiny specifies a maximum leakage current of 1\$\mu\$A. Any pullup/pulldown resistor over 1M\$\Omega\$ will be unreliable. – Elliot Alderson Nov 14 '19 at 13:04