PiR Keeps turning OFF and ON

Hello, I am running into an issue with my PiR sensor constantly going into an ON and OFF state.


D1 mini
PiR motion sensor (bought a while ago and do not have the specs/details found spec info online. rated for 5-9v.)


PiR constantly switches from ON and OFF.

[16:07:15][D][binary_sensor:036]: ‘PIR Sensor’: Sending state ON
[16:07:20][D][binary_sensor:036]: ‘PIR Sensor’: Sending state OFF
[16:07:43][D][binary_sensor:036]: ‘PIR Sensor’: Sending state ON
[16:07:45][D][binary_sensor:036]: ‘PIR Sensor’: Sending state OFF

  name: "temp-master-bedroom"
  platform: ESP8266
  board: d1_mini

  - platform: aht10
      name: "Master Bedroom Temperature"
      name: "Master Bedroom Humidity"
    update_interval: 60s

  sda: D2
  scl: D1
  scan: True
  id: bus_a

  - platform: gpio
      number: D7
      inverted: True (tried enabling and disabling this to no avail)
      mode: INPUT_PULLUP (tried adding and removing to no avail)
    name: "PIR Sensor"
    device_class: motion

The AHT20 is working as intended, but the PiR just keeps logging ON and OFF state.

Edit: Forgot to mention that I’m sharing the ground between the AHT20 and the PiR.

Does the PIR look like the one you pictured, or more like this:

If it’s like my picture then it was probably designed to run on 5V and some of them do this when running on 3.3V.

it’s a tiny one like the one in the pic I posted.

Hmm - was worth a try… :slight_smile:

I have a similar one to the one you pictured and it just worked, no pull-up or pull-down:

  - platform: gpio
    pin: D6
    name: "Office PIR"  
    device_class: motion
1 Like

I noticed you’re using D6 whereas I’m using D7. Does that matter? (I’m fairly new to this so bear with me.)

No - D6 or D7 should be fine.

Thanks for the link zoogara. I’ve already looked at that one and many more trying to fix this constant ON/OFF state. I’ve also tried some of the solutions others have tried in this community and still having the same issue.

Not sure what else to try to get this resolved…

One last suggestion - try a different power supply. It’s a long shot but worth a try.

Great suggestion. I’ve already tried 3 different wallwarts, 2 adjustable dc psu’s and 2 power banks. Still same issue.

1 Like

OK, everything I’ve tried is not working and I’m all out of ideas…Time get some sleep and start fresh tomorrow.

If anyone else has any ideas, I’d greatly appreciate it.


Hi –

I have had the constant on/off issue with the bigger PIRS before and it is usually one of these things:

  1. Bad connection between the PIR and ESP (this was most common for me as I used headers and made cables)
  2. Bad PIR
  3. Sensitivity of the PIR is set too high ( may not be a factor for your device )

I did not see in the preceding post that the sensor was swapped out. Since you are sure the power is good I’d try swapping out the sensor or wiring.

My setups look alot like yours but I used the gpio number on my d1_mini:

  - platform: gpio
    pin: 2
    name: "Motion 1 PIR"
    device_class: motion
1 Like

What happens when you connect a multimeter and test the PIR stand-alone (disconnected from esp)?

1 Like

Sleep does a body (and mind) good!

A quick update:

Continuing from last night’s investigation, I was able to find another PIR of the same type in my storage. After hooking up the new one, the PIR works as intended. Seems the initial one I tried was a dud. (Note to self, test all items when buying bulk online)…

Thanks @marc-graham for the direction about swapping out. If not for your comment, I wouldn’t have gotten off my lazy butt to try and find one. :sweat_smile:

@aceindy I’ll keep that in mind for the future. :facepunch:

Thank you all for your input and assistance in this matter. Truly appreciate it!


It’s not uncommon for PIR sensors to be defective right out of the bag, I’ve had it happen on multiple occasions. The symptom your having, its the PIR isn’t defective then i’d focus your attention on making sure your connections are solid and you might turn the pullup back On. You normally don’t need to use the internal pullup but when it bounces from ON/OFF like that, that’s a common indicator of a gpio that’s floating. Turning the pullup on likely wont fix it but turning it on while you troubleshoot will help you rule out a floating gpio. Those usually come in 3 or more packs so if you have a spare i’d try a spare to rule out a defective PIR. The GPIO your using is fine to use but just for the sake of process of elimination, i’d change gpio’s too. Can you post the model of the PIR or a picture of it?

Agreed. I’ve just had 2 ESP32s and 2 distance sensors fail from the bulk I bought the past week… Solder joints were/are fine.

Unfortunately I do not have anymore PIRs remaining. I have some on order and will keep your suggestion in mind.

Regarding a pic of the PIR, I posted it in the setup pic in my initial post. That’s the exact one I’m using.

Aliexpress I presume?

Where else can you get super cheap dev IoT devices toys? :joy:

I don’t think they’re horribly expensive on Amazon and after I quit going the cheapest possible route, I noticed that the number of DOA or defective components I received dropped significantly. When sellers have to conduct business under Amazons return policies they’re less likely to sell crap products because people will send that crap back. Who wants to pay the return shipping to China and wait another 30 days for 10$ worth of parts? no one does and they take the loss and buy it again. Thats why almost every single time you see faulty components or DOA components mentioned online and ask, they’re almost always from aliexpress. To each his own but, i’m happy paying a little extra to get my stuff the next day and having the peace of mind that if i get garbage, which rarely happens then I can send it back for free and get new stuff.