HC-SR501: Arduino compatible IR motion sensor


If you want to equip your Arduino DIY projects with the ability to detect proximity or motion, and based on that do some kind of action, such as recording an event, turn on a light, set off an alarm, activate a DC motor, etc, then you should know the HC-SR501 sensor.

This sensor uses IR, like other similar types of sensors, and in this guide I will try to explain everything you need to know to start using it from scratch. From its features, to how to integrate HC-SR501 with your Arduino UNO board, to how to integrate it with . Everything in a more practical way to make it as simple as possible.

What is the HC-SR501 and principle of operation

fresnel lens

The HC-SR501 is a type of motion sensor, a PIR sensor consisting of two departed elements. On the one hand it has a device emitting the differential signal between it and other sensors that will be the one that really activates the alarm signal.

This is achieved by means of an integrated BISS0001 circuit, which contains additional operational amplifiers and electronic interfaces. In addition, the module allows two settings of its functions, one is for the sensitivity of the PIR sensing distance with potentiometers. The other function is the automatic light detection capability, although this is not enabled at the factory.

The latter function is often used for ‘strong’ some systems to turn on the light of a system when motion is detected, but the ambient lighting is not high, i.e. at night.

In the case of the HC-SR501, there is a movement detection range of 3 up to 7 meters distance, and PIR openings of up to 90 and 110º. That’s a good range, allowing it to be installed wherever you need it, such as a wall, ceiling, floor, etc.

As you can see, the PIR sensor is covered by a kind of white dome, that’s what is known as a Fresnel lens. It’s named after French inventor and physicist Augustin-Jean Fresnel. Thanks to him, it is possible to build large-aperture, short-focal-length lenses without the weight and volume of the material that should be used with a conventional lens.

And that’s thanks to the design of this lens invented in 1822, and which follows a surface pattern that you can see in the image, similar to a golf ball. And thanks to this design, many devices have been implemented, including the HC-SR501.

Features of the HC-SR501

HC-SR501 controls

The , small and with one of the most advanced technology of all current motion sensors. With its two potentiometers and the integrated jumper, its parameters can be easily modified, adapting them to all sensitivity and distance needs, and even activation and response time.

The technical specifications of this HC-SR501 are

  • It consists of the PIR LH1778 and the BISS0001 controller
  • Supply voltage: 5 to 12v
  • Power consumption: <1 mA
  • Distance range: 3 to 7 m adjustable
  • Angle of detection: 110°.
  • Settings: by means of 2 potentiometers for the detection range and active alarm time. The jumper adds capacity to configure the alarm output in single-trip or repetitive or retarding trip mode. The alarm output can be configured for times between 3 seconds and 5 min.
    • 1 (in the picture): turn right as in the picture to set from 3 seconds to 5 minutes.
    • 2 (in picture): turn left as in picture to set from 3 meters to 7 meters maximum.
    • 3 (in picture): Jumper to set the shot. When the jumper is inserted into the two outermost pins seen in this picture, then it will be set as 1 shot. And if it is on the two insidemost pins, then it will be set to repeat mode. That is, there are 3 pins, if it is on the outside and the middle one is the mono function, and if it is on the center pin and the innermost one is the repetitive one.
  • Initialization time: after starting to feed the HC-SR501 module, it must take at least 1 min until it is operational.
  • Operating temperature: -15ºC and +70ºC
  • More information: see pinout and datasheet

Please note that these passive sensors are ideal for your projects, they will only start up if they detect a proximity, in the meantime they will remain passive. And you can achieve this very easily, as the HC-SR501 has a simple pinout:

  • Vcc for power supply.
  • GND for grounding.
  • Output for sensor output.

As for the two trimers I mentioned before, they can be adjusted as I said. What I haven’t explained are the jumper firing modes:

  • H (re-activation): the output remains high when the sensor is triggered, i.e. it keeps the voltage high when it detects movement or proximity, and does so repeatedly. It will go down when the sensor is inactive.
  • L (normal): the output increases from low to high when activated. Continuous motion results in a repeated high-low pulse.


The PIR is based on low level infrared radiation. The hotter an object is, the more IR it emits. This is the basis of this type of sensor, as people, objects and animals give off heat and with it you can measure whether they are close or not.

With this simple system you can implement from doors that open automatically, escalators that start when they detect proximity, alarms that activate when they detect presence, lights that illuminate when they detect your presence, etc. The number of applications is very high…

This combined with Arduino and many other devices such as the connectivity module, can send internet alerts, and extend the capabilities even further, making presence detection generate activity remotely. I’m referring to the ESP8266-01 module or similar…

Another recommendation is to use a relay to activate higher voltage elements, such as a door motor, a light bulb, etc.

Integration of the HC-SR501 with Arduino

hc-sr501 connection with Arduino

To integrate it with your Arduino IDE board, you can see our programming course for more information. Nevertheless, I show you a simple sketch code with which you can start to see how it is used in a basic way, and little by little you can modify the initial code and add elements to your project to make it work in a complete way.

The sample source code would be like this:

// Basic example with the HC-SR501

sensorpir byte 8; //Pin of the sensor output which is as output.
byte led=13; // You can connect a LED on 13 to see the visual effect when activated by presence detection

void setup()
 pinMode(sensorpir, INPUT); //Declared I/O pins
 pinMode(led, OUTPUT);
 Serial.begin(9600); //Set the speed of the serial monitor

void loop)
 if(digitalRead(sensorpir)== HIGH)
   Serial.println(&quot;Motion detected&quot;);
   digitalWrite(led , LOW);

Leave a Comment