int led = 13;
int pir = 10;
int val = 0;
int state = LOW;
void setup() {
// put your setup code here, to run once:
pinMode (led, OUTPUT);
pinMode (pir, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(pir);
if (val == HIGH)
{
digitalWrite(led, HIGH);
if (state == LOW)
{
Serial.println("Motion detected!");
state = HIGH;
}
}
}