Continuous Rotation Servo controlled incrementally with Rotary encoder.

Hey Guys, looking for a bit of help. I want to be able to control a continuous servo incrementally (forward, backwards) with a rotary encoder, as well as a joystick…same motion just different types of control methods…

I’m super new at this, but i somehow managed to piece together a code that seems to work. Problem is when i turn the rotary encoder it feels pretty good in relation with the servo movement, however if i turn it to quick it seems to stutter a bit and get confused for a second. I believe it’s due to the fact that i have no idea what i’m doing and somehow got lucky. I’d like to control the servo with the rotary encoder like it’s 2021 and we somehow merged with robots. I know i may be using the wrong parts for the job. I already have it working with a stepper motor, but i can’t get the feel right. End goal is to use it with a mini linear actuator type device.

Using an SPT6325LV-360 servo:

This Joystick:

Arduino Uno Board

Here’s the code

#include <Servo.h>
#define inputCLK 4
#define inputDT 5
#define potpin A3
Servo myservo;
int val1;
int counter = 1500;
int currentStateCLK;
int previousStateCLK;

void setup() {
  pinMode (inputCLK, INPUT);
  pinMode (inputDT, INPUT);
  Serial.begin (9600);
  previousStateCLK = digitalRead(inputCLK);


void loop() {
  counter = 1500;
  val1 = analogRead(potpin);
  val1 = map(val1, 0, 1023, 1000, 2000);
    currentStateCLK = digitalRead(inputCLK);
    if (currentStateCLK != previousStateCLK) {
      if (digitalRead(inputDT) != currentStateCLK) {
        counter --;
        if (counter = 2000) {
          counter = 2000;

      } else {
        counter ++;
        if (counter = 1000) {
          counter = 1000;




    previousStateCLK = currentStateCLK;


I feel like i’m a million computer clickity clacks away from solving this issue. If i spend a month on this my girlfriend will probably break up with me…Please help!

You cannot control the position of a continuous servo, only the rotation speed. 90 degrees or 1472 microseconds is standstill, the further you move toward 1000 for one direction or 2000 the other, the faster it rotates. No way to tell what position.
Here’s a test sketch:

 Try this test sketch with the Servo library to see how your
 servo responds to different settings, type a position
 (0 to 180) or if you type a number greater than 180 it will be
 interpreted as microseconds(544 to 2400), in the top of serial
 monitor and hit [ENTER], start at 90 (or 1472) and work your
 way toward zero (544) 5 degrees (or 50 micros) at a time, then
 toward 180 (2400). 
#include <Servo.h>
Servo servo;

void setup() {
  // initialize serial:
  Serial.begin(9600); //set serial monitor baud rate to match

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int pos = Serial.parseInt();
    pos = constrain(pos, 0, 2400);
void prntIt()
  Serial.print("  degrees = "); 
  Serial.print("microseconds =  ");

I appreciate the response. I am aware of the lack of positioning increments. I’m not looking to keep track of the position of the servo, hence the use of microseconds. Just looking to refine that code to make the movement a bit smoother than what I have now. It might be the best I can get and I’m fine with that. But was just looking for a way to refine the code to make the motion smoother and more Intuitive. I appreciate any advice given.