ESP8266 does not register PIR sensor but on an ESP32 it does

running into an issue getting a PIR sensor to run on my esp8266 d1, same sensor and code runs fine on an esp32 wroom. on the ESP8266 the PIR sensor is always off. i have also tried different pins (D2, D1, D5, D7) all with basically the same result. Same PIR sensor work on the ESp32 so its not a dead module.

esp8266 code:

substitutions:
  name: "esp-pumpkin-1"
#  display_name: 3D Print Filter
  device_description: ESP8266
  friendly_name: esp-pumpkin-1

esphome:

esp8266:
  board: d1_mini

# include WiFi, OTA, etc.
packages:
  device_base: !include common/device_base.yaml 

binary_sensor:
  - platform: gpio
    pin: D6
    name: "PIR Sensor"
    device_class: motion

esp32 code

substitutions:
  name: "esp32-testboard"
  friendly_name: ESP32-testboard  
  device_description: ESP32 30 pin

esphome:
  name: ${name}
  friendly_name: ${friendly_name}

esp32:
  board: esp32dev

# include WiFi, OTA, etc.
packages:
  device_base: !include common/device_base.yaml

binary_sensor:
  - platform: gpio
    pin: GPIO4
    name: "PIR Sensor"
    device_class: motion

This work ?

substitutions:
  device_name: "esp-pumpkin-1"  # Changed to 'device_name' for clarity
#  display_name: 3D Print Filter
  device_description: ESP8266
  friendly_name: "ESP Pumpkin 1"

esphome:
  name: !sub device_name  # Reference the substitution for the device name

esp8266:
  board: d1_mini

# Include WiFi, OTA, etc.
packages:
  device_base: !include common/device_base.yaml 

binary_sensor:
  - platform: gpio
    pin: D6
    name: "PIR Sensor"
    device_class: motion

i already have a name reference in the device base package

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  comment: ${device_description}

Instead of repeating “same sensor”, write what sensor. Powered from 5V or 3.3V pin or from separate power supply?

there is only one sensor being discussed so it’s the PIR sensor, and by same sensor I mean same piece of hardware. Power on 3.3V on both chips.

There are thousands if not millions of PIR sensors around.
But hardware is not important if you believe your problem is in your code…

i expect the exact PIR sensor is irrelevant since it works on one ESP chip and not the other, this to me points to some kind of configuration/code problem. but here is the exact sensor if it helps
TZT Mini IR Pyroelectric Infrared PIR Motion Human Sensor Automatic Detector Module AM312 Sensor DC 2.7 to 12V - AliExpress 502

Depends of point of view. To you it’s obvious the problem is in code because sensor is same. To me, since you have tried all the pins available and your code is just simply reading digital input, even before I have a look at the code I prefer to verify hardware. In this case there’s nothing popping up, but if your sensor was rated for 3.3V-x.xV voltage, it could have been something to verify. And I still expect you have hardware problem.

Have a look at the log, is your pin state changing there?

Have you got a multimeter to measure the voltage at the gpio whilst connected to the ESP in both triggered/non-triggered state? Would be interesting to know the levels you are getting. You are looking for something below about 0.8v for a low and above about 2.5v for a high. If you are getting something around 1.65v for either state you may get different readings between ESPs due to manufacturing differences in them.

Long shot, but given the code & sensor are the same, that only leaves the board.

I suspect you have a floating pin. Have you tried setting the pin as pull-up or pull-down in code? There’s a few examples of this in the Esphome docs, but I don’t have a link handy right now

Are you sure the sensor is indeed pulling the signal high/low? And it’s not an open collector output?

If so, try enabling the pull up or down.

Since your sensor has onboard 3,3V voltage regulator (HT33), you could power it from 5V pin to be sure logic voltage level is sufficient.

1 Like