Under Home automation, Motion sensing is an important part of taking a decision to whether start or stop any service

HC-SR501 is a motion sensor having two modes which can be adjusted by jumper on sensor


  • Single trigger
  • Repeat trigger

Complete data sheet can be found here

When any motion is detected it’s OUT pin is turns high and stays high for a time duration

This time duration can be adjusted by a knob on the sensor.

Sensitivity of the sensor can be varied by 3m to 7m




#define PIR_pin 2 //PIR input pin
#define output 13 //output shown in pin
bool state;
void setup() {
 // put your setup code here, to run once:
 pinMode(PIR_pin, INPUT); // defines PIR pin as an input
 pinMode(output, OUTPUT); // // defines output pin as an output

void loop() {
 state = digitalRead(PIR_pin); // reads the pin
 if (state == 1) // decision to be taken
 digitalWrite(output, HIGH);
 digitalWrite(output, LOW);
 // put your main code here, to run repeatedly:



This Helped
This didn't help
Close Menu


STEMpedia Starter Package is now on Indiegogo!
Get 41% OFF with Super Early Bird discounts!