Servo has a twitch every loop - Hitec HS-5475HB

Hey guys,

Could someone give me an idea for what I could try to get rid of this twitch? Every loop, my servo just twitches a bit - I'm not sure why. I'm just trying to test an LCD right now... so I'm not sure why the servo has a tick to it.

Here's the code I'm using:

// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.


#include <Servo.h> 
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created 

int pos = 90;    // variable to store the servo position 

SoftwareSerial LCD(NOT_A_PIN, 4);


void setup() 
{ 
  myservo.attach(A1);  // attaches the servo on pin 9 to the servo object 
  LCD.begin(9600);
   
} 


void loop() 
{ 
  LCD.write(12);
  LCD.write(13);
  LCD.write(9);
  LCD.write(9);
  LCD.print("Progress!");
  LCD.end();
 delay(2000);
}

where is the servo code?

Show us a schematic of your setup.

duki:
Hey guys,

Could someone give me an idea for what I could try to get rid of this twitch? Every loop, my servo just twitches a bit - I'm not sure why. I'm just trying to test an LCD right now... so I'm not sure why the servo has a tick to it.

Perhaps because you are powering the Servo from the same supply as the LCD? Perhaps
because there is some interference getting to the servo control line?

We need to see your circuit, not your code for this kind of problem.

MarkT:

duki:
Hey guys,

Could someone give me an idea for what I could try to get rid of this twitch? Every loop, my servo just twitches a bit - I'm not sure why. I'm just trying to test an LCD right now... so I'm not sure why the servo has a tick to it.

Perhaps because you are powering the Servo from the same supply as the LCD? Perhaps
because there is some interference getting to the servo control line?

We need to see your circuit, not your code for this kind of problem.

Sorry, I'm not sure of any free software to show the circuit. I'll try my best to describe it though. I just have USB going to the board for now (have a 12v battery that powers everything when it's not hooked into my computer). I have GND going to a breadboard and Pwr also. Then, I just have the signal cables to their specified pins.

GND going to a breadboard and Pwr also

Is "Pwr" from the Arduino?

LarryD:

GND going to a breadboard and Pwr also

Is "Pwr" from the Arduino?

Yes, both Gnd and Pwr are from the Arduino into the breadboard.

Simple servo test code that you can send a command position to your servo, then monitor for twitching.

// 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, 500, 2500);  //the pin for the servo control, and range if desired
  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
  } 
}

Yes, both Gnd and Pwr are from the Arduino into the breadboard.

Are you able to power the Servo motor from a separate power supply to see what happens?