Servo motor question

I have a sketch(program) on the nano board. The sketch operates a servo motor. I have found that if the servo does not start from start position( zero on control line) the program does not work. This agrees with what somebody has said about a servo not working properly if it doesn't go from its start position.
This is at odds with the Arduino pot example. This works ok even without the servo being first set to its start position. Can anyone explain this?

As usual, please post a sketch that illustrates your problem

When you attach() a servo in the sketch it will move to its default home position of 90 degrees even before you write() to it. If you want the servo to move to a different starting position when attach()ed then write() to it before attach()ing it

Where did they say this ?

you can measure the voltages on the yellow control line with a multimeter. These are very low of course because of the low duty cycle of the signal. I have measured 0.140 at the start or default position. Then it goes up from there. Typical figures are; 0.140,0.221, 0.453. When the servo is responding.
Now when my servo has failed (not moving anymore) I am getting a constant 0.378 reading. I am using the 'pot' example in Arduino. This is the obvious reason it has failed.
Then this would also indicate that the PWM from my Nano board pin 9 has failed.
What could have caused the PWM signal to fail? Might have to try another PWM pin now.

More confusion

  • Using the Servo library does not require the servo to be connected to a PWM capable pin. Any GPIO pin will work
  • The Servo library outputs its own PWM signal that changes between 0V and 5V at a frequency of 50Hz
  • You are trying to measure a 50Hz signal with a multimeter, probably on a DC setting, and have observed an apparent change of voltage, but what you are seeing is the change of duty cycle of the PWM signal

When you attach your servo, the horn will go to "its starting position" which probably is 90 degrees, determined by your library. For example, if you upload this sketch, your servo probably with move to 90 degrees, then the sketch says to move to 0 degrees.

#include <Servo.h>
#define servoPin 9
Servo myservo;

void setup() {
  myservo.attach(servoPin);
  myservo.write(0);
}

void loop() { 
  // empty
}

Then, upload this sketch, and your servo should go to 90 degrees, the starting position of the object, and stay at 90, because it is not followed with a servo command to another angle.

#include <Servo.h>
#define servoPin 9
Servo myservo;

void setup() {
  myservo.attach(servoPin);
}

void loop() { 
  // empty
}

Somebody was telling you something wrong. This usually means you did not understand "somebody" or/and "somebody" did not understand the subject.

I have been using this sketch. It was moving a servo motor in a vertical direction. For some unknown reason it is not moving the servo motor anymore. Some of my inputs were; 0,20,30 70,90, 110,120. The motor was horizontal at 30. At 120 it was 90 degrees vertical.

type or paste code here
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int val;    // set val between 0-180 to move servo

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(115200);
}
void loop() {
Serial.print("input value for variable val: ");
while (Serial.available() == 0) {
  }
val = Serial.parseInt();
Serial.print("val=");
Serial.println(val);
 myservo.write(val);                  // sets the servo position 
  delay(15);                           // waits for the servo to get there
}
Is there a way to test the servo because it must have failed. Unless somebody can see a possible error in the code or in the way I used it. When it was working originally I may have done something different.

Servos don't usually move vertically so I am not sure what you mean by this

  • What have you got the Line Ending set to in the Serial monitor ?

  • Which Arduino board are you using ?

  • What type of servo are you using (link please) and how is it powered ?

As to testing the servo, what happens when you run the Servo Sweep example ?

See post #2 and #5.

This OP has a history of vaguery.

2 Likes

Pan and tilt control with 2 servo motors
the top servo motor moves vertically. the bottom servo moves horizontally.
line ending set to 'no line ending'
nano board
HF-S3235 25kg servoHF-S3235
powered from 5v 800ma regulator
I will test with the 'pot' example to see if that will move it.
I know all these questions are relevant Bob. Its just very annoying that the sketch was working so well and now isn't. And I don't know the reason.
If somebody on this forum would test the program instead of just discussing it, I might find out why it doesn't always work. It is like a doctor who will just discuss your symptoms without sending you for tests at the hospital.

Hi, @petercl14

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you post some images of your project?
So we can see your component layout.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

A post was split to a new topic: External power supply for servos

This is forum for discussing, not a paid code testing service. If someone is asking more information about your setup, there is usually reason for it.

Name indicates 35kg servo, they are generally quite hungry. I have doubts your 800mA PSU is sufficient to reliably run that servo.

Program works OK

Thanks for testing it Jim. Also working ok now for me. The problem was a bad circuit connection. Always a problem with electronics and often very difficult to find.
Also my previous supposition that a servo motor had to always start from its home position was wrong. It can start from any position as was strongly pointed out to me on this forum. Again there was a bad wiring connection.
A 800ma PSU is quite satisfactory to run the servo. No problem in that regard.

Glad you found the problem(s) and have it working.
Have a nice day

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