How to control the rotational direction of a 360 degree servo motor?
Is it a continuous rotation servo or a conventional servo that just happens to rotate through a maximum of 360 degrees ? I suspect that it will be the former
If so then writing a value of between 0 and about 90 will rotate it in one direction and a value of about 90 and 180 will rotate it in the other direction
The speed of rotation in either case is controlled by the value written. At about 90 the servo will stop rotating but you cannot control its position
Which value is clockwise and counter clockwise? and what about the values from 181 to 360?
The direction depends on the servo. Try it and see
181 to 360 are irrelevant if you have a continuous rotation servo. A value of 0 will rotate the servo continuously in one direction at full speed and 180 will rotate it continuously in the other direction at full speed. Other values will rotate it at slower speeds but still continuously through 360 degrees
Please post a link to the servo that you have
The servo is continuous Mg996
Which Arduino are you using? Try this test program written for UNO, Nano or ProMini, connect servo to pin 9:
/*
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
//set serial monitor line ending to Newline
servo.write(90);
servo.attach(9);
prntIt();
}
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();
if(Serial.read() == '\n'){}
pos = constrain(pos, 0, 2400);
servo.write(pos);
prntIt();
}
}
void prntIt()
{
Serial.print(" degrees = ");
Serial.print(servo.read());
Serial.print("\t");
Serial.print("microseconds = ");
Serial.println(servo.readMicroseconds());
}
I am using Arduino Mega 2560.
Try the Servo Sweep example in the IDE. The servo will not sweep from end to end but will change direction and speed instead
You should have said that in your first post. Should work as is.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.