Arduino and servo problem

Hi all,

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
}

Why do You need to do it?
Don't do that. The setup is not managing.

That's not good.

  1. USB is specified for 0.5 Amps. That is likely not good enough.
  2. Don't pull that kind of current through the Arduino board. The tiny strips are not designed for that. Use a separate power supply for the servo.

Link to the datasheet of that servo please....

It is a RC car I need to make sure the servo (steering) would behave normally under performance drifting which is why rotating quickly is essential.

The servo is a SG90 demands for very little power. Data sheet: SG90 datasheet

Since I only want the servo reading, ie not using Arduino to control the servo, could I split the signal wire, to the servo and Arduino input?

uint32_t pulseWidth;

Hi,
Try this edit.

#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;

Might help.

Tom.. :smiley: :+1: :coffee: :australia:

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...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.