int ledPin = 14; // pin for LED
int pirPin = 12; // pin for PIR sensor
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(pirPin, INPUT); // declare PIR sensor as input
Serial.begin(115200);
}
void loop() {
val = digitalRead(pirPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn on the LED
if (pirState == LOW) {
Serial.println("Motion detected!");
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn off the LED
if (pirState == HIGH) {
Serial.println("Motion ended!");
pirState = LOW;
}
}
}
uno:VIN
uno:GND.2
uno:D13
uno:D12
uno:D14
uno:D27
uno:D26
uno:D25
uno:D33
uno:D32
uno:D35
uno:D34
uno:VN
uno:VP
uno:EN
uno:3V3
uno:GND.1
uno:D15
uno:D2
uno:D4
uno:RX2
uno:TX2
uno:D5
uno:D18
uno:D19
uno:D21
uno:RX0
uno:TX0
uno:D22
uno:D23
pir1:VCC
pir1:OUT
pir1:GND
led1:A
led1:C
r1:1
r1:2