The Hitech HS785HB is a 3.5 turns RC servo, typically used as a Sail Winch in RC boats.
Controlling this servo is a bit tricky since it responds differently than other standard RC servos. I had to develop a simple program to study and control this servo. The sample program that will help figure out the PWM required to drive the servo for specific end point angles. It is designed to control two servos if desired, and may be used with any other RC servos as well.
On the PC side, use a Serial Terminal program like the HyperTerminal etc. so that the key strokes are sent immediately to the Arduino. The Arduino's Serial Monitor does not send the key strokes until you click the SEND button.
Turn off NUMLOCK and use the keys on the NumPad to control the servos.
The program is configured to use 4800 baud, so set your terminal program to 4800 baud, and no handshake.
// SweepByNumPad by Umesh Ghodke, K6VUG
// This example code is in the public domain.
// Author assumes no responsibility whatsoever.
#include <Servo.h>
#define PWM1_MIN 700
#define PWM1_MID 1500
#define PWM1_MAX 2300
#define PWM2_MIN 700
#define PWM2_MID 1500
#define PWM2_MAX 2300
#define PWM_STEP 1
Servo servo1, servo2; // create servo objects to control servos
int pwm1 = 1500; // global stores value of PWM in microseconds
int pwm2 = 1500; // global stores value of PWM in microseconds
char inByte; // Byte input from command prompt
void setup()
{
// initialize servo 1
servo1.attach(6, PWM1_MIN, PWM1_MAX); // attaches the servo on pin 9 to the servo object
servo1.writeMicroseconds(pwm1); // set servo to mid-point
// initialize servo 2
servo2.attach(9, PWM2_MIN, PWM2_MAX); // attaches the servo on pin 9 to the servo object
servo2.writeMicroseconds(pwm2); // set servo to mid-point
// initialize serial port
Serial.begin(4800);
Serial.println("SweepByNumPad -- Ready");
Serial.flush();
}
void loop()
{
// Input serial information:
if (Serial.available() > 0){
inByte = Serial.read();
// use numpad keys, use ASCII values in decimal format
// "2" = 32H (50D)
if ((inByte == 50)) {
if (pwm1 > PWM1_MIN) pwm1 -= PWM_STEP;
moveServo1();
}
// "8" = 38H (56D)
else if ((inByte == 56)) {
if (pwm1 < PWM1_MAX) pwm1 += PWM_STEP;
moveServo1();
}
// "4" = 34H (52D)
else if ((inByte == 52)) {
if (pwm2 > PWM2_MIN) pwm2 -= PWM_STEP;
moveServo2();
}
// "6" = 36H (54D)
else if ((inByte == 54)) {
if (pwm2 < PWM2_MAX) pwm2 += PWM_STEP;
moveServo2();
}
// "5" = 35H (53D)
else if ((inByte == 53)) {
if (pwm1 != PWM1_MID) pwm1 = PWM1_MID;
moveServo1();
if (pwm2 != PWM2_MID) pwm2 = PWM2_MID;
moveServo2();
}
// ignore the rest, just echo the byte back
else {
Serial.println(inByte, DEC);
}
inByte = 0;
}
}
// helper function: set servo1 pwm
void moveServo1() {
servo1.writeMicroseconds(pwm1);
Serial.print("Servo1 - ");
Serial.println(pwm1);
}
// helper function: set servo2 pwm
void moveServo2() {
servo2.writeMicroseconds(pwm2);
Serial.print("Servo2 - ");
Serial.println(pwm2);
}
Increase the value of PWM_STEP a little, for faster motion.
Once you get the hang of it, you can modify the program to include other keystrokes and other actions.
Enjoy!