Servo skipping an Arduino code loop

Hello

Im new to the servo world and want to set up a simple machine that has a servo working cyclic movement - left, right, left, right and so on...

for testing, i wrote the simplest code:

void loop() {
  pos=130;
  myservo.write(pos);              
  delay(700);                      
  pos=50;
  myservo.write(pos);              
  delay(700);                   
}

what i get, is this movement:

in sec 9-11 It seems like the motor "skips" one loop (and overshoots while doing so), and than remembers the code and gets back to work.
this happens once for every 20 cycles or so, and my system cant handle this amount of inaccuracy.

any idea why and how to fix it?

Hardware -

  • Arduino Uno 3 original
  • Adafriut motor shield
  • Tower Pro Sg-5010
  • 5v 2amp power source (lithium battery)

That SG-5010 servo draws ~600mA stall current (when starting to move).
Not very wise to power everything (servo/Uno/motor shield) through a <=500mA USB connection.
But I guess you have to stick with the design of the shield.

Did you try on regular USB supply from a PC/laptop, instead of the powerbank.
Did you try slightly longer delays.
Leo..

its the same with delay(1000), and with lasptop/pc its even worse, as their USB is actually about 500ma, and the power bank is most likely at leas 1a.

Ill try to buy and connect the Arduino to a 12v cylinder socket and see what happens...

12volt on the DC socket could overheat the 5volt regulator on the Uno (that powers the servo).
Not sure how to solve this.
The 3-pin servo connector on that shield might be convenient, but is should have had it's own 5/6volt power connector, like on the Adafruit PCA9685 servo breakout boards.
Leo..

How come this isnt written in ALL-CAPS in every servo-arduino guide?!?

Anyway, the shield has a 6v input line, but its for wires and not a plug.

is there a standard way to power the shield through a wall-supply or a usb (and not a battery)?

Ok!!

tore open an extra USB cable, hooked the servo dedicated input that is on the shield to the 5V and GND lines of the extra USB, and connected a regular USB to the Arduino.

THE SERVO WORKS LIKE A CHARM!!!
(even with more advanced code that include a python GUI that controls the servo by serial port)
(In the video you can see the servo moving by 1 degree per mouse click to one direction, zeroing to 90 dergrees, moving to the other direction and zeroing to 90 again - Arduino servo solved! - YouTube)

But still, I would like to run the servos on 6v as they are faster with higher voltage.
Where can I get a STANDARD 6V power source that is NOT batteries? seems like a challenge...

4 x 1.5V AA batteries = " 6V power source that is batteries". Where's the challenge?

Steve

Servos (any motor) should be powered seperately from the Arduino.
e.g. a battery holder with four AA batteries.

Servos don't need a motorshield.

Just connect servo power/ground to a 6volt supply.
And servo signal/ground to the Arduino.

Can use pinstrips, soldered to a proto shield or a piece of stripboard.
Leo..

The problem with batteries is that the system needs to run for many hours at a time, in a continues fassion. Batteries won't cut it... I need something that plugs to a wall and gives out 6v into a 2 wire form.

Is it more reasonable to use a voltage converter on the 12v cylinder plug? Or should I try and find a 6v 2amp supply somewhere on the internet (not so easy to find something reliable)

You can find a 9V-12V AC-DC 1A adaptor and hook it to a down-step DC-DC regulator like xl4015 or something similar. Turn the pot until you get your 6V on the output pins.