I have a continuous servo motor connected to my Arduino UNO. I want it to react to the Hexadecimal code received by an Infrared remote. I want the motor to rotate once in one direction and then rotate once in the reverse direction and then stop until triggered by the remote again. At the moment, the remote will cause the the motor to rotate once in one way but then it rotates continuously in the reverse direction. Any help would be much appreciated!

#include "IRremote.h"
#include <Servo.h>

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

Servo servoMain;
IRrecv irrecv(receiver);
decode_results results;

void setup()
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn(); // Start the receiver

void loop()
  if (irrecv.decode(&results)) // have we received an IR signal?

    irrecv.resume(); // receive the next value

void translateIR() // takes action based on IR code received

// describing Remote IR codes

  switch (results.value)


    case 551520375: servoMain.write(180); delay(1000); servoMain.write(0);     delay(1000); break;
    default: break;


  delay(500); // Do not get immediate repeat

} //END translateIR

2 Answers 2


Unlike a normal servo motor where the argument of the Arduino's servo.write(angle) method represents a position, a continuous servo motor uses the argument for speed and direction. Most continuous servo motors interpret stop to be approximately 90 degrees. Full, say, reverse as 0 degrees. And full, say, forward as 180 degrees. As stated in the above link:

On a continuous rotation servo, this will set the speed of the servo (with 0 being full-speed in one direction, 180 being full speed in the other, and a value near 90 being no movement).

Also of interest, most continuous servo motors have an adjustment to set the "90 degree position" (full stop). That is to say, servo motor control signals are analog, not digital! It follows that the processor's interpretation of the "90 degree position" may not be the same as the servos' interpretation of the "90 degree position". Hence the ability to adjust the servos' interpretation.

This picture from the parallax servo tutorials web site shows how this is done:

enter image description here

  • Thanks a lot for your help. I wasn't aware about the calibration and I got it working with some minor adjustments to the code as well. Dec 14, 2016 at 23:18

I am posting that may help others in future. I have MG996R Servo Motors, this motor when I opened and inside I didn't find LOCK at main wheel and I assume its 360 degree.

I have similar problem that while testing Robotic Arm, my motor was loosing position and it was rotating 360 degree. I tried all sort of remedies but didn't find the solution.

MY SOLUTION: Connect your Servo with external power 5v supply, even connecting 5V to arduino board with round pin does not solve. once I connected with external power with 5V power my issue was solved and motors were retaining position

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.