Cannot get PIR to work with ESP32-CAM

Here are my connections

I cannot get the PIR to report motions back to Home Assistant/ESPHome.
Is my script/connections looking fine, or am I missing something (obviously I do :slight_smile: )
Her is my ESPHome script for the ESP32-CAM:

substitutions:
  devicename: cam_garasje
  friendly_name: CAM Garasje

esphome:
  name: ${devicename}
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pw

logger:
api:
  reboot_timeout: 0s
ota:

web_server:
  port: 80
  
esp32_camera:
  name: ${friendly_name}
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    sda: GPIO26
    scl: GPIO27
  data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
  vsync_pin: GPIO25
  href_pin: GPIO23
  resolution: 800x600
  pixel_clock_pin: GPIO22
  power_down_pin: GPIO32

time:
  - platform: homeassistant
    id: homeassistant_time
    timezone: Europe/Oslo

# esp32_ble_tracker:

sensor:
  - platform: wifi_signal
    name: ${friendly_name} WiFi signal
    update_interval: 30s
  - platform: uptime
    name: ${friendly_name} Uptime
binary_sensor:
  - platform: gpio
    pin: GPIO12
    name: ${friendly_name} PIR Sensor
    device_class: motion
    id: cam_garasje_pir
    on_state:
      - switch.turn_on: cam_garasje_lys
  - platform: template
    name: temp_motion
    lambda: 'return id(cam_garasje_pir).state;'
    filters:
      - delayed_off: 1min
    on_release:
      - switch.turn_off: cam_garasje_lys
switch:
  - platform: restart
    name: ${friendly_name} restart
    id: restart_switch
  - platform: gpio
    name: ${friendly_name} innebygd lys
    id: cam_garasje_lys
    pin: GPIO4

What PIR sensor are you using?

This is the one: Mini IR Pyroelectric Infrared PIR AM312 Sensor DC 2.7 to 12V

The pins are connected correctly to the PIR, it seems :slight_smile:

Needs a pullup resistor on the signal line if this schematic showing an open collector output is to be believed

3-Sensor-Interface-Schematic-1

Software pullup will be fine.

Also you will need to invert the signal. Movement = 0V, no movement = 3.3V

1 Like

Just adding this to the binary_sensor: part in the config?
mode: INPUT_PULLUP

Yep, and inverted: True (see sneaky edit in my post).

:+1:
I´ll give it a shot :slight_smile: Thank you, @tom_l

BTW, @tom_l : What is there a difference of using pin: GPIO12 and pin: 12? or are they the same?

Exactly the same. https://esphome.io/guides/configuration-types.html#pin

@tom_l; unfortunately, it’s still not working…

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO12
      mode: INPUT_PULLUP
      inverted: true
    name: ${friendly_name} PIR Sensor
    device_class: motion
    id: cam_garasje_pir

Do you have any way to measure the voltage on the PIR output pin?

Is it changing with movement?

Yes. Measuring beteeen output and ground?

Yes.

Measuring 3.309 —> 2.270 V
No change when movement…

What change would I expect?

I change the sensor… No success there either…

Below 0.8V with movement.

Try measuring the output when not connected to the ESP.

I disconnected the pin from the GPIO on the ESP, then there is 0.00v
… and I do have 3.3v on the PIR hot and ground connectors

And it does not change to 3.3V with movement?

In that case we were right to add the pullup resistor.

Try powering it from 5v. It has a 3V regulator on board.

I am powering the ESP from 5V

No, Sir. It does not!

Power the PIR from 5V.