Go Down

Topic: Newbie - HS-311 Servo 360 Continuous Rotation help (Read 4871 times) previous topic - next topic


Code for testing and setup of servos. For my DIY continous rotation servos I send a 1500us position signal to the servo and tweek the pot until the motor stopps turning, then secure the pot in place. the below sail servo might be of interest, but is $$$.


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

This code works great! Just purchased a HS-311 from ServoCity and it had a POT. I had no idea what it did and now I see it simply sets the STOP point depending on the value inputted from the keyboard. Thanks for this.


If you remove the stop, the servo will be 'stopped' by the potentiometer which will probably break.  Or perhaps you will strip some gear.

The pots in the servos I've taken apart and modified do not have stops. The only mechanical stop has been the plastic tab on the output shaft. Soon I plan to just remove the servo plastic stop tab and then do some testing with the servo. 
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


A HITEC HS-311 is rated for 4.8V-6V. As you mentioned that you have provided with 'live' , which I am assuming is 9V, you might have probably damaged the HS-311 circuit. You should connect the 9V to the Vin of the Arduino and 5V of the Arduino to the 'live' of the Servo Motor.


Please guide me i am using Hitec hs 311 but it only goes toward a angle 180 degree whatever the input is and cannot goes to a angle which i desire i have tried different codes but problem is same help me please.
i am using arduino uno r3 board :smiley-sad-blue:


and cannot goes to a angle which i desire

Most continuous rotation servos can not be commanded to stop at an "angle".
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


The problem i mention earlier is now solved can u tell me Is it possible that i can use infrared sensor without using analogue pins of Arduino uno instead can i use pin o and 1 TXd RXD for this purpose?

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!

via Egeo 16
Torino, 10131