Simple Servo Sketch Works on Uno But Not on A-Star

I am trying to get the following servo-sweep sketch to work on an A-Star 32U4:
(For those not wanting to click the link):

// Sweep
// by BARRAGAN  

#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
                // a maximum of eight servo objects can be created 
int pos = 0;    // variable to store the servo position 
void setup() 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
void loop() 
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 

The sketch runs fine on an Arduino Uno.
The sketch will load to the A-Star but when the servo and power are connected the device disappears from the device manager (Win7 Pro) and the servo arm moves back and forth quickly (sort of like a vibration) over a very small range.
The same behavior occurs with Ubuntu, i.e. servo vibration and the device disappearing from the /dev directory.
The same things occur with a second A-Star that I have.
The devices reappear in both Win7 and Ubuntu when power or the servo’s signal wire is disconnected.
I’ve also tried modifying Servo.h (timer1 to timer3) to no avail. I only did this in Win7.
The servo’s signal wire is connected to the upper left pin (9) (next to the usb) and the ground and 5V power are supplied respectively by the second and third pins from the bottom on the right side of the A-Star.
Blink runs fine on both A-Stars.

Thank you in advance.


I am sorry your are having problems with your A-Star 32U4. Can you tell me which A-Star you have? Also, can you tell me the stall current of your servo or provide a link to the servos specifications?

Generally, the regulator of a microcontroller like your A-Star or Arduino Uno is not the best power source for things like servos or motors. I suggest powering your servo from a separate power supply to see if that helps. Please be sure you have a common ground between your micro controller and servo if you use a separate power supply.


Thank you so much for the reply - and solution.
I have the A-Star 32U4 Micro (Item 3101).
I couldn’t find the stall current of the servo but did note these specs:
4.8 - 6.0 V
1.5 - 1.8 kg-cm
0.12/0.1 s/60
The servo came with the ARDX Experimenter’s Kit for Arduino (which comes with an Uno) so maybe it was sized for the Uno.
At any rate, the sketch ran fine on the A-Star when I powered the servo with a separate power supply.
This under-simplifies my design in which I was hoping to power the A-Star directly with a 12V boat battery and have the A-Star step down the voltage to the servo.
But, I’m no longer mystified - and that’s always good. :smiley:
Thanks again for the great tech support.

Hi, Bob.

I am glad you got it working with a separate power supply. To expand on what Derrill said, the regulator on the A-Star 32U4 Micro can only source about 100mA of current through the 5V out pin, while the Arduino Uno R3 can source around 350mA to 1A depending on how it is powered. This is probably why the servo ran off of the 5V output on the Uno and not the A-Star Micro.

If you want to run everything in your setup from a 12V battery, you might consider using one of our step-down regulators to power your servo.