Tags: ,

It is possible to activate a system, such as an alarm, by detecting the presence of a person using a PIR motion sensor. In home automation, it is common practice to operate devices when a person enters a room. This is made possible by motion sensors such as the Passive Infared Sensor (PIR). In this tutorial we will see how to control the PIR sensor using an Arduino microcontroller.


  • Computer
  • Arduino UNO
  • USB cable A Male to B Male
  • PIR motion sensor

Principle of operation

Any object with a temperature above absolute zero emits infrared radiation. This can be seen in thermal camera images. The PIR sensor is equipped with two infrared-sensitive cells that will detect the infrared rays reflected or emitted by an object.
When there is no movement, the level of infrared received is the same for both cells. When an object passes by, the emission of these rays will be modified on one cell and then on the other, which will allow the movement to be detected.
The white cover, which usually covers and protects the sensor, is a multifaceted Fresnel lens that allows the infrared radiation to be concentrated and sometimes filtered on the cells.


The PIR module can be powered directly by the microcontroller and, as it returns a status, the sensor output is connected to a digital input.


The PIR sensor returns a high state (HIGH) when it detects movement and a low state (LOW) if there is nothing. It will therefore be managed as a digital input using Arduino’s digitalRead() function.

const int pirPin  = 2;

bool pirStatus  = false;

void setup() {
  //Init Serial USB
  Serial.println(F("Initialize System"));
  //Init digital input
  pinMode(pirPin, INPUT);

void loop() {

void readPIR( ) { /* function readPIR */
  ////Test routine for PIR
  pirStatus = digitalRead(pirPin);
  Serial.print(F("Sensor status")); Serial.println(pirStatus);
  if (pirStatus) {
    Serial.print(F("----> Detection"));


  • Switching on a light when a movement is detected
  • Activation of an alarm upon intrusion of a person


Find other examples and tutorials in our Automatic code generator
Code Architect

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?