Help with motion activated servo please.

wildbill:
Try removing the calls to delay.

Thanks, but I had to put delays in. Without any delays, the servo just rotates continuously and uncontrollably. With only one delay, it does a quarter rotation and snaps back.

PaulS:
But not reposted it.

Sorry, all I did was take that line out of the code. I'll post the code below.

PaulS:
Servos don't have "start postion"s. They have whatever position they were in when they were powered off.

Ah, ok thanks. It's important that my servo rotates from the same location each time, so I think it is set up right for that then.

PaulS:
When motion IS detected? Or, when motion BECOMES detected? Not the same thing at all.

When it detects a movement (each time something passes the sensor).

Code:

#include <Servo.h>

 int pos = 0;
 int PIR = 7;
 Servo myservo;

 void setup () {
 pinMode(PIR, INPUT);
 myservo.attach(11);
 }

 void loop (){
  if (digitalRead(PIR) == HIGH) {
    myservo.write(300);
    delay(2000);
 }
if (digitalRead(PIR) == LOW) {
    myservo.write(0);
    delay(2000);
 }
 }