PIR sensors allow you to sense motion. They are used to detect
whether a human has moved in or out of the sensor’s range. They are
commonly found in appliances and gadgets used at home or for businesses.
They are often referred to as PIR, "Passive Infrared", "Pyroelectric",
or "IR motion" sensors.
Following are the advantages of PIR Sensors −
PIRs have adjustable settings and have a header installed in the 3-pin ground/out/power pads.
For many basic projects or products that need to detect when a person has left or entered the area, PIR sensors are great. Note that PIRs do not tell you the number of people around or their closeness to the sensor. The lens is often fixed to a certain sweep at a distance and they are sometimes set off by the pets in the house.
Once the sensor detects any motion, Arduino will send a message via the serial port to say that a motion is detected. The PIR sense motion will delay for certain time to check if there is a new motion. If there is no motion detected, Arduino will send a new message saying that the motion has ended.
Following are the advantages of PIR Sensors −
- Small in size
- Wide lens range
- Easy to interface
- Inexpensive
- Low-power
- Easy to use
- Do not wear out
PIRs have adjustable settings and have a header installed in the 3-pin ground/out/power pads.
For many basic projects or products that need to detect when a person has left or entered the area, PIR sensors are great. Note that PIRs do not tell you the number of people around or their closeness to the sensor. The lens is often fixed to a certain sweep at a distance and they are sometimes set off by the pets in the house.
Components Required
You will need the following components −- 1 × Breadboard
- 1 × Arduino Uno R3
- 1 × PIR Sensor (MQ3)
Procedure
Follow the circuit diagram and make the connections as shown in the image below.Sketch
Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New.Arduino Code
#define pirPin 2 int calibrationTime = 30; long unsigned int lowIn; long unsigned int pause = 5000; boolean lockLow = true; boolean takeLowTime; int PIRValue = 0; void setup() { Serial.begin(9600); pinMode(pirPin, INPUT); } void loop() { PIRSensor(); } void PIRSensor() { if(digitalRead(pirPin) == HIGH) { if(lockLow) { PIRValue = 1; lockLow = false; Serial.println("Motion detected."); delay(50); } takeLowTime = true; } if(digitalRead(pirPin) == LOW) { if(takeLowTime){ lowIn = millis();takeLowTime = false; } if(!lockLow && millis() - lowIn > pause) { PIRValue = 0; lockLow = true; Serial.println("Motion ended."); delay(50); } } }
Code to Note
PIR sensor has three terminals - Vcc, OUT and GND. Connect the sensor as follows −- Connect the +Vcc to +5v on Arduino board.
- Connect OUT to digital pin 2 on Arduino board.
- Connect GND with GND on Arduino.
Once the sensor detects any motion, Arduino will send a message via the serial port to say that a motion is detected. The PIR sense motion will delay for certain time to check if there is a new motion. If there is no motion detected, Arduino will send a new message saying that the motion has ended.
No comments:
Post a Comment