UKHeliBob:
Although nor recommended I would expect the code posted to cause the servo to move between 0 and 90 degrees when powered from the Arduino 5V pin with servo GND connected to Arduino GND and the servo signal wire connected to Arduino pin 3, although the comment says pin 9Which pin is the servo signal wire connected to ?
However, from your further description it may be that you have connected the servo to the 12V supply which has probably damaged the servo. Try the 5V connection again and report back what happens. Add some Serial.print()s to the code so that you can tell that it is running.
I note that the code and comments don't match which does not matter but is very sloppy.
Thanks for the reply. I was quickly trying to figure if the pins I had earlier attached to weren't working. The servo is wired according to the code and not the comments (so pin 3).
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
void setup() {
myservo.attach(3);
myservo.write(0);
delay(2000);
Serial.begin(9600);
}
void loop() {
myservo.write(90);
Serial.println ("fwd");
delay(1000);
myservo.write(0);
Serial.println ("bwd");
delay(1000);
}
Updated code.
Before I connected the external supply, I tried working it with the supply that the USB provides. It didn't work then. Then I connected the 12V, it didn't work even then (did i burn it?).
Now i tried the 5V, still doesn't work.