How to Use PIR Sensor With Arduino Nano

by STEAM-DIY in Circuits > Arduino

56 Views, 0 Favorites, 0 Comments

How to Use PIR Sensor With Arduino Nano

ccccccccccccccccccccc.png

Welcome back to my blog. We have described the ultrasonic sensor in the previous post. If you have not read it, 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.

Supplies

 let’s do the project step by step using the PIR sensor. The required components are as follows.

  1. Arduino Nano board — 
  2. PIR sensor —  
  3. LED bulb — 
  4. 1K resistor — 
  5. Jumper wires

Firstly, identify these components.


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

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.

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

  1. The complete program of this project
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
}


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.

Please subscribe my youtube channel . https://www.youtube.com/@steam-diy

Thanks