Problem driving my servo

Hello everyone,

I’m stuck and I don’t have a clue why and I was hoping that someone could tell me why. BTW I’m a real beginner. I bought a Arduino YUN and I also bought a Adafruit MotorShield V2 to drive my motors. Right now I feed my arduino with a small battery pack and the motorshield is connected to a 9.6v battery. I have on regular motor on it and this one works good, but my servo isn’t. As soon as my arduino is booting I hear the servo growling and it never stops. No commands I send works on the servo, I do hear him try to do something when I try to sent it to the left but it doesn’t move. It’s like if it was stuck and couldn’t move.

I really hope that someone can enlighten me on this. Cause I’m raging on that project.
I’m adding my code so If anyone can tell me if the problem is the code.

#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#include <Bridge.h>
#include <Console.h>
#include <Wire.h>
#include <Servo.h>
#include <YunServer.h>
#include <YunClient.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *rearWheels = AFMS.getMotor(1);
// Declaring the servo that controls the webcam
Servo servo1;

// The pin that the LED is attached to
const int ledPin = 13;

// We open the socket 5678 to communicate.
YunServer server(5555);

void setup() {
  Serial.begin(9600);

  // Attach the LED to pin 13 as output
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);

  // Bridge startup
  Bridge.begin();

  // Create with the default frequency 1.6KHz
  AFMS.begin();

  //Front Wheels initialization
  servo1.attach(9);
  servo1.write(90);

  // Rear Wheels initialization
  rearWheels->setSpeed(150);
  rearWheels->run(FORWARD);
  rearWheels->run(RELEASE);

  server.listenOnLocalhost();
  server.begin();
}

void loop() {
  YunClient client = server.accept();

  // There is a new client
    client.setTimeout(5);

    String command = "none";
    String _direction = "";
    int _speed = 0;

    digitalWrite(ledPin, HIGH);

    do {
      if (client.available() > 0) {
        command = client.readString();
        Serial.print("Read: ");
        Serial.println(command.substring(0, 1));
        Serial.print("Length: ");
        Serial.println(command.length());

        _direction = command.substring(0, 1);
        _speed = command.substring(1, 3).toInt();

        Serial.println(_direction);
        Serial.println(_speed);
        if (_direction.equals("s")) {
          Serial.println("Stopping");
          servo1.writeMicroseconds(1500);
          rearWheels->run(RELEASE);
          delay(1000);
        } else if (_direction.equals("l")) {
          Serial.println("Turning Left");
          servo1.writeMicroseconds(1000);
          delay(1000);
        } else if (_direction.equals("r")) {
          Serial.println("Turning Right");
          servo1.writeMicroseconds(2000);
          delay(1000);
        } else if (_direction.equals("f")) {
          rearWheels->setSpeed(_speed);
          rearWheels->run(FORWARD);
        } else if (_direction.equals("b")) {
          rearWheels->setSpeed(_speed);
          rearWheels->run(BACKWARD);
        }

      }
    } while (!command.substring(0, 4).equals("stop"));
    Serial.println("Out of loop");
  }
  Serial.println("Quitting");
  digitalWrite(ledPin, LOW);
  if (servo1.attached()) {
    servo1.writeMicroseconds(1500);
    delay(1000);
    servo1.detach();
    client.stop();
  }

}

How is the servo connected?

Have you tried the servo on a different I/O pin?

Have you tried writing a very short code with nothing but a servo in it ? Try it without any motor shield - but make sure to give the servo its own power supply with the servo GND connected to the Arduino GND.

...R

I’ve been doing some test on that servo, model : TowerPro MG995. So here goes, on my shield if I connect the brown cable which is the - my arduino reset and never boots. I don’t even see the wifi part of the arduino and the bright led, the USB one, never go up. But if I reverse the cables so the orange, pwn cable, go on the left everything work except the stupid servo. All I her is a growling sound and it moves really slowly.

Could it be that the servo is defective ??? I’m so confused right now.

Thank you for the help guys.

AllSystemGO:
So here goes, on my shield if I connect the brown cable which is the - my arduino reset and never boots. I … But if I reverse the cables so the orange, pwn cable, go on the left

Verbal descriptions of wiring are too easy to misunderstand. Make a pencil drawing of the connections and post a photo of the drawing.

Are you trying the servo without the motorshield ?

…R

Robin2: Make a pencil drawing of the connections and post a photo of the drawing.

And a good clear picture of your actual setup and connections can be very helpful!

Ok let me take some picture and I'll post them, would a video on youtube be a bit more helpfull too?

AllSystemGO: Ok let me take some picture and I'll post them, would a video on youtube be a bit more helpfull too?

@AllSystemGO, actually, you sketching by pencil will be the most help. This is actually a debugging technique. If it goes as usual, you'll be doing your pencil sketch - the suddenly go, "That's not right". And you will have debugged it yourself.

In the worst case, we'll say - you might have read this wrong or that. In a few rare case, we have found the documentation in error.

TIA Jesse