PIR motion sensor (HC-SR501)
Senses the warmth of a person moving, up to a few metres away: alarms and lights that turn on as you pass.
The test program
Test this part on its own before you build the rest: if it works alone, the rest is built on something you know works.
10 LED red, off
20 IF SENSOR("motion")=1 THEN LED red, on
30 WAIT 100
40 GOTO 10What you should see: Wave a hand in front of the sensor: the red light comes on and stays on for a few seconds.
▶ Try it in the IDEWhat to buy
- PIR motion sensor (HC-SR501)
How to wire it to an ESP32-S3
- OUT → ESP32-S3: GPIO7
- VCC → ESP32-S3: 5V
- GND → ESP32-S3: GNDCommon ground: this link is mandatory.
If it does not work
- The program runs but nothing happens
- Just after power-up a PIR sensor needs about a minute to settle, and at 3.3 V it often does not work. Power it from 5 V, wait a minute without moving in front of it, then wave your hand.
What you can adjust
- The two orange screws on the sensor: one sets the distance, the other how long it stays on.
Which boards it works on
- ESP32-S3 Freenove: yes
- Nordic nRF54LM20 DK: yes
- Arduino UNO R4 WiFi: yes