Servos being weird

I have a servo connected to my Arduino Uno. It is connected via digital pin 9, the 3.3v socket, and GND. Here is my code:

#include <Servo.h> 
 
Servo myservo;
  
void setup() 
{ 
  myservo.attach(9);
} 
 
void loop() 
{ 
  myservo.write(180);                  
  delay(15);                  
}

The servo moves between 0 and 180 constantly. It should stay at 180, but it gets there, and immediately starts going back to 0. It does this continuously. If I change the 180 to, say, 50, it does the same thing, but moves to 50 instead and then back to 0 and so forth. I've tried swapping the servo with 5 others, and all do the same thing. I've also tried using several different pins, and they all do the same thing. I'm beginning to wonder if something on the arduino is fried.
Does anyone know what the problem could be? And how to fix it? It's extremely frustrating. :frowning:

I have never seen a servo that was designed to work on 3.3vdc power. Are you sure that is the voltage you should use? Most servos are rated to use like 4.5 to 6vdc. Your uno board has a +5vdc pin you can use if that is the case. Keep in mind that while testing or playing with a servo one can usually power it from the board, if you are going to use more then one or if they are under heavy load or of large size one should really use an external regulated +5vdc power supply to power them and allow one amp per servo when selecting the external power supply.

Lefty

I only need the one servo to work for what I'm building. I've tried it in the 5V pin, and it works when it runs off batteries, but when connected to the usb power, something is going wrong. Windows randomly makes the device disconnected/connected sound and occasionally says the device cannot be recognised when I go to upload code to the arduino. :-/

I only need the one servo to work for what I'm building. I've tried it in the 5V pin, and it works when it runs off batteries, but when connected to the usb power, something is going wrong. Windows randomly makes the device disconnected/connected sound and occasionally says the device cannot be recognised when I go to upload code to the arduino.

The USB connection on the uno board has a 500ma thermofuse, so that fact that windows is disconnecting and reconnecting indicates that your servo is drawing over the 500ma limit of the fuse and USB specifications for power. The external power connector allows for a little more current, but still less then one amp. So your choices is to either continue to use external power either via batteries or a 8-12volt DC 1 amp wall wart type power module.

Lefty

You can NOT use the 3.3V pin to power a servo. The specs for the 3.3v is "DC Current for 3.3V Pin - 50 mA" which is way less than what you need. A guideline for RC servo motors are 1A (1000mA) pr. servo.

The Uno board that the OP stated to own can supply more then 50ma of 3.3vdc current due to it's on-board 3.3v regulator vs the older boards that used the internal 3.3v regulator inside the FTDI chip which does have a 50ma limit. Either way 3.3v is the wrong voltage to power a standard rc servo.

Lefty

The Uno board that the OP stated to own can supply more then 50ma of 3.3vdc current due to it's on-board 3.3v regulator vs the older boards that used the internal 3.3v regulator inside the FTDI chip which does have a 50ma limit. Either way 3.3v is the wrong voltage to power a standard rc servo.

Lefty

The documentation on the Uno board is wrong then, because the page http://arduino.cc/en/Main/ArduinoBoardUno says 3.3V is only 50mA current.

A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.

The documentation on the Uno board is wrong then

Yes, that is an error. See the schematic showing a standalone 3.3v regulator. I don't own a Uno board, but the issue has been discussed here and most feel one could draw up to 100ma of 3.3v voltage if desired. However this brings up a high compatibility problem that could damage older boards. If a manufacture designed arduino shield type board that utilized more then 50ma but less then 100ma of 3.3v power then it would work on the new Uno and mega2650 boards but most likely damage the FTDI chip used on most older arduino boards. So maybe that's why they listed 50ma limit for 3.3v power on the Uno, not because the Uno board can't supply more then 50ma?

Lefty