Servo Problems Help

Hi All,

I still very green with arduino but have had some success with bits. However this one has me (and some more advanced arduino users) completely stumped.

Basically, I’ve written some code which creates a motion tracking platform for some art for a uni project. Here’s an example (not mine) :

However, I needed mine to be more durable since the art in question is quite heavy and this is where the problem came about. After upgrading to the new servos, my code stopped working and caused the servo to turn full CW and stall or sometimes swing back and forth no matter what code was used.

After lots of troubleshooting, these are the conclusions I have:

  • The code is written correctly as the smaller servos work with it and others see no problem with it
  • The circuit is built correctly as I had it looked at by someone more qualified than me, all grounds and power are coming from the same source and it is stable according to the oscilloscope
  • None of the components are faulty as I have spares of everything and have the same issue
  • The PWM output is working correctly, changing length for the desired orientation (again, oscilloscope)
  • Some guessed that the Attach(min, max) functions could hold to key to fixing the issue but attempts yielded no fix

This leads me to believe it must be the difference between the servos but unfortunately I’m out of my depth at this point. Could someone suggest what the issue is?
Here’s the small servo that works: http://www.servocity.com/html/s3003_servo_standard.html
Here’s the Bigger ones that don’t: http://www.servocity.com/html/s3306.html

I can show you my main code, but I think its way too long, however, something even as simple as this sweep code doesn’t even work:

// setup libraries
#include <Servo.h>;
Servo myServo;

int servoPos = 0;
//declare pins
int servoPin = 11;
int dir = 10;
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  
  myServo.attach(servoPin, 100, 200);
  Serial.begin(9600);
  Serial.println("Begin");
  myServo.write(servoPos);
  

  
}

void loop() {


servoPos = servoPos + dir;
if (servoPos > 170) {dir = -10; } else if (servoPos < 10) {dir = 10; };
Serial.println(servoPos);
delay(500);

myServo.write(servoPos);
}

Sorry for the mini essay, but I really could use some advice and I know in the past I’ve been unclear or left important bits out so I wanted to cover all the bases :slight_smile:

Thanks in advance!

Jack

How is this powered? Maybe show how it is all wired up.

Hi Nick,

Thanks for the speedy reply! Its probably easier to describe it as a picture would be really complicated. Here a brief description:

  • A 9v/2Amp supply is fed into 2 voltage regulators, one 5v and one 6v
  • The 5v supply is fed to the arduino and the distance sensors for the motion tracking
  • The 6v supply is fed to the S3306 servo and small fan to keep everything cool
  • Everything is Earthed together via 9v supply's (-) side via the breadboard (-) rail

Hope this makes sense, if there's anything that doesn't please feel free to ask!

Thanks again,

Jack

Try some decoupling capacitors on the board side or the servo side (or both).

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Hi Nick,

Thanks for the link :) Actually the original guide I followed for my circuit used capacitors but the circuit didn't work. I suspect I didn't wire it correctly or had the wrong value capacitors. This page, however is a bit beyond my knowledge, :~ Could you suggest what value capacitors I should try and how to arrange them with the regulator? From my previous attempt I can deffinatly tell you I haven't the first clue of the correct way of doing this.

Thanks again!

Jack

•The circuit is built correctly as I had it looked at by someone more qualified than me, all grounds and power are coming from the same source and it is stable according to the oscilloscope

99% chance that is the source of your issue. Did you monitor the arduino 5v pin voltage with the o-scope when the servos were trying to move? A standard servo under load can probably pull more than 1a when trying to start moving.

Edit: below is a way I isolated a servo control chip from voltage drops when two servos I have for a pan/tilt cam setup start to move.

Hi Zoomkat,

Unfortunately we didn't :~ And I'm now about 30 miles from the nearest one I can use. I have a feeling that it was fine though since we ran the servos with the o-scope on the servo's pin and the output looked stable and the servo didn't konk out.

Thanks again!

Jack

A simple test might be to power the arduino separately via a 9v battery and see if the issue persist.

Hi Zoomkat,

We tried something similar, powering the servo via the circuit and the arduino via the usb connector with the earths connected still. Even trying this, the problem remained :~

The cause of a servo traveling in one direction until it hits the hardstop is often a bad/corrupt control signal to the servo (the arduino resetting due to low voltage might cause this effect. Where are you connecting the 5v regulator chip output on the arduino? Below is some simple servo test code that should help determine if there is a code problem.

// 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, 500, 2500);  //the pin for the servo control, and range if desired
  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
  } 
}

Hi Zoomkat,

I'm connecting the 5v supply to the Vin pin of the arduino. Also the o-scope showed a stable control signal with no static and a clear PWM signal changing as specified by the code. I won't be able to try out your code till tomorrow, what does it do exactly? Just so I know what I'm looking for :) I've read through it but I was a bit lost at points.

Thanks again!!

Jack

dantedraven13: I'm connecting the 5v supply to the Vin pin of the arduino.

That means the 5V supply will be connected via the onboard voltage regulator, which needs a minimum of 7V to produce a 5V output to the microcontroller. If you have a regulated smoothed 5V supply you should be able to connect it directly to the Arduino's 5V terminal i.e. bypassing the onboard regulator.

The code just moves a servo to the commanded position. With a multimeter have you measured the voltage at the arduino 5v pin? If you look at the below schematic it appears that your supplying the 5v supply to the VIN pin will have issues due to having to go thru the on board regulator chip with a significant voltage drop. Try connecting the output of your 5v regulator chip to the 5v pin on the arduino.

http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf

Hi Guys,

So basically I’m not giving the Arduino enough power? I didn’t know the 5v pin was an input as well :astonished: I’ve always used to just to power the (+) rail on my breadboard. Also earlier Nick mentioned I should try de-coupling capacitors on the 6v regulator but I have no idea what values they should be or how they are arranged across the pins of the regulator (if thats right). Could either of you suggest how I should do this?

Thanks again!!

Jack

So basically I'm not giving the Arduino enough power?

If you don't understand the previous post, you may need an easier project. :roll_eyes:

Hi Zoomkat,

zoomkat: If you don't understand the previous post, you may need an easier project. :roll_eyes:

I'm just trying to make sure you mean 'connect the power to the 5v pin' since I haven't been told anything to suggest that pin can be used as an input to power the arduino till now. I can't afford to destroy my arduino by put current down the wrong pin.

Thanks again!

Jack

dantedraven13: I'm connecting the 5v supply to the Vin pin of the arduino.

That is not intended for that. Vin goes through the voltage regulator and should be at least 7v. If you have 5v and it is regulated already then that can go on the 5v pin (not Vin). A decoupling capacitor would be a 0.1 µF capacitor between your 5v supply and Gnd.

By "regulated already" I mean, if you measure it with no load it should show 5v. Some power packs put out a much higher voltage than the rated ones if they are under a light load.