Crazy Erratic servo operation

ok im fairly new to arduino and this is a school project.

My only purpose at the moment is to control 2 servos using pots

I am using spark fun servos if that matters. DGservo s05nf
Which seems to have no data sheet

The servos are wired to a separate DC power supply not the board it self

I have two pots being read into two analog pins, and im using the servo library to write to the servos.

They are going nuts
For some reason the voltage signal is going crazy and sending the servos into a frenzy
When the pots are connected to the power supply and you look at the dvm they show a nice stable signal as you move the pot around
The second you put them on the board the signal goes nuts and starts fluctuating all over.

The power supply is power a breadboard. Which is where the Servo gets its power and also the pot.
I ran the ground pin from the arduino to the ground on the breadboard. So the power supply and arduino share the same ground.
Is that my issue?

Also i have tried several different pots. High and low values
The current ones are 3k adn 250k
The results seem to be worse using a 1 meg pot

Here is the code im using

#include <Servo.h>


Servo servo1;
Servo servo2;



void setup(){

Serial.begin(9600);  
  
servo1.attach(5);
servo2.attach(6);

  
}



void loop()
{
  
  

int angle = analogRead(0);
delay(100);
int angle_claw = analogRead(5);

angle=map(angle,0,1023,10,165);//0 to 1023 int returned == 0to 180 degrees

angle_claw=map(angle_claw,0,1023,10,165);//0 to 1023 int returned == 0to 180 degrees

servo1.write(angle);
delay(15);
servo2.write(angle_claw);

/*
Serial.print("The angle being read in is    ");
Serial.print(angle);
Serial.print("\n\n");
  
//delay(150);

for(int x=0; x<5; x++){
  
 Serial.print("Wait this many seconds before changing pot    ");
Serial.print(x); 
Serial.print("\n\n");
delay(100);
  
}
*/  
  
}

You must have the Arduino and Servo(s) share a Ground so that's not the problem.

The code looks fine assuming your pots are wired correctly: +5, A0/A5, Gnd.

My guess would be a wiring error of some kind. The servos should have +Power on Red, -Power and Arduino Ground on Black and Signal on White (or Yellow).

Some breadboards have the power lines ( red and blue usually) not continuous. If there is a break in the colored line then that is the case.

Hi John

Thanks for the reply

Im actually from Mass myself but at CU at the moment for EE

Well here was my guess
I forgot to mention above they work one at a time ok but it goes nuts when u add the second

Which made my start thinking power supply issues

I actually rewired the whole thing. The way its wired at moment, the servos 5v+ and the pots 5V+ are all shared
So when one loads up it changes the 5+v refereance on the other.
Which makes sense so i rewired it in parallel which now just divided my voltage. So when one pots at zero the other has a potential of 5 but if they are both at all the way down so to speak its really only 2.5 at each. So clearly that wont work . Is my only choice separate supplies for everything? Or atleast seperate supplies for the pots? Let the servos share main power?

@justone

Thanks for the idea but yes of course i do know this and that has been taking care off. Thanks for the thought though. Always good to assume the poster knows nothing just in case he really does i suppose lol

Thanks

you don't really need a datasheet for servo's, they act all the same (the only difference is continuous or angled)

Are you sure they are angled servo's, and not continuous rotation servo's? if not, send a static value to them, e.g. 60, and they should move to that angle and stay there. If they keep on moving, they're continuous rotation servo's, and then the value you print to is the speed, and not the angle.

in any case, here's the wiring for brown, red, orange:

and for red, white black:

I would wire the pots up using the arduinos 5volt rather than the breadboards power supply. Just use the breadboard supply for the servos.

Thanks for all the replies

I figured out the servo pin out a while ago. I had never worked with them but my assumptions were correct
on the colors

Also in regards to my last post please forget the voltage divide comments i was stupid and forgot my ground lol which is why it made it look like it split.

Ok so now the pots are acting independently of each other.
Gonna test it now like this and see results

Stand by!
And thanks for all the input everyone

Ok so here is the new development

There is something wrong with the code for sure

Now that the power is straitened out, i am now sending a nice stable signal into the analog read. Im watching the signal on my scope and dvm and its nice and as you would expect.

However the servo is still going insane?

There is something from with the code for sure!
its either arduino servo issue or something else

I double checked the part time and these are not continuous rotation servos which would make sense of the issue however

Anyone else have any ideas?

Below is the typical arduino servo wiring setup with an external power supply (using the arduino for powering the servos normally causes problems). Bottom is some simple servo test code you can try independent of the pots. 5v is near the normal minimun 4.8v fro servo operation.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}

There is something from with the code for sure! its either arduino servo issue or something else

Well, good to see all aspects are covered.

With the servos disconnected, what do the servo signals look like on the scope?

AWOL:

There is something from with the code for sure! its either arduino servo issue or something else

Well, good to see all aspects are covered.

With the servos disconnected, what do the servo signals look like on the scope?

Thats exactly the issue

I cant see any

Im scoping the signal line and dont ever see a blip

Is the Pwm on these servos on sent for a split second or is it sent continuously?

The signals are sent at around 50Hz continuously.
Are you certain that the supply grounds are connected, and that the supply is up to the job?

AWOL:
The signals are sent at around 50Hz continuously.
Are you certain that the supply grounds are connected, and that the supply is up to the job?

Yep ground tied together for sure and i still cant see any pwn being passed on the scope

The supply is monster high current supply for my DC motors its about 500 times as powerful as it needs to be

Have you tried zoomkat's test code?

Using an external power supply did it work fine for me. Thank you very much!!!
Using UNO and DGServo S05NF STD

Interesting. I have two servo test controllers; on the simple one the servo drives to one end and jams, on the other all the mode lights start blinking erratically and the servo does nothing. If you got it to work by running the servo on it's own dedicated battery that would seem to imply this thing is drawing way too much current. I am testing using a standard R/C flight pack (4.5v) and a servo test rig that generates standard pulses and should allow the servo to be moved through it's normal range of rotation. Any other servo I have (HiTech/Jr) plugged into the same test rig works as expected.

I believe these servos are either defective or they are built to a non standard timing. Unfortunatly for the gripper in question I have not found another servo that fits - next step is to modify the gripper to work with a known good namebrand servo.

Lawrence