0

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.begin(9600);
 Serial.println("IR Receiver Button Decode");
 irrecv.enableIRIn(); // Start the receiver
 servoMain.attach(10);
}
void loop()
{
 if (irrecv.decode(&results)) // have we received an IR signal?
 {
 translateIR();
 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
RowanP
8696 silver badges21 bronze badges
asked Dec 8, 2016 at 22:56
3
  • You never tell it to stop. I assume that writing op degrees would stop it. Commented Dec 8, 2016 at 23:06
  • Have you checked out linked and related questions? Seems like this question may duplicate some of them. Commented Dec 9, 2016 at 1:32
  • arduino.stackexchange.com/questions/4076/… Commented Dec 9, 2016 at 2:01

2 Answers 2

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

answered Dec 9, 2016 at 12:55
1
  • 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. Commented Dec 14, 2016 at 23:18
1

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

answered Jul 28, 2020 at 6:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.