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);
}
}
}
}