Controlling the parallax standard servo

Hi there, i’m having some issues controlling the parallax standard servo with my arduino uno.

The servo is connected to the +5v with red, Gnd with black, and pin#3 with white on the arduino. I am using supplied code by the parallax guys, and it doesn’t work. Yet when everything else is connected, and i disconnect/reconnect the +5v cable, the servo turns about 10° clockwise, so obviously the servo works. Does anyone have an inclination as to what my issue is? Code used is below:

#include <Servo.h> // Use Servo library, included with IDE

Servo myServo; // Create Servo object to control the servo

void setup() {
myServo.attach(3); // Servo is connected to digital pin 9
}

void loop() {
myServo.write(180); // Rotate servo counter clockwise
delay(2000); // Wait 2 seconds
myServo.write(0); // Rotate servo clockwise
delay(2000);
myServo.write(90); // Rotate servo to center
delay(2000);
}

Thanks!

I’ve been asking a lot of questions here on the forum, so it’s probably time I tried to answer someone else’s questions :slight_smile:

I haven’t got my Uno in front of me to try this, but the code looks fine to me from what I can see so it may be a hardware set up issue. Could you confirm the white signal cable is connected to pin 3 and not to pin 9?
(The code says the servo should be connected to pin 3 but the comment says pin 9).

If it’s definitely connected up correctly, I would try using the “sweep” sketch example that comes with the arduino IDE. That sketch uses pin 9 for the PWM signal.

Yes it is hooked up to the right pin, sorry I forgot to change the comment code.

I'll try sweep next, thanks!

Tried sweep, nothing happened. Unsure of where to go from here

The sweep example is pretty much definitive working code, so if that’s not working I can only assume you have some sort of hardware issue.
I’m sure you’ve already done this, but I would double check all the connections again. In fact, as it’s only 3 cables, I would actually pull them all out and set this up from scratch again just to be sure.

I’m not sure if this is the same servo you’re using, but going by the picture on this link:-

  • The Black cable on the outer connection should go to the ground pin on the Uno board
  • The center red cable is the power. Connect this to the 5v pin on the Uno board
  • The white cable is the signal, and should be plugged into pin 9

Rather than using Parallax’s code, stick to “sweep” for the moment. I’m also assuming that the only power source you have is the USB connected to the Uno board, there are no other components connected (LEDs etc…), there is no load on the servo and you’re using the Uno board directly and not a breadboard in anyway?

So it should look like my attached picture.

If it still doesn’t work after this, I can only assume something’s wrong with the servo, the Uno board/microprocessor or the servo has a voltage requirement above 5V (unlikely). The datasheet or website you purchased this from should tell you this.

Thanks, Bobu. Yup, all hooked up directly to the Uno, and the Uno is being driven by USB.

The data sheet has spec between 4 to 6volts input, so that shouldn't be a problem. Guess it's time to try another servo? I don't think the microcontroller is screwed up.

As a side note, is there a good way to test my PWM out pins to make sure they work?

The only way I can think of to test those pins to power some LEDs with them (this won't test any PWM functions obviously, but it will check if the pins work).

There's the standard LED blink example sketch you can use and then modify in order to test the specific pins Don't forget to add a resistor so the LED doesn't burn out.

Note that some servos draw too much current to be powered directly from the arduino 5V pin. The parallax has a note also on this issue:

Note: Servo current draw can spike while under load. Be sure that your application's power supply and voltage regulator is prepared to supply adequate current for all servos used. Do not try to power this servo directly from a BASIC Stamp module's Vdd or Vin pins; do not connect the servo's Vss line directly to the BASIC Stamp module's Vss pin.

Lefty

Tried powering it from a 9V battery... then from two 9V batteries in series.. (probably blew it at that point) to no avail.

retrolefty: Note that some servos draw too much current to be powered directly from the arduino 5V pin. The parallax has a note also on this issue:

Note: Servo current draw can spike while under load. Be sure that your application's power supply and voltage regulator is prepared to supply adequate current for all servos used. Do not try to power this servo directly from a BASIC Stamp module's Vdd or Vin pins; do not connect the servo's Vss line directly to the BASIC Stamp module's Vss pin.

Lefty

mHo2: Thanks, Bobu. Yup, all hooked up directly to the Uno, and the Uno is being driven by USB.

The data sheet has spec between 4 to 6volts input, so that shouldn't be a problem. Guess it's time to try another servo? I don't think the microcontroller is screwed up.

Even 9 vdc can damage a servo, they are usually rate for 4.5 to 6.0 vdc. But your drawing shows you powering the servo from the shields 5V pin so what the voltage you applied at the external power connector has no direct barring.

Lefty

Tried powering it from a 9V battery... then from two 9V batteries in series.. (probably blew it at that point) to no avail.

Yep, that's probably what's happened. The servo was rated for 6V max, so if you connected it directly to a 9V supply, it probably damaged it in someway. If that didn't do it then it more than likely would have gotten damaged when 2x 9V in series (as that would come to 18V).

If you power it from something higher than what it's rated for, you'll need to use a regulator to bring the voltage down.

@Bobu - Nah it wasn't working with the 5VDC before I tried the 9VDC or 18.. So it was most likely screwed up before hand.

@Lefty - I had hooked up the 9VDC to the servo it self, not the arduino

mHo2: @Bobu - Nah it wasn't working with the 5VDC before I tried the 9VDC or 18.. So it was most likely screwed up before hand.

@Lefty - I had hooked up the 9VDC to the servo it self, not the arduino

I think your servo was just drawing too much current for your 9vdc battery to power both the board and servo via it's 5vdc bus, that would not have damaged the servo, but it just would drag down the +5vdc power such that the board and servo could not work. However when you then decided to apply 9vdc (and then 18vdc) directly to the servo then you probably did cause that damage. So bottom line you did not have a bad servo to begin with just a bad power plan, and you then proceeded with an even worst and damaging power plan. You are going to have to learn about current not just voltage as you work with arduino projects. So live and learn. ;)

Lefty

Connect the servo's black and red wires to a separate 6V battery (4 1.5V cells). Connect a wire between GND pin on the Arduino and the black wire.

Hello there,

I know its been quite a while but the reason I'm replying is because I had the same problem as you some minutes ago. The solution to it was to download the arduino software version 0020 in order to make the library work as it should (a lot of people have been messing with the library like in this topic http://forum.arduino.cc/index.php?topic=117879.0 ) The change on the "Servo.h" file causes the "myServo.writeMicroseconds();" to malfunction.

I hope these helps for people that are still having problems with the servo control.

pd: you can download the old vertsion from here http://arduino.cc/en/Main/OldSoftwareReleases

Couple of points ...

There is rarely any value in reopening a very old Thread. Most Threads are dead within a few weeks.

I am using Arduino IDE v1.0.5 (and before that 1.0.4) and I have never had a problem with servo.writeMicroseconds().

As far as I can see the problem of the person who started this Thread was caused by an inadequate servo power supply. Unfortunately a great many newcomers don't realize the need to have a separate power supply for servos or motors; don't understand the difference between amps and volts and don't understand the limitations of small batteries.

A big part of the problem is that powering a servo from the Arduino 5v pin (and drawing too much power) can cause symptoms that appear to be software problems even though the software is perfectly fine. And, again, newcomers often don't have the experience to recognize this.

...R

Thank you for the retro,

So do I open a new one? I really dont care much about the points, I just came here because the symptoms of my problem took me to this site as I was trying to run my Parallax Standard Servo. After doing the changes mentioned in my previous post I was able to upload and run a PID control over it and power was not a problem. The servo controlled a gas valve succesfully.

I will look forward for your response and thank you for taking the time of explaining me the dynamics of the forum.

jlangulo: So do I open a new one?

Yes, its usually better to open a new Thread than to reopen a very old one. Sometimes it may be useful to include a link back to a relevant older Thread.

...R