I am having issue controlling my 25kg servo with a simple joystick. I am using a simple analog joystick to control just the x axis, but the motor seems not really responding to the joystick movements (sometimes it moves randomly after a couple of seconds).
this is my code:
#include <Servo.h>
Servo myServo;
int Joy = A0;
int JoyVal;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myServo.attach(5);
}
void loop() {
// put your main code here, to run repeatedly:
JoyVal = analogRead(Joy);
JoyVal = map(JoyVal, 0, 1023, 0, 180);
Serial.println(JoyVal);
myServo.write(JoyVal);
delay(20);
}
I think I have solved the issue of joystick control. However, it looks like the motor needs a slight input to start working. Also for example if I just set a starting position such as:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myServo.write(60);
myServo.attach(5);
}
The motor doesn't actually rotate to that position. What could be a possibel issue?
Try running the example Sweep program from the IDE. If that doesn't work it's probably a bad servo. If that works but a simple write(60), delay(100), write(120) doesn't then you don't have enough power. What is the current rating of your 5V power supply?
You need a power supply of at least 3.4 (found on a few pages, such as this one).
If you have a cheap power supply from Ebay/Amazon/AliExpress, then you need a power supply of 10A and hope that it can deliver 3.4A.
Is your servo motor a "TD-8125MG" ?
Try to find its stall current. That is current that the power supply should be able to provide.
Even if you do not stall the servo motor, the peak current when it starts moving could be near the stall current.
A breadboard can not be used for those currents. A breadboard can be used for a led or a sensor, and even then they often fail to make good contacts because of the low quality.
This is a common mistake. When buying a servo motor, some think that stronger is better. But for a servo motor, smaller and less current is better. If the servo motor is not strong enough, perhaps that can be solved in a mechanical way.