Skip to content

Commit c309e35

Browse files
Create motion.ino
1 parent b544121 commit c309e35

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

motion.ino

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
int led = 12;
2+
int pin = 2;
3+
4+
int value = 0;
5+
int pirState = LOW;
6+
7+
void setup() {
8+
pinMode(led, OUTPUT);
9+
pinMode(pin, INPUT);
10+
Serial.begin(9600);
11+
}
12+
13+
void loop() {
14+
15+
value = digitalRead(pin);
16+
17+
if (value == HIGH) {
18+
digitalWrite(led, HIGH);
19+
20+
if (pirState == LOW) {
21+
Serial.println("Motion Detected!");
22+
pirState = HIGH;
23+
}
24+
}else{
25+
digitalWrite(led, LOW);
26+
27+
if(pirState == HIGH){
28+
Serial.println("Motion Ended!");
29+
pirState = LOW;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)