Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)
User avatar
By dxguidan
#8048 Hi all,

I have an ESP-01 (GPIO0 and GPIO2 only) running on the RTOS 0.94 sdk.

I'm trying to get a read from the PIR sensor output into one of the available GPIOs, and while it does work I'm having trouble getting the PIR's output with a pull-up to stabilize.

The ESP is powered with a 3.3v regulator, which works fine.
The PIR sensor ( needs 5v and outputs an open drain 3.3v signal so it needs a pull-up resistor, it works fine with an Arduino and a 10k pull-up resistor.

Connecting the PIR sensor's 3.3v output signal to one of ESP gpios does work, but the signal is not getting a strong enough pull-up no matter what I do, and after triggering it I am getting signal oscillations (GPIOs input reads 1 when triggered correctly but then oscillates continuously between 1 and 0 non-stop which does not happen with the arduino).

The GPIOs are configured as input, and anything above 1k pull-up allows for the dreaded oscillations to happen (pull-up is not strong enough), anything equal or below and the pull-up is too strong so I'm only getting an input of 1 (internal pull-up or pull-down GPIO configuration does not seem to matter as it's not strong enough). The pins do work as connecting the GPIOs to 3.3v VCC or GND reads correctly as 1 or 0 respectively.

My configuration is this:

* The ESP is powered by the 5v->3.3v regulator. (all GNDs are connected together)
* The PIR is directly connected to 5v/GND, the output pin (3.3v signal, open drain) is connected to a 1k+ resistor that's connected to the 3.3v regulator VCC (for a strong pull-up) - following that, it is also connected to GPIO0 (or 2, does not matter - same result).

This works effortlessly with an Arduino, but the signal refuses to stabilize on the ESP. Once the PIR is triggered I correctly read the signal as 1, but couple of seconds later it just keeps on changing between 0 and 1 without end as if the pull-up is not strong enough. I've tried so many configuration I've just came to the conclusion that I'm missing something.

I do realize that the Arduino has 5v input and the ESP has 3.3v input so that comes into play with how strong the pull-up needs to be to get the same result (I've calculated that 10k pull-up with VCC being 5v is around 6.6k with VCC being 3.3v, but anything above 1k and it's as if there's no pull-up at all).

I thought it might be something with my code not setting the GPIO input mode correctly, but it's almost directly copied from the SDK and works fine with any strong signal / other devices that are not open drain. The code for setting a GPIO pin to INPUT (normally / internal pullup/pulldown) also works fine, I've tested this.

Any ideas?
User avatar
By elac
#8049 Have you tried pull up or down resistor(around 10k) on GPIO2 while the PIR is connected to GPIO1? It can help reduce cross-talk between the GPIO pins caused by floating inputs.
User avatar
By quantalume
#8050 It sounds like you are doing everything right. 5V may be a marginal supply voltage for the sensor, given that it calls for 12V in the data sheet. Is it possible that it's getting a little more voltage in your Arduino setup? You might try powering it from a 9V battery. I'd also try putting some caps between the supply line and ground, close to the sensor, maybe 47 uF in parallel with 0.1 uF. Triggering the output might be inducing just enough voltage drop in the supply lines to cause it to stop working temporarily, which reduces the voltage drop and allows it to come back on, etc.
User avatar
By dxguidan
#8547 Update [SOLVED]:

I've tried mimicking exactly the Arduino configuration that does work, at some point I was positive that the problem is caused by using the 3.3V regulator output as a pull-up for the PIR's output signal as opposed to using the Arduino's 5V as a pull-up in the Arduino configuration. There was not much I could do about it since the ESP is a 3.3v device, but I thought mixing signals (running the PIR from 5V and pulling up to 3.3V) might be the problem. It made no sense pulling up to 5V only to use an external IC / voltage divider to convert the final output back to 3.3V so I quickly dropped the idea of going around it.

Also swapped my trusty raw (capless DIP) 5V->3.3V regulator with one that has caps built in and is smaller: same result. Tried running the entire thing from a 9V battery - same result. I still got signal fluctuations every 30 seconds or so.

I then noticed something odd: whenever the ESP was doing some processing as opposed to idling (for example: running SSL encryption code that's pretty processor intensive) - the PIRs output would go crazy, alternating between 0 and 1 really quickly.
That made me think that the problem may be that particular PIR sensor, whether it was faulty or too sensitive or what-not. And though it DID WORK with the Arduino, there was nothing much going on on the Arduino as it was simply a testbed for the sensors.

I said what the heck, swapped out the PIR sensor with a new one, changed the pull-up back to 10k.. and what do you know - IT WORKS!

Apparently, sometimes it's just a faulty sensor to begin with.. still have to see if it lasts, but everything works for now.

BTW: those PIRs can be run directly from 3.3V if you bypass the on-board regulator and solder directly. I'm aiming for a fully 3.3V configuration for the final project, so it still remains to be seen whether it's stable enough. For now everything works fine from 5V.

Thanks everyone for all your help!