/*
PIR sensor tester
*/
#include <Servo.h>
#define UP 2
#define DOWN 3
Servo myServo;
int inputPin = 11; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
int PMW = 9; // variable for reading the pin status
int position = 0;
void setup() {
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(UP, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
pinMode(DOWN, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
myServo.attach(PMW);
myServo.write(position);
Serial.begin(9600);
}
void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
}
else {
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
if(!digitalRead(UP)){
position +=1;
myServo.write(position);
delay(5);
}
if(!digitalRead(DOWN)){
position -=1;
myServo.write(position);
delay(5);
}
}