PIR sensor Arduino nano Tutorial — Step by step Instruction

 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 presets. One preset changes the distance and the other preset changes the delay time. The 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.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the Arduino Nano board, LED bulb, and Resistor to the breadboard.

Step 3

Thirdly, connect these components to the 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

Now, copy and paste the following program to the Arduino IDE.

  • 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 into 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

Now, select the board and port. After, click the upload button.

Now, you can test this project. The full video guide is below. So, we hope to see you in the next project or tutorial. Have a good day.

PIR sensor Arduino nano Tutorial — Step by step Instruction

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *