1

I'm using the default Servo library in Arduino. When my Arduino Uno starts up and it attaches the servo the motor will move a good portion of its range. I can't have this happen for my project, I need it to turn and stay in its current position.

Also I have seen this post but if I am reading it correctly its for a different library.

approxiblue
  • 6,982
  • 16
  • 51
  • 59
King
  • 45
  • 1
  • 2
  • 4
  • Welcome to SO, how to help you with only "default Servo library in Arduino"... Please read again ["How do I ask a good question?"](http://stackoverflow.com/help/how-to-ask) and try to provide ["a Minimal, Complete, and Verifiable example"](http://stackoverflow.com/help/mcve). – J. Piquard Nov 30 '16 at 21:26
  • "a good portion of its range"? what does that mean? 20%? 50%? what is its range? will it always move to the same position? this sentence says nothing. – Piglet Dec 01 '16 at 07:40

2 Answers2

4

Why the problem occurs?

RC servos set their position accordingly to width of a pulses sent to them. Usually this width changes in range of ~500 - 2500us, with a frequency of 50Hz. When a servo receives such a signal, it goes to a corresponding position. For example - if it receives pulses 1500us wide, it would go to middle position. When you invoke servo.attach(), Arduino will start sensing pulses of DEFAULT_PULSE_WIDTH which happens to be 1500us.

What can be done about that?

The solution from the linked question applies also to standard Arduino servo library. Find DEFAULT_PULSE_WIDTH and change it's value to 0. If there are no pulses, the servo won't turn. Arduino will start sending signal after first servo.write() call. Remember, that there will be no holding torque until that time.

mactro
  • 518
  • 7
  • 13
  • 1
    @King if you are wondering what is going on in a library just read its source code. In my case its in C:\Program Files (x86)\Arduino\libraries\Servo\ for the given problem. you have the source code and it is up to you to read, understand and if needed modify it. its a computer, your very own, willingless slave. become it's master! – Piglet Dec 01 '16 at 10:17
  • @Piglet which source file would you change, specifically, in your Servo folder? Do you know how many `Servo.cpp` source files are in that folder? – eric Mar 26 '18 at 22:45
  • @neuronet you cannot have more than one `Servo.cpp` in the same folder... and you change the file that contains the particular thing you want to change. I really don't get what you want. please be more specific – Piglet Mar 27 '18 at 18:53
0

Possible cause

When your Arduino Uno starts up two things are going on at the same time

  • Arduino Uno runs it's bootloader and servo pin is in input mode
  • Servo gets power and moves a bit while getting no signal

After bootloader finished your, program starts and call to attach is perfomred.

I could reproduce the effect with my Arduino starter kid and its includes cheap servo.