How to use PIR Motion sensor with Arduino

Posted by admin 21/08/2018 0 Comment(s)

 

 

How to use PIR Motion sensor with Arduino

 

 


 

Circuit diagram:

 

 

 

Motion Sensor connection with Arduino
PIR motion sensorArduino
VCC5V
GNDGND
OUTD2

 

 

Relay Module/Led connection with arduino
LedRelay ModuleArduino
+VCC5V
-GNDGND
 IND13

 

 

 

 

 

 

 


 

Code

int led = 13;                // the pin that the LED is atteched to
int sensor = 2;              // the pin that the sensor is atteched to
int state = LOW;             // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)

void setup() {
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
  Serial.begin(9600);        // initialize serial
}

void loop(){
  val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH
    digitalWrite(led, HIGH);   // turn LED ON
    delay(100);    

 

 

 

 

 

Write a Comment