3

I'm looking for a way that the ESP8266 (or alternative, like an Attiny85 with an RF module) is only turned on once a reed switch (or similar sensor) has been triggered.

The problem is that the ESP8266 should have just enough time to power on and send a message over the Wi-fi network. The reed switch could close too fast for the device to send a signal.

Are there any components I can use to add a minimum power time before the reed switch (or power, somehow) is closed again?

The purpose is to keep the batteries for a long time while also notifying when the reed switch is activated.

  • Do you mean that the reed switch might be closed only for a short time and then opens again before you can get a chance to fully perform your task? – jonk Dec 30 '16 at 15:00
  • It's possible to use a normally open or closed reed switch, as long as I'm able to send a short signal and then stop using the batteries once that's done. The first answer is great, but I'm waiting to see if there are any other ways. – Kevin Van Ryckegem Dec 30 '16 at 15:20
  • If I read you correctly, I'd say there are two ways to go. (1) Circuit starts a timer when reed relay closes with a "too short" time period, but where the CPU periodically "re-starts" the timer until it is done. (2) Circuit starts a timer when the reed relay closes with a "too long" time period, but where the CPU can turn it off, when done. Do you have a preference? – jonk Dec 30 '16 at 15:39
  • What about using a transistor, as suggested by @Dampmaskin? – Kevin Van Ryckegem Dec 30 '16 at 15:42
  • What about the sleep mode suggested by Scott?? Is there a reason you can't consider that idea? And if not, why not? Also, I seem to recall that the ESP8266 accepts 5 V but that this goes through an LDO to generate either 3.6 V or 3.3 V for the actual device and that you may bypass the LDO and directly provide the lower voltage. What supply voltage rail are you providing the device? (I think the peak startup currents are on the order of \$\frac{1}{3}\:\textrm{A}\$, though the operational currents [sans-Wifi Tx/Rx] are lots lower.) – jonk Dec 30 '16 at 16:09
  • Are you supplying 5 V, then? I read that you see 15 mA when sleeping. I read elsewhere this is really about 0.1 mA at 3.3V. So this suggests to me that you are also powering the LDO, too. Just curious what power rail you are supplying. (The ones I have here have TWO -- the 5 V one that goes through an LDO and the 3.3 V one that doesn't go through the LDO.) – jonk Dec 30 '16 at 16:36
  • My mistake! I should've said 10mA. I'm planning to use 2xAA (or 2xAAA, will see how well the batteries last and fit) batteries to power it. I've seen tutorials doing that as well. The device only has to send a notification about 4x a day, otherwise it can stay in deep sleep. – Kevin Van Ryckegem Dec 30 '16 at 21:34
  • When you say "I'm planning" does this mean you haven't tried it yet? If you haven't, then once again I have to ask "are you supplying 5 V when you measure 10 mA?" What are you doing now, what do you know about that situation, what do you want to do, and what do you know about that, as well? Be as complete as you can here. I think the ESP8266 will work off of 3 V (which is about what 2xAA is.) But not a lot lower than that. Which may be a problem. – jonk Dec 30 '16 at 21:38
  • I didn't receive the hardware yet. However, the manual shows that it should have a power usage of about 10mA in deep sleep. In case 2xAA is a problem, I will search alternatives (adding more batteries?). – Kevin Van Ryckegem Dec 30 '16 at 21:45
  • Okay. So. You can't make _any_ measurements, at all, yet. All you have is documentation, for now. Can you at least provide a link to the _exact_ part you are ordering (or planning to order?) I'm beginning to think this question is far too soon for any meaningful response. There are _many_ different implementations of the ESP8266. What is the reed switch being driven by? A flywheel? What, exactly, is the entire mechanism you are considering? (I ask because now I realize you don't even know how long the reed will be engaged nor how long your ESP8266 needs to be on, either.) – jonk Dec 30 '16 at 22:07

3 Answers3

2

Dampmaskin has the right idea, but his design is overly simplistic, for the reasons I outlined in my comments.

A more robust circuit would look like this:

schematic

simulate this circuit – Schematic created using CircuitLab

R1 and R3 make sure that leakage currents in either transistor won't cause unwanted activation of the circuit.

Obviously, the micro must set the GPIO pin high as soon as possible after it comes out of reset, before C1 discharges too far (make C1 larger if necessary). Then, it can set the pin low (or tristate it) when the task it is doing is complete.

You can substitute MOSFETs for the BJTs if you like, in which case, R2 and R4 are not needed (but they cause no harm, either).

Dave Tweed
  • 168,369
  • 17
  • 228
  • 393
  • It's more complicated than I expected, but better to be robust of course! What's the capacitor used for? – Kevin Van Ryckegem Dec 30 '16 at 15:57
  • It's complicated because it is built of discrete components, if you prefer a simpler schematic you can use an IC having most of the needed function in a tiny package, like one intended for switching downstream port power in USB hubs. – Chris Stratton Dec 30 '16 at 15:58
  • See my edit above. Plus, you should have at least one decoupling capacitor on any microcontroller anyway. – Dave Tweed Dec 30 '16 at 15:58
  • What if the reed switch is not closed long enough and uC will not have enough time to turn ON Q1? – Nazar Dec 30 '16 at 15:59
  • @Naz: Even a very short closure of the reed switch will charge the capacitor, which should be large enough to get the microcontroller out of reset. – Dave Tweed Dec 30 '16 at 16:00
  • Peak start up currents can be high: http://www.esp8266.com/viewtopic.php?f=13&t=3875 – jonk Dec 30 '16 at 16:15
0

One possible approach: Let the reed switch power the Attiny in parallel with an NPN transistor (or perhaps an N-channel MOSFET) as a low side switch. When the Attiny turns on, it can output a HIGH to the base of the transistor, turning the transistor on, keeping the Attiny powered for as long as it needs to. When the Attiny is done doing whatever it's supposed to do, it can then set the output LOW, which turns the transistor off and shuts everything down (unless the reed switch is still closed).

Dampmaskin
  • 3,787
  • 1
  • 16
  • 29
  • 1
    It's better to use a high-side switch. Then you don't run into issues with different parts of the circuit having different ideas about what "ground" is. – Dave Tweed Dec 30 '16 at 15:23
  • 1
    Also, in order to shut off the transistor, you need to tristate (open-circuit) the control pin -- and also make sure it doesn't have any ESD protection diodes -- otherwise, leakage currents through the rest of the circuit will keep the transistor partially on. This is why most such circuits employ a minimum of *two* external transistors. – Dave Tweed Dec 30 '16 at 15:36
  • @Dampmaskin Do you mean something like this? http://imgur.com/a/qtmVS It's for a door sensor. I hope I put the transistor right. – Kevin Van Ryckegem Dec 30 '16 at 15:38
  • I was thinking about a normally open reed switch that powered the micro directly, not a normally closed one. Anyway, I only meant to convey the concept, as I don't have a full working solution to present to you. But other than that, yes, something like that, more or less. – Dampmaskin Dec 30 '16 at 15:44
  • @DaveTweed: Thanks for the comments. Perhaps using a P-channel MOSFET with a pull-up resistor on the gate would do the trick then? – Dampmaskin Dec 30 '16 at 15:46
  • Neither a single N- or P- single device will suffice as it will be at least partially activated by the protection diodes. You need a dual stage device, ie, a high side switch controlled by a high signal. Look at something like the Richtek USB power switch IC's - the RT9701 may be being discontinued but you can still find them, and there are doubtless replacements. – Chris Stratton Dec 30 '16 at 15:57
-1

You functionality should have nothing to do with how long the reed switch is activated. Identification of reed switch activity should put your system into a state where it does what it needs to do, complete the job, then turn off.

This is how sleep modes work.

Scott Seidman
  • 29,274
  • 4
  • 44
  • 109
  • You mean like making the system deep sleep when the reed switch is not activated? I thought about that, however I thought that since the switch would only be activated 3-4x a day, the battery would drain less if the esp is entirely shut off (since it still consumes about 15mA when in sleep mode) – Kevin Van Ryckegem Dec 30 '16 at 16:13
  • Then pick a platform with better sleep functionality. – Scott Seidman Dec 30 '16 at 16:14
  • Of course, the microcontroller controls power to the RF module, probably through a FET, or LDO with an enable. – Scott Seidman Dec 30 '16 at 16:16
  • The ESP8266 is basically like an Arduino -- high level software, lots of libraries that most programmers are mostly ignorant about, they can be _very tiny_, and they can be bought overseas for $3, including all shipping costs. A "better sleep" platform might require more money, be much much larger, or else require a LOT more technical expertise than you can reasonably expect from a user. Though I cannot speak for the OP, here. – jonk Dec 30 '16 at 16:32