Arduino PIR Sensor : Arduino 13th Lesson of Arduino Tutorial

In the previous lesson we have learn about how to communicate with Serial Monitor. Today we are going to work with most basic sensor in the electronics. It’s PIR sensor. Let’s get started.

PIR sensor is a sensor that gives you motion senses. It’s also known as motion sensor. If some human or animal go near to this sensor, it begins to sensing. So, this is very useful when making security system. You can make your own security system using this. PIR sensor has VCC (+) and GND (-) pins as others and it has Signal pin for getting output. You have to give 5v of Arduino to VCC of PIR sensor and also, you have to connect Arduino GND with PIR sensor’s GND to powerup this sensor. No use of only powering the sensor. You have to get inputs. To do that, you have to connect Signal pin with Arduino’s 2nd pin and A0 pin. 2nd pin is for getting digital inputs and A0 is for getting analog inputs. Then you have to connect LED to show output. You can use Serial Monitor instead of this, but I used both for easiness. If you don’t know how this PIR sensor’s pinout, click the button below. Also, you have to make the circuit like below to work with PIR sensor.


You have to make the code like above to work with PIR sensor. In this code, first I put two integers named “val” and “anval”. Val is for storing digital readings form sensor and Anval is for storing analog readings. In the void setup, I initialized 2nd pin as input and 8th pin as output. Also, I initialized A0 pin as input and serial monitor’s baud rate for 9600. Inside the void setup, I placed val for digital reads of 2nd pin and anval for A0 pin analog readings. Then I put if condition and set the condition for if it equal to HIGH. It means if digital readings form 2nd become high. Inside that if condition, I made a code for turning on the 8th pin LED and printing motion value in the serial monitor. I added ln for anval for making line break. That will make the readings easier to read. Then I added another if condition and it’s for what to do if 2nd pin’s readings go low. Inside that if condition, I set code for turning of the LED and print the analog readings. It’s not totally efficient to use Tinkercad for this type of thing. But you can tryout and practice it before creating it practically.

If you have any kind of question, please comment below. We are here to reply you and, you can also contact us through the contact us page links. We are available at Telegram and also email. Discord and Reddit replies may be late. But don’t worry. Comment below. Comment section is for everyone. If you see any kind of idea to improve us, please comment it below. See you and have a nice day.

Post a Comment

If you have any doubt, Let us know

Previous Post Next Post