Servo slow response

hello! This is my second post here, as I have magically resolved my first problem by myself.

I have a full rotation servo GWS S03NSTD, I figured out the 'write' values that give me the results I need:

93 is center 0 s CW 180 is CCW 97 is CCW slow 89 is CW slow.

Here is what I need. Upon start of a program the servo is rotating CW at full speed.


What I need to happen is upon a switch press, the servo moves in the opposite direction (CCW).

For some reason however, the servo takes too long to respond, what I mean is say the switch is connected to pin 4 (yes, everything is properly declared), and then I plug the 3V3 jumper into pin 4 (that's my switch), the SMD LED "L" flashes for a sec (while the servo is still spinning CW) then sometimes it (the servo) jolts a few times and only then does the servo start to spin in the opposite direction. The delay is 5 seconds or more.

if (val==HIGH)  
} else

I don't see anything wrong with my code, so I am now completely stumped as why I can't instantly switch the servo from one direction to the next.

Any help is greatly appreciated! Thanks in advance!

A couple suggestions:

The pin may be floating---do you have pullup resistors?

Why are you using 3v3?

You may be experiencing contact bounce. The contacts in the switch may bounce some before settling. Shouldn't be 5 seconds though.

Can the arduino handle the current needed to drive the servo? It may be resetting when changing direction, it probably draws more current then. Especially if there is contact bounce and it is switching direction a lot in a short amount of time. (i think)

Any, or none, of these may be an answer.

Thank you so much! I have determined that the cause of the problem, well my new code has shown it to me:

I have a LED on pin 2, and every time the servo is on, it turns on. Furthermore, I have changed the 3V3 to 5V, seemed to improve stability a lot.

here is the new code.

  val = digitalRead(inPin);  // read input value
  if (val==HIGH)
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin, LOW);

So making pull-up resistors should do the trick? Or what is the best way to prevent pin float?


Sorry for doublepost, but thank you very much! The floating pin was fixed via using a pullup resistor and this took the float away! Not sure if it was an issue, but the pullup resistor did the job!

Glad I could help.
And by the way, the atmega chip has built-in pullups on each pin. Just initialize a pin as an input, then digitalWrite it HIGH, and the internal pullups are enabled.

See, you learn something new every day. So the code to do this would be:

int inPin = 4;

//then in the setup:

pinMode(inPin, INPUT); digitalWrite(inPin, HIGH);

Then that will enable the pullup mode?

That saves me my redundant hardwiring of my pull up switch :). Thanks a bunch!

PS: Where do find all this helpful info? Is there some massive FAQ on this? Thanks again!

Thanks! That completely solved my issue. To recap here was my problem (so that others may learn from this).

My 'slow servo response' was actually the uController resetting itself (probably interference). The solutions for my problem:

use the pullup resistors on digital inputs power servos externally

Thanks! :D