#include <Servo.h>
#define PIRpin 10
#define servoPIN 6
#define PushButtonUP 4
#define PushButtonDOWN 3
Servo brazo;
int position=100;
int statePIR=LOW;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(PushButtonUP,INPUT);
pinMode(PushButtonDOWN, INPUT);
pinMode(PIRpin,INPUT);
brazo.attach(servoPIN);
brazo.write(position);
}
void loop() {
// put your main code here, to run repeatedly:
int readPin_PIR=digitalRead(PIRpin);
int readPin_PUSHButtonUP=digitalRead(PushButtonUP);
int readPin_PUSHButtonDOWN=digitalRead(PushButtonDOWN);
if(readPin_PIR==(HIGH))
{
if(statePIR==LOW)
Serial.println("Motion in place");
statePIR=HIGH;
}
else{
if(statePIR==HIGH)
Serial.println("No motion");
statePIR=LOW;
}
if(readPin_PUSHButtonUP==HIGH)
{
if(position<=180){
position +=2;
brazo.write(position);
delay(10);
}
}
if(readPin_PUSHButtonDOWN==HIGH)
{
if(position >=0){
position -=2;
brazo.write(position);
delay(10);
}
}
}