Arduino Uno Servomotor won't move

Hi, I'm new to Arduino and I'm trying to move a servomotor attached to a gear that has a wire with 3 pins. I have the middle pin connected to 9 on the Arduino board and I know board works because the lights blink every time i upload the code. However, the servomotor never works. Do you think it's because I have 3 pins for the Servo wire or what? One pin is in 8, one in 9, and one in 10. This is my code:

#include <Servo.h>
Servo servo1;
int servoPin = 9;

void setup(){
  servo1.attach(servoPin);
}

void loop(){
  servo1.write(0);
  servo1.write(180);
}

Hello @fyi05 !
Welcome to the Forum!

Usually it´s necessary to provide some more details on what you´re doing (for example, which servo you´re talking about, what arduino board do you have and how you´re powering you project). But, as you told you´re new to Arduino and this is your first post, there are some tips that can be already shared.

Presuming you have a SG90 microservo, it´s pins are +,- and data. Arduino is not a power provider, so ports 8 and 10 can´t be used as + and - even if you had set them to "output" (which you didn´t). Each of those pins can deal with a maximum current of 40ma (presuming Arduino Uno), while your servo needs 100-250mA to move.

So, if you have this SG90, connect red wire to Arduino +5V, black or brown wire to GND and orange wire to pin 9 to set up your hardware.

At your code, I suggest giving some time between two movements of the servo. The servo takes some microsseconds to move itself. So if you do this:

void loop(){
  servo1.write(0);
  servo1.write(180);
}

You probably won´t see any movement at all. Try this instead as a test:

void loop(){
  servo1.write(0);
  delay(1000);
  servo1.write(180);
}

Have fun! :upside_down_face:

A gear with wires? Never heard of.
Learn the difference between a servo motor and a servo.
Post schematics! No guesses will cover all reasons for failure. Links to the datasheets of the servo thing.

Still won't see movement. It's a loop. The two positions requested happen us apart when the loop iterates.
Put in a second delay, after the servo.write(180). Maybe delay(2000), so you can tell the difference.

1 Like

You need the second delay because the way that it is it goes to 0 then waits a second then tries to go to 180, but right away is told to go to 0 when loop() loops. So it will never move from 0.

Try:

void loop(){
  servo1.write(0);
  delay(1000);
  servo1.write(180);
  delay(1000);
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.