First project... here is what i have done, i want the servo to turn when the motion sensor sees something (me in the morning making coffee, the cat walking by or an army of evil honey badgers) and then turn a servo (to turn on lights, make coffee or thwart said honey badgers). it should leave a light on while not in action.. i do not have my stuff yet, will probably get it tomorrow, could someone test it or tell me if they see any errors beforehand (the stuff will take a while to arrive so do not worry about being too late)
const byte ledPin = 13; // LED pin
const byte motionPin = 2; // motion detector input pin
byte senseMotion = 0; // variable to hold current state of motion detector
void setup() {
// set the digital pin directions
pinMode(ledPin, OUTPUT);
pinMode(motionPin, INPUT);
servoMain.attach(10); // servo on digital pin 10
}
void loop()
{
// Now watch for burglers
senseMotion = digitalRead(motionPin);
if (senseMotion == HIGH) { // burgler found!
servoMain.write(90); // Turn Servo Left to 90 degrees
} else { // no burgler, yet...
digitalWrite(ledPin, HIGH);
}
}
thank you,