I want to use a reed switch in a button cell based project. If the reed switch is used like this
then it consumes current when the reed switch is closed. One way of reducing power is to increase the value of 1K resistor. Is there any other way to interface the reed switch to an MCU that consumes no power or sub uA power?
The physical resistor serves only to prevent the pin floating too much (to prevent high currents in the pin input circuit). The internal pullup is enabled only for long enough to read the state of the pin - the 4M7 resistor by itself wouldn't be reliable in preventing noise pickup.
Note that if you want ultra low power operation all unconnected pins must be set to INPUT_PULLUP
to prevent current flow through due to floating pins - this can be a few mA if they just happen to float
mid-rail.
MarkT:
the 4M7 resistor by itself wouldn't be reliable in preventing noise pickup.
Not even with the help of a small cap in parallel? 1-10nF or so. Of course It does take a while (5-50 ms) for the pin to be pulled high when the reed switch opens again... but that's probably not an issue.
@OP: modern LEDs are pretty bright with a 1-2k series resistor, and you may even PWM them at 50%, that's near 100% brightness to your eyes. Saves heaps of power!
wvmarle:
Not even with the help of a small cap in parallel? 1-10nF or so. Of course It does take a while (5-50 ms) for the pin to be pulled high when the reed switch opens again... but that's probably not an issue.
@OP: modern LEDs are pretty bright with a 1-2k series resistor, and you may even PWM them at 50%, that's near 100% brightness to your eyes. Saves heaps of power!
A small cap would mean having to wait after powering up the internal pullup before reading the
pin, involving more charge flowing than without it. Noise pickup only matters when reading the pin
I think, its probably of no consequence otherwise.
Actually scratch that, you're right, but I think you can just save the cost of a cap.
With the cap you can use an interrupt to wake up the MCU when the reed switch is activated.
Come to think of it - you can just use the internal pull-up, upon triggering of the reed switch the interrupt wakes up the MCU and you immediately switch off the internal pull-up. No need to wake up frequently (less power use) and faster reaction (no need to wait until next poll).
Now going to sleep when the reed switch is still closed becomes an issue, as you don't want to activate the internal pull-up yet, let alone stay awake until the reed is opened again.
As on the above drawing, use another pin, say D6 connected as shown. Configure it as output ( pinMode(6, OUTPUT) ). Set it to LOW ( digitalWrite(6, LOW) ). That consumes NO current BUT you also do not measure the switch state. WHEN you want to measure - and only then - set the pin 6 HIGH, wait 1 millisecond and then read the pin 4, right after that set the pin 6 again to LOW. If you measure e.g. once per second, your consumption will have duration only 1/1000. If the switch in ON and the series resistor is 1K, AVERAGE consumption goes to I = V/R = 5V/1K = 5mA. 5mA / 1000 = 5uA.
That's the concept. Increase the resistor and / or the sampling interval and consumption can go reaaaly lower than that. I believe the code is super easy. Note also that you can keep a low enough resistor that way (near one KOhm). You can increase the resistor as well but keeping it low you have a solution very immune to noise of long wires. I assume you will need great autonomy on a battery and in that case it is the average current that counts in battery depletion, not the instantaneous value of it (taking about <10mA).
Yes that's probably the cleanest approach, at expense of one extra pin and external resistor. No need to
wait longer than 1 microsecond though, 1k is pretty low impedance and stray capacitance is unlikely to be
anything like 1nF.