IR sensor and servos

Hey everyone. Only my second ever post and I'm really stuck.

I am trying to create a mirror that tracks people as they walk past. It is just the one mirror just now to prototype it.Both Servo motors have to work and turn at the same time to have vertical tilt and horizontal tilt.

I have 2 x servos
1 x IR sensor (Not PIRsensor)

I can't seem to get the IR sensor to control 1 servo never mind the two.

Any help would greatly appreciated.

code :

#include <Servo.h>
int sensorPin = A0;
Servo servoPan;
Servo servoTilt;
int sensorValue = 0;

int pos = 0;

void setup(){
servoPan.attach(11); //pan servo is on pin 11
servoTilt.attach(12); // tilt servo is on pin 12
servoPan.write(176); // home both servos to centre
servoTilt.write(176); // home both servos to centre
}

void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue < 300){
if(Serial.available() >=2 ) { //two bytes waiting for us
int pan = Serial.read(); // 1st byte is Pan position
int tilt = Serial.read(); // 2nd byte is Tilt position
servoPan.write(pan); // move pan servo
servoTilt.write(tilt); //move tilt servo}
}
for(pos = 0; pos < 180; pos +=1)
{
servoPan.write(pos);
delay(15);
}
for(pos = 180; pos >=1; pos -=1)
{
servoPan.write(pos);
delay(15);

for(pos = 0; pos<180; pos +=1)
{
servoTilt.write(pos);
delay(15);
}

for(pos = 0180; pos >=1; pos -=1)
{
servoTilt.write(pos);
delay(15);
}
}
}
}

Perhaps you are intending the code at the end of loop() that waggles both servos to be in an "else" block so they only happen when sensorValue >= 300? At the moment they will waggle everytime through the loop(), which can't be very useful.

for(pos = 0180; pos >=1; pos -=1)

The leading 0 defines an octal value. Probably not what you want.

Haha thanks!

Well now both servos work but they don't turn together, they rotate in turns and the motion sensor doesn't seem to stop them when nothing is moving.

I took out that if statement but wasn't sure if the else function should go after the "if" because if the distance is less then 300 then i want it to switch on, the else would be to switch it off would it not?

but they don't turn together, they rotate in turns

That's because that is how you've written the sketch, with the movement in sequence.