Skip to content

Motion Sensor with ESP32

Easy 20 min $8

ESP32 Motion Sensor

PIR sensors are perfect for detecting motion. Turn on lights automatically, get notified when someone comes home, or build a simple alarm system.

PIR sensor to ESP32 wiring diagram

PartDescriptionPrice
ESP32 DevKitWiFi microcontroller$5
HC-SR501 PIRMotion sensor$2
Jumper wires3 pcs male-female$1
Total~$8
  1. Red (VCC) β†’ ESP32 5V or VIN pin

  2. Yellow (OUT/Signal) β†’ ESP32 GPIO5

  3. Black (GND) β†’ ESP32 GND

hallway-sensor.yaml
esphome:
name: hallway-sensor
friendly_name: Hallway Sensor
esp32:
board: esp32dev
logger:
api:
encryption:
key: "your-key"
ota:
platform: esphome
# PIR Motion Sensor
binary_sensor:
- platform: gpio
pin: GPIO5
name: "Hallway Motion"
device_class: motion
filters:
- delayed_off: 10s # Keep "on" for 10 sec after motion
# Optional: Status LED
light:
- platform: status_led
name: "Status LED"
pin: GPIO2
wifi:
ssid: "your-wifi"
password: "your-password"
  1. Click INSTALL β†’ Wirelessly (or USB first time)

  2. Go to Home Assistant β†’ Developer Tools β†’ States

  3. Search for binary_sensor.hallway_motion

  4. Walk past the sensor - status changes to on

HC-SR501 has two small screws you can adjust:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ β”‚
β”‚ [Time] [Sens] β”‚
β”‚ ↑ ↑ β”‚
β”‚ Duration Sensitivity β”‚
β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
ScrewCounter-clockwiseClockwise
TimeShorter β€œon” time (~3s)Longer β€œon” time (~5min)
SensitivityShorter range (~3m)Longer range (~7m)
automations.yaml
automation:
- alias: "Turn on hallway light on motion"
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "on"
action:
- service: light.turn_on
target:
entity_id: light.hallway
automations.yaml
automation:
- alias: "Turn on hallway light at night"
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "on"
condition:
- condition: sun
after: sunset
before: sunrise
action:
- service: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: 50
- delay: "00:02:00"
- service: light.turn_off
target:
entity_id: light.hallway
automations.yaml
automation:
- alias: "Smart hallway light"
mode: restart # Restart timer on new motion
trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "on"
action:
- service: light.turn_on
target:
entity_id: light.hallway
data:
brightness_pct: "{{ 30 if is_state('sun.sun', 'below_horizon') else 80 }}"
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.hallway_motion
to: "off"
for: "00:02:00"
- service: light.turn_off
target:
entity_id: light.hallway
ProjectDescription
Automatic lightTurn on lights in hallway on motion
Security alarmSend notification when away
Activity logTrack when rooms are used
Smart heatingHeat only used rooms

Kommentarer