How to connect HC-SR504 Motion Sensor With Arduino


In this tutorial, you will learn how to integrate the HC-SR504 PIR Motion sensor with Arduino so that you can detect motion.


Category:  Arduino

Difficulty:  Beginner

Submitted by: Gideon

Date: 31st January, 2018


The HC SR501 PIR motion sensor that is also call Passive Infrared sensor or IR motion sensor.HC SR501 PIR motion sensor uses IR differences in a room to detect motion. Every thing emits a little heat and this heat generates infrared rays. When a humanbeing approaches a room, the heat in the room increases or decreases. That change is a signal depicting motion. It is usually used in home automation and in security systems.

HC SR501 PIR motion sensor can be used without a microcontroler. You can connect a relay, a light source,  sound or even an actuator which will respond whenever the sensor picks a signal. The two potentiometers do that job. Look at this for more details

The sensor can be used with other sensor like the  HCSR04 Ultrasonic sensor in robotics and other areas of smart devices.



The PIR motion has a range of up to 7m in a circular area of 120 degress. This range makes it easy to detect intrusion than distance sensors or obstacle sensors. The sensor receives from 3.3v to 20 volts. To change the sensitivity and clock settings, there are two potentiometers that are tune to the requirement of the particular project. Look at this site for more details

In this tutorial we will be connecting the HC SR501 PIR motion sensor to the arduino nano board. The sensor can be used on any of the arduino boards or raspberry pi. Below are the components needed for this tutorial.

This is the fritzing diagram of the circuit

fritzing setup

This is the code for the setup

int motionsensor=5;
int led=13;

void setup(){

void loop(){

int motion=digitalRead(motionsensor);
Serial.print("motion state=");

if (motion==1){

The picture of the setup

Set of the circuit


We hope you enjoyed the tutorial and this little lesson will purport you into great levels. Enjoy yourself in electronics. For more tutorials and questions, please leave your comments in the comment area. See other components on the site Inspiring ingenuity.


This is the tutorials website for Invent Electronics. We are a top online retailer of electronics components, microcontrollers and sensors in Ghana. Besides providing customers with good quality electronic components we want to help them build great projects with the components they buy for us so we’ve put together a ton electronics resources, projects and tutorials on this site just for you!

Looking for electronic components to buy in Ghana?

Get all your sensors, electronic components, Arduinos, Raspberry Pi and other parts for your project at great prices from our online store.

Join Our Community

We’re more than just an electronics store. We are also a community of makers, engineers, enthusiasts and more. Join our community today, meet and learn from other people like you.