Servo doesn't work

Hi,

I tried the connections and the code given as per the servo library and the servo (SG 90 Tower Pro Micro Servo Motor) didn't work. I believe it should at least rotate on no load condition without an external supply.

I also tried powering the arduino mega with an external power supply (12V, 5A). I connected the power line of the servo to the Vin. It still doesn't work.

Any clue as to what I can do to get the servo working?

Thank You!

Any clue as to what I can do to get the servo working?

Post a schematic. Post the code you are actually using. Post a link to the servo.

The link to the servo I am using:

Code:

#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);  // attaches the servo on pin 9 to the servo object
  myservo.write(0);
  delay(2000);
}

void loop() {
  
    myservo.write(90);              // tell servo to go to position in variable 'pos'
    delay(1000);                       // waits 15ms for the servo to reach the position

    myservo.write(0);              // tell servo to go to position in variable 'pos'
    delay(1000);                       // waits 15ms for the servo to reach the position
  
}

The schematic is the basic one that is used to run the example in the servo library. When that didn't work, I switched the power line from the 5V to the Vin pin after connecting an external power supply to the Arduino power port.

Schematic
Image as in https://www.arduino.cc/en/Tutorial/Sweep

sorry, I tried attaching the image but it didn't work for some reason.

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 9

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

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 9

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

did i burn it?

Possibly, but unless you have another way of testing the servo or another servo to try with the Arduino it will be difficult to find out.

Although the sketch as uploaded looks like it should work, try the Servo Sweep example from the IDE and connect the servo signal wire to pin 9, the servo power wire to 5V and servo GND to Arduino GND.

DO NOT use the servo like this for more than a few seconds and make sure not to stall the servo to avoid drawing too much current.

UKHeliBob:
Possibly, but unless you have another way of testing the servo or another servo to try with the Arduino it will be difficult to find out.

Although the sketch as uploaded looks like it should work, try the Servo Sweep example from the IDE and connect the servo signal wire to pin 9, the servo power wire to 5V and servo GND to Arduino GND.

DO NOT use the servo like this for more than a few seconds and make sure not to stall the servo to avoid drawing too much current.

I tried that, Bob. It isn't working. I tried the same even before I used the 12 V supply and it didn't work. It was a servo which was working perfectly fine before that. Not sure what happened there.

Do you have a second servo or another way to test it such as a servo tester ?
Do you know anyone who flies RC model aircraft or drives RC cars ?

The link to the servo I am using:

No, it isn't. It is a link to a reseller. We want links to the manufacturer's site.

You might trying to send the servo to a position besides the extreme ends of travel, like 30 and 150.
Try this test sketch:

/*
 Try this test sketch with the Servo library to see how your
 servo responds to different settings, type a position
 (0 to 180) or if you type a number greater than 200 it will be
 interpreted as microseconds(544 to 2400), in the top of serial
 monitor and hit [ENTER], start at 90 (or 1472) and work your
 way toward zero (544) 5 degrees (or 50 micros) at a time, then
 toward 180 (2400). 
*/
#include <Servo.h>
Servo servo;

void setup() {
  // initialize serial:
  Serial.begin(9600); // set serial monitor baud rate to match
                  // set serial monitor line ending to Newline
  servo.write(90);
  servo.attach(3);
  prntIt();
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int pos = Serial.parseInt();
    // look for the newline. That's the end of your sentence:
    if (Serial.read() == '\n') {}
    servo.write(pos);
    prntIt();
  }
}
void prntIt()
{
  Serial.print("  degrees = "); 
  Serial.print(servo.read());
  Serial.print("\t");
  Serial.print("microseconds =  ");
  Serial.println(servo.readMicroseconds());
}