Reputation: 45
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.
Upvotes: 1
Views: 4250
Reputation: 29
Possible cause
When your Arduino Uno starts up two things are going on at the same time
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.
Upvotes: 0
Reputation: 518
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.
Upvotes: 4