How to use PIR motion sensor - Simple tutorial
Wednesday, April 19, 2017This is a simple, brief guide to use or test your PIR motion sensor with arduino for first time.
When the PIR sensor is detect a motion the LED will glow.
Parts required
- Arduino UNO/Nano (any arduino board)
- HC SR501 PIR sensor module
- Jumper cables
- LED bulb
Steps
- Connect +ve (long leg) of LED to Arduino pin 2
- Connect -ve (short leg) of LED to Arduino pin GND
- Connect VCC of PIR sensor to Arduino pin 5V
- Connect OUT of PIR sensor to Arduino pin 9
- Connect GND of PIR sensor to Arduino pin GND
Circuit diagram of PIR motion sensor with arduino.
Source code for PIR motion sensor with arduino.
int pirPin = 9; //the digital pin connected to the PIR sensor's output
int ledPin = 2; //the digital pin connected to the +ve od LED
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
}
void loop() {
if(digitalRead(pirPin) == HIGH)
{
Serial.print("Motion Detected");
Serial.print('\n');
digitalWrite(ledPin, HIGH);
}
if(digitalRead(pirPin) == LOW)
{
digitalWrite(ledPin, LOW);
Serial.print('\n');
}}
Click here to download the code
1 comments
Using PIR MOTION SENSOR was an intimidating tak for me because i have not proper information about the requirements and things which we need to carry it but your post has helped me a lot . Dissertation Writing Service
ReplyDeleteClick on 'Notify me' to get replies of your comment.