PIR sensor is the motion detection sensor that detects variation in the IR energy of the environment. It works from 3 to 7 metres of lenght based on the calibration. It has got good accuracy and the sensor is very cheap. It can be used for alive human ditection, automatic door opens and for security alarms.
PIR sensor is a digital sensor which has three pins. vcc, ground and Dout. It can be directly interfaced with arduino. Data out can be connected to any of the digital pins.
PIR sensor is a digital sensor which has three pins. vcc, ground and Dout. It can be directly interfaced with arduino. Data out can be connected to any of the digital pins.
Components required
- Arduino
- PIR sensor
- Jumper wires
- Led
Step 1 Pin connections
Vcc - 5v
Dout- any digital pin
Pin 13 - Led
Step 2. Dump the below code to arduino
The code is tested for its functionality
Whenever motion is detected by PIR, the LED will turn ON. The glowing interval depends on the calibration of PIR sensor. Before trying, check out the calibration of the sensor.
The code is tested for its functionality
Whenever motion is detected by PIR, the LED will turn ON. The glowing interval depends on the calibration of PIR sensor. Before trying, check out the calibration of the sensor.
- /*
- * PIR sensor tester
- */
- int ledPin = 13; // choose the pin for the LED
- int inputPin = 9; // choose the input pin (for PIR sensor)
- int pirState = LOW; // we start, assuming no motion detected
- int val = 0; // variable for reading the pin status
- void setup()
- {
- pinMode(ledPin, OUTPUT); // declare LED as output
- pinMode(inputPin, INPUT); // declare sensor as input
- Serial.begin(9600);
- }
- void loop()
- {
- val = digitalRead(inputPin); // read input value
- if (val == HIGH) // check if the input is HIGH
- {
- digitalWrite(ledPin, HIGH); // turn LED ON
- if (pirState == LOW)
- {
- // we have just turned on
- Serial.println("Motion detected!");
- // We only want to print on the output change, not state
- pirState = HIGH;
- }
- }
- else
- {
- digitalWrite(ledPin, LOW); // turn LED OFF
- if (pirState == HIGH)
- {
- // we have just turned of
- Serial.println("Motion ended!");
- // We only want to print on the output change, not state
- pirState = LOW;
- }
- }
- }
No comments:
Post a Comment