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:
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:
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.
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.