#define pirPin 2
#define outPin 13
int val;
void setup() {
Serial.begin(112500);
pinMode(pirPin,INPUT);
pinMode(outPin,OUTPUT);
digitalWrite(pirPin,LOW);
digitalWrite(outPin,LOW);
}
void loop() {
val = digitalRead(pirPin); //read state of the PIR
if (val == LOW) {
Serial.println("No motion"); //if the
value read is low, there was no motion
digitalWrite(outPin,LOW);
}
else {
Serial.println("Motion!"); //if the
value read was high, there was motion
digitalWrite(outPin,HIGH);
}
delay(1000);
} |