Movement Detection Using PIR Sensor and Arduino
OBJECTIVE
The objective of this project is to detect human movement using a PIR sensor and Arduino to trigger a response such as lighting an LED .
MODULES REQUIRED
- Arduino uno
- Pir motion sensor
- LED
SCHEMATIC DIAGRAM
SCHEMATIC CONNECTION
Connect pir :
Connect led:
To begin your project, click this template link:
ARDUINO CODE
int led = 8;
int pir = 9;
int state = LOW;
int val = 0;
void setup() {
pinMode(led, OUTPUT);
pinMode(pir, INPUT);
Serial.begin(9600);
}
void loop(){
val = digitalRead(pir);
if (val == HIGH) {
digitalWrite(led, HIGH);
delay(100);
if (state == LOW) {
Serial.println("Movement detected!");
state = HIGH;
}
}
else {
digitalWrite(led, LOW);
delay(200);
if (state == HIGH){
Serial.println("No movement!");
state = LOW;
}
}
}