//line to the project in the description
/*
PIR sensor tester
*/
int ledpin =13; //choose the pin for the LED
int inputpin = 2; //choose the input pin (for Pin 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(inputpin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputpin); //read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledpin, HIGH); //turn LED ON
if(pirstate == LOW) {
// we have just turned on
Serial.print("Motion detected");
// we only want to print on the output change, not state
pirstate = HIGH;
}
} else {
digitalWrite(ledpin, LOW); //turn LED OFF
if (pirstate == HIGH){
// we have just turn of
Serial.println("Motion ended");
// we only want to print on the output change, not state
pirstate = LOW;
}
}
}