PIR Motion Sensor And Arduino UNO - 2022
Maybe your like
Introduction
Passive Infrared Sensor (PIR sensors) find their applications in many fields. The PIR sensor is used to detect motion. Some of the applications of motion detection are automatic lights control (saves Power, gives more lifetime to the LEDs), Burglar detector/intruder detector - which is a basic safety mechanism to detect movement in unattended houses. It is also used in fencing. For examples. pets are not allowed to travel very far from the garden or house.
In this tutorial we will use a PIR sensor to detect motion. Once the motion is detected, we will turn on an LED for a simple demo. You can expand the project based on your needs further.
Components used
- Arduino UNO
- PIR sensor
- LED
Connection diagram
PIR sensor and Arduino UNO on Wokwi Arduino Simulator- Pin 2 of Arduino goes to Digital Output pin of PIR sensor
- + Pin of PIR sensor goes to 5 V on the UNO
- - Pin goes to GND pin of the UNO
Live Project link:
you can use the PIR motion sensor and Arduino UNO project page to directly interact with the code, modify it and test it online. No hardware is needed. It is very easy to share the code as well. More information on the PIR sensor is documented on Wokwi Docs page.
The code for PIR sensor and Arduino UNO interface
/*PIR sensor tester*/int ledPin = 13; // choose the pin for the LEDint inputPin = 2; // choose the input pin (for PIR sensor)int pirState = LOW; // we start, assuming no motion detectedint val = 0; // variable for reading the pin statusvoid setup() {pinMode(ledPin, OUTPUT); // declare LED as outputpinMode(inputPin, INPUT); // declare sensor as inputSerial.begin(9600);}void loop() {val = digitalRead(inputPin); // read input valueif (val == HIGH) { // check if the input is HIGHdigitalWrite(ledPin, HIGH); // turn LED ONif (pirState == LOW) {// we have just turned onSerial.println("Motion detected!");// We only want to print on the output change, not statepirState = HIGH;}} else {digitalWrite(ledPin, LOW); // turn LED OFFif (pirState == HIGH) {// we have just turned ofSerial.println("Motion ended!");// We only want to print on the output change, not statepirState = LOW;}}}Feedback and questions?
If you have any questions, please leave a comment here. To discuss with other enthusiast community, I welcome you to Wokwi Discord channel. Also, let me know what would you like to simulate on the Arduino simulator next? Created a project:? - Please share your project here for your fellow readers 😀
Share your interesting projects and browse through several curious projects from fellow developers and makers on Facebook Wokwi Group!
Stay Safe!
Don't stop learning!
#wokwiMakes
Tag » Arduino Ir Motion Sensor Detection
-
PIR Motion Sensor: How To Use PIRs W/ Arduino & Raspberry Pi
-
Arduino With PIR Motion Sensor
-
Interfacing Arduino Uno With PIR Motion Sensor
-
Arduino With PIR Motion Sensor - Random Nerd Tutorials
-
Motion Sensor | Arduino Tutorial
-
Arduino With PIR Motion Sensor - YouTube
-
Using A PIR W/Arduino | PIR Motion Sensor - Adafruit Learning System
-
How To Interface PIR Motion Detection Sensor With Arduino Uno
-
How HC-SR501 PIR Sensor Works & How To Interface It With Arduino
-
Arduino - PIR Sensor - Tutorialspoint
-
PIR Motion Sensor With Arduino In Tinkercad - Instructables
-
Arduino Motion Sensor
-
Arduino Motion Sensor - JavaTpoint