I wrote a program that takes PWM (pulseln) values from a RC radio control, to an Arduino (d1 mini), and through the servo library outputting the same command to a servo, basically using the Arduino as a middle man to pass through PWM signals for a servo, this way I can make actions based on servo positions.
It works perfect however if I am deliberately rotating the servo back and forth quickly for few seconds, the servo would end up stopping abruptly half way and pauses for few seconds before I could rotate again. It is connected with usb from 5V and Ground.
Could the Arduino be having too much information to process and stalled? I woud like to have servo with full control without sluggish performance
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int inputPin = D1; // choose the input pin (for pulseIn signal)
int pulseWidth; // variable for pulse width in microseconds
int servoPin = D2; // choose the output pin (for servo)
void setup() {
// initialize serial communication
myservo.attach(servoPin); // attaches the servo on D2 pin to the servo object
pinMode(inputPin, INPUT); // set the D1 pin as input
}
void loop() {
pulseWidth = pulseIn(inputPin, HIGH); // read the pulse width from the D1 input
int angle = map(pulseWidth, 1000, 2000, 0, 180); // map the pulse width to a servo angle
myservo.write(angle); // set the servo angle to the mapped value
// wait for the servo to move
}
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int inputPin = D1; // choose the input pin (for pulseIn signal)
int pulseWidth; // variable for pulse width in microseconds
int servoPin = D2; // choose the output pin (for servo)
void setup() {
// initialize serial communication
myservo.attach(servoPin); // attaches the servo on D2 pin to the servo object
pinMode(inputPin, INPUT); // set the D1 pin as input
}
void loop() {
pulseWidth = pulseIn(inputPin, HIGH); // read the pulse width from the D1 input
int angle = map(pulseWidth, 1000, 2000, 0, 180); // map the pulse width to a servo angle
myservo.write(angle); // set the servo angle to the mapped value
delay(10),
// wait for the servo to move
}
The delay will give the servo time to actually move before the next command.
Also check if the servo has plastic gears, that model servo is a economy version, and by the looks of the picture in the datasheet;
Found the problem. I was connecting with laptop’s usb power with a generic usb cable before for reading serial monitor and powering up the device. Now I connected with a charging cable and AC adaptor designed for charging phones, the servo worked perfect and did not pause anymore. Either my computer usb port was under power or the usb cable was not capable handling more than 0.5A.
Your USB port is likely protected against users demanding more than 0.5 A, which is different from not being capable of...
As for the spec sheet you pointed to, there's not a single mention of current in the whole document. Sad, really. You're misguided in claiming it's low power, you simply don't know. Those el cheapos range in stall current from 0.5 to 1.5A (those are the extremes I've actually measured). So...