1. Home
  2. ESP-8266
  3. Sensors
  4. PIR Motion Sensor HC-SR501

PIR Motion Sensor HC-SR501

There are cheap PIR motion sensors available for the ESP8266. The HC-SR501 is such a module. It can be configured through two potis at the back regarding sensitivity and delay after a motion detection, before the output is reset again.

The sensor has three pins: One for +5V, one for ground, and the middle pin is a 3.3v output, which can be connected to a digital input pin from the ESP. Getting notified about motion is very easy like this.


Example code to connect the sensor:

gpio.mode(inpin, gpio.INT)

startTime = 0

function motionStart()
print('Motion detected!')
gpio.trig(inpin, "down", motionStop)

function motionStop()
duration = tmr.time() - start
gpio.trig(inpin, "up", motionStart)

gpio.trig(inpin, "up", motionStart)

Updated on February 11, 2017

Was this article helpful?

Related Articles