I'm trying to program my continuous servo motor to do the basic function of turning clockwise or counter-clockwise for a certain amount of time. From what I understand, the motor should turn clockwise if I write to it 180, counter-clockwise for 0, and stop for 90. Therefore, a code like the following should turn the motor clockwise:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(180);
}
The problem is when I upload this to the arduino, the motor just makes a clicking noise. I don't think the motor is faulty because when I use the servo sweep example code, it rotates back and forth, but it still makes a clicking noise for a few seconds before it rotates. I've tried using a separate power supply for the motor as well as using the 5V on the arduino. I think my problem is with the code or maybe I'm just not understanding something. Any solutions with an example code would be greatly appreciated.
What does it do if you myservo.write(85) or (95)? Try this test sketch, use microseconds instead of degrees:
/*
Try this test sketch with the Servo library to see how your
continous rotation servo responds to different settings, type
a position (544 to 2400) in the top of serial monitor and hit
[ENTER], start at 1472 (stop position) and work your way
toward zero (544) 50 micros at a time, then toward 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.writeMicroseconds(1472);
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 speed = Serial.parseInt();
// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {}
servo.writeMicroseconds(speed);
prntIt();
}
}
void prntIt()
{
Serial.print("microseconds = ");
Serial.println(servo.readMicroseconds());
Serial.println(" Enter a value between 544 and 2400, then press [ENTER]");
}
I don't think the motor is faulty because when I use the servo sweep example code, it rotates back and forth, but it still makes a clicking noise for a few seconds before it rotates.
This sounds like a broken gear in the servo.
Which model servo?
Did you buy it as a 360 servo or did you do the continuous rotation conversion yourself?
I’m using a kookye mini servo that I got from amazon. I don’t feel like the gear is broken otherwise it wouldn’t spin at all, right? It only seems to work with the example sweep code.
No, the servo can still move. I have used a LOT of servos and when they fail with broken teeth in the geartrain, it can be deceptive. The servo might behave properly until it reaches that one point on the gear where the tooth is broken. It might click a few times skipping over the broken tooth, then grab and move to complete teeth and start rotating normally.
Try this. Run the servo so it moves continuously. Then apply some friction to the output shaft. Not hard enough to stop the servo, but tight enough that you make the motor work a little.
When it gets to the spot where it used to click and then continue rotating, I think that now it will just keep clicking until you let go.
When it runs off the example code, it only ever clicks for about 5 seconds at the beginning. I've tried playing with the delay times in the code and by increasing it from 15 milliseconds to 50, I can get it to rotate in each direction for a longer amount of time. I'm not sure why this is or how the delay affects this. If I try to change the delay to anything more than 100, it doesn't rotate at all, it just makes clicking sounds.