Arduino

Arduino Tutorial #6 PIR Motion detection sensor with Arduino & interface with LED light

Motion detection sensor (PIR) with arduino)

If you are visual guy you can watch this tutorial in video mention below this lesson.

hi guys in this tutorial we will see how to use motion detection sensor in Arduino & interface with LED light. So lets get started.  PIR sensor this is also called motion detection sensor. we can use this sensor in home automation like lights off automatically when there is no one in the room & light ON when someone enters the room. It can be also use for counting people or object I will show you in next tutorial.PIR sensor have two slot which senses IR if someone (warm body human or animal) passes by it. It will have difference in IR which will cause positive differential change between both slot. It will detect whenever there is IR changes.

Components:
  1. PIR sensor,
  2. Arduino,
  3. jumper wire,
  4. Bread board,
  5. LED light.

To see which pin is for VCC & GND. Just remove the white cover you can see there is pin name & in some sensor it is printed on the bottom side of circuit so make sure which in VCC & GND and middle one is for output.

Pin number
Pin number
PIR sensitivity & time trigger trimport
PIR sensitivity & time trigger trimport

 

 

 

 

 

 

 

 

 

PIR has a trimpot which can be use for adjusting sensitivity & trigger time.

Circuit diagram:

Do connection as shown in diagram.

PIR sensor circuit diagram
PIR sensor circuit diagram

 

sketch:
int ledPin = 13;                // choose the pin for the LED
int inputPin = 3;               // 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;
      delay(200);
    }
  } 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;
    }
  }
}

 

We will set the pin number 13 for LED, input pin which is our PIR sensor output pin. When Arduino start there is no motion therefore pirstate is low. Val which is variable for reading pin PIR sensor initially at zero that is low. Pinmode declare the LED as output, sensor as input. Serial.begin will initialize the communication between computer & Arduino. Val value equal to sensor input value. If it is high LED light will on. If pirstate value is low. it will print motion detected. And set  pirstate equal to high. To prevent printing motion detected or motion ended repetitively. You can give any second delay for LED light. We want only output when it is detected it will show in serial monitor. If val is low it will turn off light. It will print motion ended. Upload the sketch. Go to tool & serial monitor. When I move my hand over sensor it will show motion detected when hand passed the sensor it shows motion ended. If it is continuously blinking or LED is ON so adjust the sensitivity & time trigger trim port.

Components to buy online:

http://amzn.to/2fvSRJq   (Arduino)

http://amzn.to/2vqnDHc   (PIR sensor)

http://amzn.to/2wxPmWz  (Breadboard)

http://amzn.to/2vJ3lvo   (Jumper wire)

http://amzn.to/2vSpUON   (LED)

  Till then keep learning keep making. 🙂

3 thoughts on “Arduino Tutorial #6 PIR Motion detection sensor with Arduino & interface with LED light

Leave a Reply

Your email address will not be published. Required fields are marked *