I have an ESP8266 that does something, then goes to sleep.

I also have an AM312 PIR sensor which wakes up the ESP when activated. The PIR generates a 2 second long pulse when activated.

The ESP wakes up when RST pin goes low. I use the PIR output to drive a transistor to pull down the RST pin.

This works fine, the problem is, the ESP only wakes up once the 2 second pulse is over, and this slow wake-up delays the ESP's response. IOW: the ESP needs a short negative pulse to wake up, but only wakes up when the RST pin goes high again. While it is low, it will not wake.

breadboard layout

How can I convert the 2s pulse from the PIR into a short pulse, to trigger the transistor, and wake up the ESP faster?

This is a low power battery-driven application (hence the sleep), so I hope there is a simple low-tech solution to this problem which won't blow my power budget.

The LED shown lights up as status to show when the ESP is awake.

Transistor is a 2N2222a.

The 47k resistor between power rail and RST keeps the RST pin high during normal operation.

  • \$\begingroup\$ Kinda similar problem to electronics.stackexchange.com/questions/301477/… and electronics.stackexchange.com/questions/325574/… \$\endgroup\$ – codemonkey Oct 1 '17 at 1:26
  • 2
    \$\begingroup\$ Use a small capacitor (an order of magnitude near to \$1\:\mu\textrm{F}\$) to the base of your 2N2222 and PIR output. Ground the 2N2222 emitter. Tie a \$10\:\textrm{k}\Omega\$ resistor between the PIR +V voltage pin and the 2N2222 collector. Tie the 2N2222 collector to your RST pin. Ugly, not designed well, but probably will work. Add a diode, with cathode to 2N2222 base and anode to ground, to partly discharge the cap on the "other side" of the PIR pulse. And add a \$10\:\textrm{k}\Omega\$ resistor in parallel with the diode. That's more "designed." \$\endgroup\$ – jonk Oct 1 '17 at 5:32
  • \$\begingroup\$ Thanks @jonk - the addition of the cap & the 10k resistor didn't work, but after adding the diode and additional 10k resistor in it started working! The ESP responds quicker now. If you want to claim the points for answer, please post your comment as an answer. Thanks again!!! \$\endgroup\$ – codemonkey Oct 2 '17 at 2:22
  • \$\begingroup\$ Yeah, I didn't think the "ugly" version was all that likely -- there was no way for the charge to reset and a DC path was pretty important. I'll write it up, since the other answerer didn't bother with a schematic. \$\endgroup\$ – jonk Oct 2 '17 at 3:19

Here's the schematic I had mentioned in the comments:


simulate this circuit – Schematic created using CircuitLab

The main idea is that pulling up rapidly on \$C_1\$ also pulls up on the other side of \$C_1\$ (if \$C_1\$ has \$0\:\textrm{V}\$ across it, then hauling up on the left side means that the right side of \$C_1\$ will also be at the same voltage... for a moment.) This means the base of \$Q_1\$ is similarly pulled up and base current immediately activates \$Q_1\$ (while at the same time charging \$C_1\$ so that the right side of it moves towards ground.) \$R_1\$ also helps charge \$C_1\$ and together with the base current of \$Q_1\$ rapidly charges \$C_1\$ until there is no more base current for \$Q_1\$ to stay active. The exact duration here isn't terribly important, so long as it is "long enough" so that the collector of \$Q_1\$ is pulled down and causes the low-going RST pulse that's needed.

Once \$C_1\$ has developed a charge across it, and \$R_1\$ has helped to fully complete that job, \$Q_1\$ has to completely turn off and the RST line goes back high, again. It will stay there until there is another high-going edge at the left of \$C_1\$.

At some point later in time (\$\ge 2\:\textrm{s}\$), the left side of \$C_1\$ is hauled back down to ground. But \$C_1\$ is charged ([+] on the left, [-] on the right) and so hauling down on the left side causes the right side to have a rather negative voltage (below ground.) Here is where \$D_1\$ comes to the rescue, giving \$C_1\$ a way to (mostly) discharge; and quite rapidly. The rest of the charge can be removed by \$R_1\$ in order to completely reset and remove the voltage across \$C_1\$, readying it for another event.

The pulse width should be on the order of hundreds of microseconds -- long enough to get the job done, I think.

It might be wise to add a series resistor to \$C_1\$, as in:


simulate this circuit

Roughly \$1\:\textrm{k}\Omega\$ should be fine. A little less, if you like. This will limit the base current into \$Q_1\$ and decrease the charging rate, widening the pulse and helping make the behavior better managed than before.

There are other ways that are technically superior. Assuming that the output from the PIR may need to be "shaped," it's output might be fed to a Schmitt trigger circuit with that being followed by a one-shot timer (such as a 74LS121, for example.) Or, with a clean enough output from the PIR (probable here), just the 74LS121 would be enough. These can be set up to trigger on the rising or falling edge of their input (A vs B) and the timing of their output can be adjusted using an RC timing pair. You can choose the sense of the output, as well. So they are quite good for something like this.

But the above circuit might work okay for you. It's cheap and I suspect you already have the parts on hand. So that's nice, if it does work out.

  • \$\begingroup\$ Thanks @jonk, I think I learned more about capacitors today than I did in that 1 semester electronics course I took at uni long ago :) \$\endgroup\$ – codemonkey Oct 2 '17 at 10:27
  • \$\begingroup\$ Some more info on p57 of "Analog and Digital Circuits for Electronic Control System Applications", by Gerald Luecke. Link: books.google.co.nz/… \$\endgroup\$ – codemonkey Oct 8 '17 at 1:04
  • \$\begingroup\$ @codemonkey Yeah. The middle (#3 of 5) chart in Figure 40 is what I had in mind, at the base. The BE junction only operates on the positive spike. The negative spike is why D1 and R1 are desired. \$\endgroup\$ – jonk Oct 8 '17 at 1:08

You could of course wake up from Deep-sleep based on the RTC clock instead of reset. Set the clock to say 100 ms and test the movement detector output when you wake. This would give reasonably low power operation and you don't need any extra components at all.

You could also use Light-sleep and a GPIO pin change to wake the MCU, but this will have a higher base level of sleep current at about 900 uA.

enter image description here

See the sleep documentation and here for calculations.

  • \$\begingroup\$ Thanks, I considered this. This would have been plan B in case I can't fix it via interrupt to wake-up. The ESP spikes when booting, so consumption is high... I've also not been able to realize the suggested ~20uA deep sleep... Best I can get is 1.7mA. I'm begging to suspect it's something wrong with my cheap LoLin ESP board not supporting full deep sleep... \$\endgroup\$ – codemonkey Oct 2 '17 at 2:14

Add a 47 K resistor from the 2N2222 collector to Vcc. Replace the 100 ohm series resistor with a 0.1 uF series capacitor.

This will differentiate the leading edge of the long pulse into something that still is negative going, but now its trailing edge will occur in only about 5 milliseconds. Adjust the values of the existing 47 K resistor and the new 0.1 uF capacitor for other pulse widths.

Next time, consider posting an actual schematic, with a unique reference designator for each component. This prevents misunderstandings about which components are being discussed.

  • \$\begingroup\$ The idea of differentiating with a cap is the first thing that came to my mind, too. But I find your complaint about "posting an actual schematic" just a bit hypocritical, since you didn't post one either and you certainly could have done so in order to help improve your answer, greatly. \$\endgroup\$ – jonk Oct 1 '17 at 5:22
  • \$\begingroup\$ Last time I tried, the site would not let me post an image. I've never used the on-site schematic editor, and was in a scramble and didn't have time to learn it. Separate from that, your "hypocritical" comment is false equivalence. This is an electrical engineering forum. You are asking for a favor. I don't think it is unreasonable to expect a schematic of a circuit when the question you are asking for free help with is about components in a circuit. Note that no one else has volunteered the time to convert your image to a schematic for you, either. \$\endgroup\$ – AnalogKid Oct 1 '17 at 10:38
  • \$\begingroup\$ Separate from that, I'm curious - if you know about and considered differentiating the leading edge of your long pulse to create a short pulse, why did you not try that? \$\endgroup\$ – AnalogKid Oct 1 '17 at 10:44
  • \$\begingroup\$ You should be able to use the schematic editor. It's right there as part of your editing tools. And so far as I'm aware, there are no rep pts required to use it. So you do not need to post an image. That said, to post an image only requires 10 rep pts and you are able to do that, as well. \$\endgroup\$ – jonk Oct 1 '17 at 13:33
  • \$\begingroup\$ Also, while I agree that the OP should do so, I also think that anyone bothering to answer AND to chastise the OP for failure to use a schematic, is in a poor position when they also fail to add a schematic in their answer. I'm not complaining. You have good thoughts and I actually wanted to +1 your answer (and will do so, I suspect, if you bother to add one.) But couldn't, because of my opinion at this point. If you don't do the schematic, then I probably will add an answer that does (though I still may not.) \$\endgroup\$ – jonk Oct 1 '17 at 13:37

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.