PIR sensor Arduino nano Tutorial – Step by step

Hello guys, Welcome back to my blog. We have described the ultrasonic sensor in the previous post. If you have not read it, click on the link and read it now. Today we are going to talk about the motion sensor (PIR) in the post. It is really easy to use and this sensor is very cheap in the market.
What is the motion sensor?



This is called a PIR sensor. It is used to detect movements. The PIR sensor emits a digital signal when a person or something is in motion. It operates from 7 meters to 160 degrees. The PIR sensor is covered with a plastic hemispherical cover. Due to the plastic cover, a motion of up to 160 degrees is applied to the PIR sensor. You can remove the plastic cover and look at the sensor. This sensor has two preset. One preset changes the distance and the other preset changes the delay time. Delay time is how long the signal should be given by the sensor. The PIR sensor has three pins. The middle pin is used to receive the signal. The other pins are used to power the sensor. The PIR sensor emits digital signals. Gives a digital value of 1 when a movement occurs and 0 when it does not. Okay, let’s do the project step by step using the PIR sensor. The required components are as follows.

Components
- Arduino Nano board — Amazon / Our Store
- PIR sensor — Amazon / Our Store
- LED bulb — Banggood / AliExpress / Amazon
- 1K resistor — Banggood / AliExpress / Amazon
- Jumper wires — Amazon / Our Store
Step 1
So, Identify the components.
Arduino Nano board

You can use any other Arduino board for this project.
PIR(Motion Sensor)

It is described above.
LED bulb

This component is used to view the output.
1k resistor

It is used to control the current.
Jumper wires

The project uses two male-to-male jumper wires and three male-to-female jumper wires.
Step 2
Connect the LED bulb and Arduino Nano board to your breadboard.

Step 3
Connect the PIR sensor to your Arduino Nano board.


Connect the anode pin of the LED bulb to the D2 pin using a 1k resistor and the cathode pin to the GND pin. On the Arduino board, connect the D2 pin to the center pin on the sensor. Connect the other pins to the GND and VIN pins.
Step 4
Let’s look at the code below.
The complete program of this project – Download
void setup() {
pinMode(2, INPUT);//define arduino pin
pinMode(3, OUTPUT);//define arduino pin
Serial.begin(9600);//enable serial monitor
}
void loop() {
bool value = digitalRead(2);//get value and save it boolean veriable
if (value == 1) { //check condition
Serial.println("ON");//print serial monitor ON
digitalWrite(3,HIGH);//LED on
} else {
Serial.println("OFF");//print serial monitor OFF
digitalWrite(3,LOW);//LED off
}
}
This code is prepared as a D2 pin input pin and D3 pin output pin.Also, the serial monitor is enabled
void setup() {
pinMode(2, INPUT);
pinMode(3, OUTPUT);
Serial.begin(9600);
}
A Boolean variable is created and ‘value’ is used as its name. The sensor reads the digital value and puts it to that variable.
bool value = digitalRead(2);
This code checks if the digital value is equal to 1 or 0. If the digital reading is 1, the LED bulb turns ON. Otherwise, the LED bulb turns OFF. You can see this process on the serial monitor.
if (value == 1) { //check condition
Serial.println(“ON”);//print serial monitor ON
digitalWrite(3,HIGH);//LED on
} else {
Serial.println(“OFF”);//print serial monitor OFF
digitalWrite(3,LOW);//LED off
}
Step 5
Select board and port.



Step 6
Upload this code and enjoy it.

What do you think about this project? please comment below. Below is the full video of this project. Watch it. We will meet in the next post. Have a good day. Bye-bye.
PIR sensor Arduino nano Tutorial — Step by step Instruction