Need help with MG99R pan tilt

Hey all

A bit of a newbie here and feeling my way around things and appreciate any assistance in advance.

I'm trying to make a pan tilt device. I started with 2x micro 9G servos and everything works. The servo's were powered by a small phone charger.

Code I used:

#include <Servo.h>
Servo servo1;
Servo servo2;
int xaxis = A0;
int yaxis = A1;
int xpos = 90;
int ypos = 90;

int val;

void setup()
{
servo1.attach(4);
servo2.attach(5);
Serial.begin(9600);
}

void loop()
{
val = analogRead(xaxis);
val = map(val, 0, 1023, -1, 2);
xpos = xpos + val;
if (xpos > 180) xpos = 180;
if (xpos < 0) xpos = 0;
servo1.write(xpos);

val = analogRead(yaxis);
val = map(val, 0, 1023, -1, 2);
ypos = ypos + val;
if (ypos > 180) ypos = 180;
if (ypos < 0) ypos = 0;
servo2.write(ypos);

Serial.println("X-position is");
Serial.println(xpos);
Serial.println("Y-position is");
Serial.println(ypos);
delay(0);
}

But the servos were under powered so I replaced it with 2xMG996R servos. using the same mobile phone charger, one servo behaved erratically and the other did not respond.

I upped the power source for the servos using a 5V5A ACDC adapter and neither would work

Does the code need to be looked at or is it the power supply? I'm really confused.

Thanks again!

Please post schematics and a link to the motors. Explain what the mapping of 0 to 1023 into -1 to 2 is intended to do. map returns an integer as far as I know...

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Hi Railroader,

Here's a sketch of the circuit:

The mapping of 0 to 1023 was meant to slow the speed of the motor to allow for greater position control.

Thanks

5V 5A should be adequate for 2 x MG996s provided it is a good regulated power supply and the supply negative is connected to the servos AND the Arduino GND which your sketch does not show.

Steve

Thanks! Almost okey...
Read the reply from Slipstic!

Thanks! i'll give that a go and report back

Supplying power to motors through a breadboard, expect issues.

The bread board will get damaged and future projects will face "impossible", unexpected problems.....

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.