Motion Sensor Tutorial for HC-SR501, HC-SR505, Mini AM312, HC-SR312

In this section we’ll walk through creating a PIR Motion Sensor using ESP32, ESP8266 or Raspberry Pi Pico W and then view the motion changes via Alexa or SmartThings.

Prerequisites :

  1. ESP32, ESP8266 or Raspberry Pi Pico W x 1.
  2. HC-SR501, HC-SR505, Mini AM312, HC-SR312 x 1.
  3. Jumper Wires.
PIR Working voltage Delay time Blocking time Trigger Distance
HC-SR312 2.7-12V 2 seconds 2 seconds Repeatable 3-5 meters
HC-SR505 4.5-20V 2 seconds 2 seconds Repeatable 3 meters
HC-SR501 4.5-20V Adjustable Adjustable Adjustable 3 meters to 7 meters

Quick introduction to PIR Motion Sensors

Passive infrared (PIR) motion sensors detect the presence of people or animals by measuring changes in infrared radiation. PIR sensors work by detecting the infrared radiation emitted by all objects that have a temperature above absolute zero. When a person or animal moves into the field of view of a PIR sensor, the sensor detects a change in the amount of infrared radiation and triggers an alarm or other output. PIR sensors are a versatile and cost-effective way to detect motion. They are easy to use and can be installed in a variety of locations.

The output of the PIR Motion Sensor is:

To get accurate measurements, wait for the PIR sensor to calibrate properly, this will normally take from 10 to 60 seconds after turning it on.

The HC-SR501 has adjustable configurations:

Sinric Pro esp8266 HC-SR501

Sensitivity Adjustment
Time-Delay Adjustment
Jumper Set

Example: The motion detector’s time delay is set to 3 seconds, but it cannot detect motion for about 6 seconds after detecting motion.

Sinric Pro esp8266 PIR Single Trigger Mode

Example: The time delay is 3 seconds. After motion is detected, the time delay period restarts. However, detection is still blocked for 3 seconds after the time delay expires. This 3-second delay allows the sensor to rest before starting to detect motion again..

Sinric Pro esp8266 PIR Multiple Trigger Mode


Sinric Pro esp8266 PIR wiring

ESP32 16
ESP8266 5 (D1)
Pico W GP5

Let’s verify that motion sensor is wired correctly and working.

Arduino IDE Serial Monitor will show the motion detections like this:

Step 1 : Create a new device in Sinric Pro

Sinric Pro create device alexa

Sinric Pro motion sensor device notifications

You can set the threshold here to receive a push notification via the Sinric Pro app when the motion is detected at Daytime or Nighttime. Use the Retrigger Time to set the delay between push notifications.

Sinric Pro copy device id

Step 2 : Connect to Sinric Pro

Step 2.1 Install Sinric Pro Library

Sinric Pro install SinricPro library

You can generate the code using Zero Code feature or write it by your self. If you do not have programming experice, we recommend to use Zero Code feature in the Portal to generate the code, download and flash.

2.2 Complete Code

Now you should be able to view the motions via Alexa, SmartThings

Sinric Pro motions via Alexa, SmartThings

via Portal

Sinric Pro Portal Temperature Sensor

Please note that Google Home not supported.


  1. Please refer to our Troubleshooting page for more details.

This document is open source. See a typo? Please create an issue