Sunday, April 25, 2021

How PIR work | PIR motion sensor with and without arduino

 Hello My name is Manitesla i'll be teaching you guys how to use PIR sensor. HC-SR501 PIR sensor has three output pins VCC, Output and Ground as shown within the diagram below. It has a built-in transformer so it are often powered by any DC voltage from 4.5 to 12 volts, typically 5V is employed . Other than this, there are a few options you've got together with your PIR. Let’s check them out.

One of the explanations of HC-SR501 PIR sensor being extremely popular is that the incontrovertible fact that HC-SR501 may be a very versatile sensor that's pretty capable all on its own. And by interfacing it to some microcontrollers like an Arduino you'll expand upon its versatility even further. For our first experiment we'll use the HC-SR501 on its own for instance how useful it's by itself.


Pir Sensor

The wiring for this experiment is very simple. Batteries are connected across VCC and GND of the sensor and alittle Red LED is connected to the output pin through a 220Ω current limiting resistor. That’s it!

Now when the PIR detects motion, the output pin will go “high” and light up the LED!

Remember once you power up the circuit you would like to attend 30-60 seconds for the PIR to acclimatize to the infrared energy within the room. During that time the LED may blink a little. Wait until the LED is off then move around ahead of it, waving a hand, etc, to ascertain the LED light up!



Pir without arduino

Wiring – Connecting PIR Sensor to Arduino UNO

Now that we've an entire understanding of how PIR sensor works, we will begin hooking it up to our Arduino!
Connecting PIR sensors to a microcontroller is basically simple. The PIR acts as a digital output so all you would like to try to to is listen for the output pin to flip HIGH (Motion Detected) or LOW (Not Detected). Power the PIR with 5V and connect ground to ground. Then connect the output to a digital pin #2.
You will want to line the jumper on the HC-SR501 to the H (Retriggering) position for this to figure correctly. You’ll also got to set the TIME to the minimum of three seconds, turn the TIME potentiometer as far counterclockwise because it will go. Set the sensitivity anywhere you wish , set it to midpoint if you're unsure .


Pir with arduino

Arduino Code:

int ledPin = 13;                // choose the pin for the LED
int inputPin = 8;               // 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) 
	{
      Serial.println("Motion detected!");	// print on output change
      pirState = HIGH;
    }
  } 
  else 











ManiTesla.tech

Author & Editor

Innovator and Robotics enthusisast intrested in building robots and web development

0 comments:

Post a Comment

Ask Something