-
Notifications
You must be signed in to change notification settings - Fork 0
/
pir.ino
66 lines (61 loc) · 1.76 KB
/
pir.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPinA = 2; // choose the input pin (for PIR sensor)
int powerPinA = 3;
int inputPinB = 4;
int powerPinB = 5;
int pirStateA = LOW;
int pirStateB = LOW;
int valA = 0; // variable for reading the pin status
int valB = 0;
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPinA, INPUT); // declare sensor as input
pinMode(powerPinA, OUTPUT);
pinMode(inputPinB, INPUT);
pinMode(powerPinB, OUTPUT);
digitalWrite(powerPinA, HIGH);
digitalWrite(powerPinB, HIGH);
Serial.begin(9600);
}
void loop(){
valA = digitalRead(inputPinA); // read input value A
valB = digitalRead(inputPinB); //
// Serial.println(valB);
if (valA == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirStateA == LOW) {
// we have just turned on
Serial.println("A");
// We only want to print on the output change, not state
pirStateA = HIGH;
}
}
if (valA == LOW) {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirStateA == HIGH){
// we have just turned of
Serial.println("Z");
// We only want to print on the output change, not state
pirStateA = LOW;
}
}
if (valB == HIGH) { // check if the input is HIGH
if (pirStateB == LOW) {
// we have just turned on
Serial.println("B");
// We only want to print on the output change, not state
pirStateB = HIGH;
}
}
if (valB == LOW) {
if (pirStateB == HIGH){
// we have just turned of
Serial.println("Y");
// We only want to print on the output change, not state
pirStateB = LOW;
}
}
}