Wii camera project servos not moving correctly

New to using Arduino so I apologize if this is an easy fix that I am overlooking. I am trying to replicate a project using the wii IR camera and a pan/tilt camera platform using two 9g micro servos. I have tested the wii camera with a separate blob tracking software and the camera identifies the blobs correctly. After I validate and upload the code to control the servos the servos do not respond as I would expect. As I move a light source in front of the camera the servos only move a tiny bit, but in the opposite direction. I searched online and found that it may be the following settings for the servos, but I am not certain. The post said that they may need to be modified and that I should "play" with them. Not entirely sure how to play with them though. I was going to post the entire code but was not sure how much space it would occupy. Thanks in advance for the help!

servo 1
#define S1_LEFT_SLOW 1550
#define S1_LEFT_MEDIUM 1700
#define S1_LEFT_FAST 1800
#define S1_RIGHT_SLOW 1450
#define S1_RIGHT_MEDIUM 1300
#define S1_RIGHT_FAST 1200
#define STOP 1500
//servo 2
#define S2_RIGHT_SLOW 1510
#define S2_RIGHT_MEDIUM 1525
#define S2_RIGHT_FAST 1560
#define S2_LEFT_SLOW 1490
#define S2_LEFT_MEDIUM 1475
#define S2_LEFT_FAST 1440

You have not posted enough information or enough code for anyone to give you a useful answer

post all the code

I am trying to replicate a project using the wii IR camera

post a link to this

tell us how the wii is communicating etc etc etc

Thanks for the reply, here is all of the code:

#include <Wire.h>
#include <PVision.h>
#include <Servo.h> 
 
Servo servo1;
Servo servo2;
int ledPin = 12;
PVision ircam;
byte result;

//servo 1
#define S1_LEFT_SLOW 1550
#define S1_LEFT_MEDIUM 1700
#define S1_LEFT_FAST 1800
#define S1_RIGHT_SLOW 1450
#define S1_RIGHT_MEDIUM 1300
#define S1_RIGHT_FAST 1200
#define STOP 1500
//servo 2
#define S2_RIGHT_SLOW 1510
#define S2_RIGHT_MEDIUM 1525
#define S2_RIGHT_FAST 1560
#define S2_LEFT_SLOW 1490
#define S2_LEFT_MEDIUM 1475
#define S2_LEFT_FAST 1440


int s;

void setup()
{
  Serial.begin(115200);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  servo1.attach(9); 
  servo2.attach(10);
  ircam.init();
  digitalWrite(13, HIGH);
  
  
}
int x;
void loop()
{
  result = ircam.read();
  
 

  if (result & BLOB1)
  {
    digitalWrite(ledPin, HIGH);
//SERVO 1
      if (ircam.Blob1.X > 480 && ircam.Blob1.X < 520)
        {
          servo1.write(STOP); 
        }

//Servo 1 moves left
      else if (ircam.Blob1.X < 480)
        {

        if (ircam.Blob1.X < 200)
          {
             move_servo1(S1_LEFT_FAST); 
          }
        else if (ircam.Blob1.X < 400)
          {
             move_servo1(S1_LEFT_MEDIUM);
          }
        else
          {
             move_servo1(S1_LEFT_SLOW);
          }
    
        }
//servo 1 moves right
      else if (ircam.Blob1.X > 520)
        {    
         if (ircam.Blob1.X > 800)
          {
             move_servo1(S1_RIGHT_FAST); 
          }
        else if (ircam.Blob1.X > 600)
          {
             move_servo1(S1_RIGHT_MEDIUM);
          }
         else
          {
             move_servo1(S1_RIGHT_SLOW);
          }

        }     
//servo 1 end 

//SERVO 2
if (ircam.Blob1.Y > 365 && ircam.Blob1.Y < 405)
{
  servo2.write(STOP);
}

  else if (ircam.Blob1.Y < 365)
{

  if (ircam.Blob1.Y < 150)
    {
     move_servo2(S2_LEFT_FAST); 
    }
   else if (ircam.Blob1.Y < 270)
    {
     move_servo2(S2_LEFT_MEDIUM);
    }
    else
    {
     move_servo2(S2_LEFT_SLOW);
    }
    
}

else if (ircam.Blob1.Y > 405)
{
 if (ircam.Blob1.Y > 650)
    {
     move_servo2(S2_RIGHT_FAST); 
    }
    else if (ircam.Blob1.Y > 500)
    {
     move_servo2(S2_RIGHT_MEDIUM);
    }
    else
    {
     move_servo2(S2_RIGHT_SLOW);
    }

}     

  }//Ends if Blob
else
{
  digitalWrite(ledPin, LOW);
 servo1.write(STOP);
servo2.write(STOP); 
}

}// ends loop

void printBLOB(int irX)
{ 
 Serial.println(irX); 
}

void move_servo1(int val)
{
//Serial.print(val);
//Serial.print(" ");
//Serial.print(ircam.Blob1.X, DEC);
//Serial.println();
   servo1.write(val);                  

}
void move_servo2(int val)
{
//Serial.print(val);
//Serial.print(" ");
//Serial.print(ircam.Blob1.X, DEC);
//Serial.println();
   servo2.write(val);                  

}

Link to the project

The pixart camera has been removed from the wiimote and soldered to a rocket brand board
https://sites.google.com/a/rocketbrandstudios.com/rocket-brand-studios/store/sensors/wiicamera-arduino

I attached the servos to pins 9 and 10 as indicated by

servo1.attach(9); 
  servo2.attach(10);

and both servos are being powered by the arduino.

The wii camera is attached to the 5v, 3.3v, and the sda and scl pins on the arduino.

Thanks again

The names used in the #defines would seem to indicate that they relate to the speed at which the servos move rather than the position they move to. This in turn implies that continuous rotation "servos" are being used rather than normal ones.

What type of servos are you using and how are they powered ?

and both servos are being powered by the arduino.

Wrong! Servos can not be powered by the Arduino. They need their own power supply.

So it is likely a supply issue, but what about UKheliBob's comment about the type of servo? They are 9g(SG90) micro servos and nothing I can find online lists if they are continuous rotation or otherwise. If the code suggest that I should be using continuous rotation ones, are there any micro sized that will fit my pan tilt rig? thanks all

Continuous rotating servos are a bit of a missnomer. You can not set the angle of one, only control the speed.

what about UKheliBob’s comment about the type of servo? They are 9g(SG90) micro servos

The online details that I can find make it almost certain that they are normal, real servos and as such can be commanded to go to a particular angle and stay there.

My query was because of the names and use of the #defined constants in the program. For instance

#define S1_LEFT_SLOW 1550

Effectively this means that wherever S1_LEFT_SLOW appears in the program it will be replaced with 1550

Somove_servo1(S1_LEFT_SLOW);becomesmove_servo1(1550);which in turn means that when

void move_servo1(int val)
{
   servo1.write(val);                  
}

is executed it becomes servo1.write(1550);

Normally servo.write() takes a value between 0 and 180 to set the angle. It will accept values greater than that and will treat them as microseconds as if the writeMicroseconds() method had been used, but it is unusual to see it used that way instead of just using writeMicroseconds() in the first place.

So, the code will work to move the servo but the #defined names are still strange as the code does not change the speed of the servos, only their position, hence my query about the type of servos. So called continuous rotation servos cannot be moved to a defined angle rather the parameter passed to servo.write() determines the speed and direction of rotation which matches the #defined names better.

Using a normal servo and fixed values for servo.write() as the program does means that the servos could only move to fixed positions. Is that what is supposed to happen ?

Looking at the code I think you do need continuous rotation servos.

If it dosn't say continuous rotation servo in the description then it is not. These types of servos are not common. I have seen one on spark fun's web site though so unless you are into modifying the servo you have then you need new ones.