Servo Motor And PIR

There are 4 pir and 1 servo motor and each pir has its own degree. when a pir detect the motion then servo motor rotates to degree of motion but this pir returns to its degree as triggered after the servo motor return to starting point. servo motor makes this situation 2 or 3 times.

is the problem about connection or codes ?

#include <Servo.h>

Servo myservo;
int pin1 = 2;
int pin2 = 4;
int pin3 = 11;
int pos = 0;
int pin4 = 6;
int wait = 1000;

void setup(){
Serial.begin(9600);
pinMode (pin1,INPUT);
pinMode (pin2,INPUT);
pinMode (pin3,INPUT);
pinMode (pin4,INPUT);
myservo.attach(13);
myservo.write(90);
}

void loop (){

int sensor_1 = digitalRead(pin1);
int sensor_2 = digitalRead(pin2);
int sensor_3 = digitalRead(pin3);
int sensor_4 = digitalRead(pin4);

if (sensor_1 == HIGH){
Serial.println(sensor_1);
myservo.write(125);
delay(wait);
}
else if (sensor_2 == HIGH){
Serial.println(sensor_2);
myservo.write(106);
delay(wait);
}
else if (sensor_3 == HIGH){
Serial.println(sensor_3);
myservo.write(68);
delay(wait);
}
else if (sensor_4 == HIGH){
Serial.println(sensor_4);
myservo.write(55);
delay(wait);

}
else
{

myservo.write(90);
}

}

(not sure if I fully understand what yot mean..)
I guess part of problem is that when triggered, the PIRs keep their high output for several seconds.
Your code should change order when reading, so all sensors are treated equally

#include <Servo.h>

Servo myservo;
#define pin1 2
#define pin2 4
#define pin3 11
#define pin4 6
// int pos = 0;
int wait = 1000;

byte pir[4][2]={{pin1,125},{pin2,106},{pin3,68},{pin4,55}};
byte i,j,k; // general counters
boolean movement; // used to decide 'goto 90 deg'

void setup(){
  Serial.begin(9600);
  pinMode (pin1,INPUT);
  pinMode (pin2,INPUT);
  pinMode (pin3,INPUT);
  pinMode (pin4,INPUT);
  myservo.attach(13);
  myservo.write(90);
}

void loop ()
{
  movement=false; //guess no movement
  i++; 
  for (k=0; k<=3; k++) // run all 4 sensors
  {
    j=(i+k)%4; // this will be a number running througt 0..3 , repeated
    if (digitalRead(pir[j][0])== HIGH) //
    {
      movement=true;    
      Serial.print("sensor "); // print sensors number
      Serial.println(j);
      myservo.write(pir[j][1]); // and move servo to correct position for 1 sec
      delay(wait);
    }
  } 
  if (!movement) myservo.write(90);
}

bro code worked but there is nothing changed,the problem continues :frowning:

When a PIR is triggered… Have you measured the time it keeps its output high?
(on most sensors, this time can be set by user)
If possible, set the sensor to NOT retriggable

knut_ny:
When a PIR is triggered.. Have you measured the time it keeps its output high?
(on most sensors, this time can be set by user)
If possible, set the sensor to NOT retriggable

I do not count the time while pir's output high.
Do you mention potentiometer while taking about setting the time?
I do not know what you wanted to tell with this sentence "If possible, set the sensor to NOT retriggable"
I would be happy and glad if you can explain all these points bro.

++++