Go Down

Topic: Stumped on my first servo motor project (Read 602 times) previous topic - next topic

Sniipe

So I followed this guide on youtube:
http://www.youtube.com/watch?v=ZIQKf98cAMk

The problem I'm seeing is that instead of going from 10degrees to 170degrees at the specified time I get:
The motor jerks every second even though I said every 10 seconds.  It jerks forward the whole time until its reached its limits... then it does nothing else. 

The motor is a "TowerPro MG995"
According to this spec: http://robotbase.en.alibaba.com/product/461190134-211878901/Tower_Pro_MG995_Servo_Motor.html it should work fine with 5volts.

zoomkat

Simple servo test code. Also, most standard size servos won't power well from an arduino. They usually need a seperate power supply.

Code: [Select]

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  }
}

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Sniipe

You were right Zoomkat.  I hooked up an external power supply and it worked.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy