-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpir-sensor.ino
38 lines (34 loc) · 863 Bytes
/
pir-sensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Read human presence in PIR motion senser
/*
* For this we need
* 1.Arduino Uno
* 2.PIR sensor (VCC-5V,GND-GND,OUTPUT-2(DigitalPin)
* 3.LED (Led blink on motion) 13&GND
*/
int led = 13;
int pin = 2;//OUTPUT for PIR senseor
int value = 0; //Read initial data comes from sensor
int pirState = LOW; //status of PIR sensor Reading HIGH or LOW
void setup() {
pinMode(led, OUTPUT);
pinMode(pin, INPUT);
Serial.begin(9600);
}
void loop() {
value = digitalRead(pin);//reading data from sensor
//if Human body comes in sensor range
if(value==HIGH){
digitalWrite(led, HIGH);//led blink on human motion
if(pirState == LOW){
Serial.println("Motion Detecting!");
pirState = HIGH;
}
}
else{
digitalWrite(led, LOW);
if(pirState == HIGH){
Serial.println("Motion Ended!");
pirState = LOW;
}
}
}