1

I'm trying, what I thought would be simple, to wake a sleeping ESP8266 via motion detected by a PIR.

There are a lot of schematics around and they all seem to go about it more or less the same way, and the simplest form seems to be this:

wake esp from pir

Where RST is the RST pin of the ESP8266 and Trigger is the PIR's trigger line.

The problem I'm finding is that this is not working.

The PIR is working fine, and throws out almost 3v for 2 seconds when triggered and 0 when no motion is detected.

My ESP is being woken up when the PIR trigger is OVER, not when it STARTS. So if the PIR senses motion for a long time, the ESP will only wake up when the motion STOPS.

The PIR is one of these.

The ESP is currently a NodeMCU on breadboard, but the final product will be a Wemos D1 Mini.

What am I doing wrong here?

  • 1
    you measured only 1/2 of your circuit .... The PIR is working fine, and throws out almost 3v for 2 seconds when triggered ... how about measuring the RST line – jsotola Jul 21 '18 at 2:35
  • The RST line has 3.3v as expected. When the PIR fires, the voltage on RST drops to zero, which I expect to wake the ESP. However, the ESP only wakes when the PIR stops firing and the voltage to RST goes back up to 3.3v. I don't get it. – Andreas Huttenrauch Jul 21 '18 at 18:32
  • it is simple, the esp8266 stays in reset mode as long as RST is active (low) .... it leaves reset mode and starts executing its program when RST becomes inactive (rising edge on RST) – jsotola Jul 21 '18 at 20:26
1

What you need is an edge detector. As long as the PIR output is hight, the ESP stays in reset mode.

You can use a capacitor to do the trick, as shown in the following schematic.
You'll probably want to get rid of the pull-down resistor R1 since you're using an open-collector output.

Edge detector

If the voltage at the collector is the blue curve, then the resulting voltage at the output of the circuit will be similar to the yellow curve. (Note that this simulation used an ideal square wave as input, produced by a push-pull output from a CMOS chip, for example. An open-collector output will have slightly different characteristics, the high peak won't be as high.)

Simulation

At the instant when the collector voltage drops to (almost) zero, the voltage across C1 will be 0V, so the output is close to 0V as well. Then the capacitor immediately starts to charge through R2, so the voltage on the reset pin rises exponentially.

To prevent a high voltage peak when the PIR turns off, a diode is used to discharge the capacitor more quickly. If the resistor at the collector is large enough, this might not be an issue at all.

The same principle is used in the Arduino UNO, for example, to reset the ATmega when DTR goes low.

  • Thanks. That is very useful. Based on your schematic and a few others I found, I have re-worked my wiring to this: groovy.globi.ca/img/… This is working very well. The ESP is woken quickly, and by setting D3 LOW, is prevented from re-booting while running. The problem I'm now facing is that the PIR output pin is showing a negative voltage. I want to connected it as an INPUT to the ESP so it can check the status, but the ESP goes crazy when connecting it. Any ideas? – Andreas Huttenrauch Jul 22 '18 at 16:27
  • If D3 goes from low to high when trigger is low, trigger will get pulled negative. (Because there was a negative charge on C1). The output impedance of most PIRs is greater than 1kΩ, so the voltage will go negative. You need a resistor on your base. If you do the edge detection after the transistor, you shouldn't have to worry about this. You can still use the AND configuration you have right now. – tttapa Jul 22 '18 at 17:10
  • Hmm. I put another NPN between V++ and the edge detect with trigger to the base, but I'm still getting a negative voltage on the trigger. Where exactly do you think the resistor should go, and what value? Is the 1M resistor maybe too high in this circuit? – Andreas Huttenrauch Jul 22 '18 at 19:50
  • Use your initial circuit, the one you used in your question. Then add the circuit of my answer (without R1). Connect your RST output to my DTR input. Then add the second transistor between the emiter of the first transistor and ground (collector 2 to emitter 1, emitter 2 to ground, base 2 through a resistor to the GPIO pin of the ESP). – tttapa Jul 22 '18 at 21:14
  • I tried adding your edge detector to my original circuit at RST, and it looks like this: groovy.globi.ca/img/… However, when I plug D3 into the ESP, it never boots - just throws gibberish to the serial console and dies. Did I mis-interpret your instructions? – Andreas Huttenrauch Jul 23 '18 at 16:12

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.