Go Down

Topic: Servo help (Read 804 times) previous topic - next topic


Hello.  I am trying to drive a Hitec standard HS 311 servo with an Arduino Mega 2560.  I have uploaded many different sketches related to servo control, but there is absolutely no result.  I have tried this code with 3 other servo of the same type. 

I have tried the same procedure with 3 of the exact same servo, with the same result.  I have connected the Mega to a wall outlet while it was connected to the USB port on my laptop.  The wall outlet ad/dc adapter provides a little under 9 volts to the Arudino. 

I have connected the servo directly to the 5V, GND pin and the PWM port 8 on the Arduino.  No result.  I then used a breadboard to run a 6 volt battery pack to the servo, no result. 

I have tried the following servo sketches with no results: all servo examples that are included with the latest version, the software servo sketch, servo sketches from the Arduino Companion phone app, and all servo code in the Arduino Cookbook.  Again, no results.

Please help if you can.


Typical servo wiring with external power supply for the servo. Note the servo power supply and arduino grounds need to be connected. Servo test code bottom.

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() {
  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.print("writing Angle: ");

    readString=""; //empty for next input

Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up