2.31 PIR Module¶
In this lesson, you will learn how to use PIR Module. The PIR sensor detects infrared heat radiation or the presence of organisms that emit infrared heat radiation. This module is widely used in daily life for our intruder alarm and visiting prompt.
In this example, we can connect the pins of Sound Sensor Module to the pins of Mega 2560 Board directly, and we use digital pin 2 to read the signal of PIR Module. Connect the VCC of PIR Module to 5V, GND to GND, and OUT to digital pin NOTE: you can remove the PIR cover to see the pin mark.
You can open the file
2.31_pirModule.inounder the path of
Or copy this code into Arduino IDE.
After the codes are uploaded to the Mega2560 board, you can open the serial monitor to see the reading value of the pin. When PIR Module detects activity nearby, the serial monitor will display 「1」; otherwise, it will display 「0」. Check 1.4 Digital Read detail code explanation.
There are two potentiometers on the PIR module: one is to adjust sensitivity and the other is to adjust the detection distance. In order to make the PIR module work better, you need to try to adjust these two potentiometers.