Servo power dip

Hi! I’m trying to control a servo (S3003) using an ultra sonic sensor (HC-SR04). When the servo is moving the input signal from the sensor gets very unstable, giving the motor the wrong positions, making it move even more, creating this bad feedback loop. I heard this can happen as the servo draws more current when it moves and that i should put i capacitor over the power to the servo. I tried this using different capacitors (100uF, 470uF, 1000uF) but it doesn’t help. I’m using a bench power supply set to 5V for the servo and the sensor and i’m powering the arduino via USB from my computer. Anyone know what causes this or have any tips on what to try next? I have attached i drawing of the circuit.

Thanks in advance! :slight_smile:

Is there a connection between the external power
supply ground and the Uno ground?

My first troubleshooting step would be to power the servo from a 6V battery pack.
Make sure the servo GND is connected to the arduino GND.
If the problem goes away then the cause is what you already described.

BTW, FYI, it's not called a "power dip", it's called a "power SAG" (opposite of power SURGE)

herbschwarz:
Is there a connection between the external power
supply ground and the Uno ground?

Yes! sorry, forgot to include that in the drawing.

raschemmel:
My first troubleshooting step would be to power the servo from a 6V battery pack.
Make sure the servo GND is connected to the arduino GND.
If the problem goes away then the cause is what you already described.

I have tried powering the servo using the bench power supply set to 6V and powering the sensor with the 5v from the arduino but it did not work. Should this give the same result as using a battery pack?

Is there a conneciton between the servo gnd and arduino GND ?

I would expect a bench supply to have the same result as a battery pack but if you have
nothing else to do you could try a battery for the servo just to confirm it.

Hi! I'm trying to control a servo (S3003)

I couldn't find a current rating for that servo and of course I don't know the current rating for you bench supply, but I'd guess that's not the problem.

Have you tried some simple code that just moves the servo, and/or just moves it to a position and holds it?

The problem might be a logical error in your code, or maybe a "conflict" where reading of the sensor interrupts the servo-control pulses, or the opposite where the servo code interrupts the sensor code.

Where’s the code ?

raschemmel:
Where’s the code ?

#include <Servo.h>

int servoPin = 10;
int triggerPin = 6;
int echoPin = 7;
int servoPos;
int distanceMillimeter = 0;
Servo servoMain;

void setup() {
  servoMain.attach(10);
  pinMode(servoPin, OUTPUT);
  pinMode(triggerPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
  digitalWrite(triggerPin, LOW);
  digitalWrite(echoPin, LOW);
}

void loop() {

  digitalWrite(triggerPin,LOW);
  delayMicroseconds(2);
  digitalWrite(triggerPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin,LOW);
  distanceMillimeter = (pulseIn(echoPin,HIGH) / 27.6233 / 2.0) * 10;
  
  
  servoPos = map(distanceMillimeter, 40, 600, 0, 180);
  if(servoPos < 0){
    servoPos = 0;
  }
  if(servoPos > 180){
    servoPos = 180;
  }
  servoMain.write(servoPos);
  //Serial.println(servoPos);

  

  delay(50);
}

DVDdoug:
I couldn't find a current rating for that servo and of course I don't know the current rating for you bench supply, but I'd guess that's not the problem.

Have you tried some simple code that just moves the servo, and/or just moves it to a position and holds it?

The problem might be a logical error in your code, or maybe a "conflict" where reading of the sensor interrupts the servo-control pulses, or the opposite where the servo code interrupts the sensor code.

Yes, if i move the servo using only code there are no problems.

You don't need the " pinMode(servoPin, OUTPUT);", the servo.attach() sorts out all that for you. I don't know that resetting it yourself will cause problems but I'd take it out.

Steve

slipstick:
You don't need the " pinMode(servoPin, OUTPUT);", the servo.attach() sorts out all that for you. I don't know that resetting it yourself will cause problems but I'd take it out.

Steve

Ok thanks! I tried removing it but it makes no difference.