Arduino-Servo Motor-PIR sensor-Please help

i have a gate system project which is connected PIR and servo motor to the arduino board. The arduino is then connected to the VB.NET. Here is my question, how can i close the gate (servo motor as my gate) once the motion is detected by the PIR? Below is my coding.

#include <Servo.h>

Servo myservo;  //creates a servo object
Servo myservo2;                 //a maximum of eight servo objects can be created


//amount of time we give the sensor to calibrate(10-60 secs according to the datasheet)
int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;        

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000; 

int pirPin = 12;            //digital pin connected to the PIR's output
int pirPos = 13;           //connects to the PIR's 5V pin

void setup(){
  myservo.attach(5);    //attaches servo to pin 4
  myservo2.attach(3);
  Serial.begin(9600);    //begins serial communication
  pinMode(pirPin, INPUT);
  pinMode(pirPos, OUTPUT);
  digitalWrite(pirPos, HIGH);

  //give the sensor time to calibrate
  Serial.println("calibrating sensor ");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(calibrationTime - i);
    Serial.print("-");
    delay(1000);
  }
  Serial.println();
  Serial.println("done");
 
  while (digitalRead(pirPin) == HIGH) {
    delay(500);
    Serial.print(".");     
  }
  Serial.print("SENSOR ACTIVE");
}

void loop(){
int pos;
if (Serial.available()>0){
  pos=Serial.read();
  if(pos=='0'){
  openGate();
  }
}

if(digitalRead(pirPin) == HIGH) //turn servo
{ 
    closeGate();

  }

  

}

void closeGate(){

  myservo.write(90);
  myservo2.write(90);
  }

 void openGate(){
 myservo.write(-90);
 myservo2.write(-90);
 delay(60000);
 }

Appreciate for the help. Thanks

So what does it do and what doesn't it do that you want it to? And how is it all connected?

Steve

Hi slipstick, thanks for reply. All hardware are connected. The servo motors are successfully rotated 90 degree once the button in the VB.NET software application is clicked. However, it does not rotate back to the original position when the motion is detected by the PIR sensor motion.

ps: sorry for broken english

I think i have make it the problem stated above. Here comes another problem. Once i connected the buzzer, it keeps bee....beee.... how can i make it stop and sounds when it is needed but not all the way?

I cannot see anything in your code that does anything with any sort of buzzer.

I'm not good at guessing games.

Steve