Servos freeze after a few seconds

So I have tried lots of things, the servos have external power supply and breadboard and arduino Uno share same 5V and GND in common. I have tried powering through USB, it fails, through wall adapter and barrel jack it fails, I have tried with one servo it fails, 4xAA battery holder, it fails, and recently bought a 9v, hasn't arrived though. I honestly, followed rachel debarros tutorial because I was so desperate I was doing something wrong, my coding and everything else is the same and they still do that. So the servos work for a few seconds and they just freeze in whatever position they're in, if I unplug the power supply and put it again they all reset and work again until freezing.

Also here's my code (exact copy of the rachel de barros video):

#include <Servo.h>

int xPin = A0;
int yPin = A1;

int xVal;
int yVal;

int xServoPin = 9;
int yServoPin = 10;

int xServoPos;
int yServoPos;

Servo xServo;
Servo yServo;

void setup() {
 pinMode(xPin, INPUT);
 pinMode(yPin, INPUT);

 xServo.attach(xServoPin);
 yServo.attach(yServoPin);
}

void loop() {
  xVal = analogRead(xPin);
  yVal = analogRead(yPin);

  xServoPos = map(xVal, 0, 1023, 0, 180);
  yServoPos = map(yVal, 0, 1023, 0, 180);

  xServo.write(xServoPos);
  yServo.write(yServoPos);

}

Ditch the breadboard. Breadboards are for temporary experiments with low power logic circuits.

Breadboard tracks cannot support motor currents and will burn, so solder power connections,or use screw terminal connectors, or use servo power distribution PCBs.

Test each servo with the simplest possible circuit (as follows), with an external power supply capable of supplying 1 Ampere per small (SG-90), or 2.5 A per large servo (MG996R).

Thanks for the reply, I tried what you said, nothing happens, sorry

  • Show us good images of your ‘actual’ wiring.

Did you program the Arduino with some servo code? I recommend the "servo sweep" example.

In your next posts, always include part numbers, a wiring diagram and all of the code, formatted using code tags.

Done

I did put the code. The servos were sg90

The one thing you haven't shown us.

Sorry, it's because I've tried many things, that one is a 4xAA battery holder, but I have connected through the barrel jack with wall adapter and it still does the same when powering through USB, it does the same with all the power supplies I have tried.

  • To prove these are what you think they are, use the Serial monitor to print xVal and xVal.

So you're putting 6V into the Arduino's 5V pin.

Ouch.

I tried the barrel jack through the regulator and it didn't work, I thought they weren't getting enough power, I'm so confused

You didn't have a power problem. You had a current problem. By putting 6V on the Arduino's 5V line you attempted to solve a current problem with more voltage. 6V is right on the ATmega328P's Absolute Maximum Rating limit. If your AAs were fresh, you've exceeded that limit. And now even if your Uno is still apparently working, it is damaged, and should always be viewed as suspect.

So I wonder something. If I replace the arduino and start again, cuz I just tested this... I'll need to unplug any power sharing from breadboard to arduino, have the servos receive power from the breadboard rails and independently power the arduino through barrel jack or USB, that's gonna work, right? I tested that but since you said the arduino's damaged maybe I should replace it.

Hi, @rougeyaz
WQelcome to the forum.

PLEASE do this;
Connect ONE servo to your UNO.
Load and run the "Sweep" example for the servo library.
The UNO and your computer USB will be able to power this setup.

Try both servos separately and through the pins you are using in your project code.

The reconfigure your circuit to use the batteries to power the servos and use the "Sweep" code again.

If this works then;
Connect both servos to your circuit with the batteries and run the servo for each.

Then get back to us.

You need to develop your code in stages to find where the problem is.

You are now trouble shooting, which means logical and definite tests of your project.

Tom.... :smiley: :+1: :coffee: :australia:
PS. Disconnect power each time you change your hardware configuration.

What is the wall adapter's output voltage and current?
You can't power a servo from the UNO's 5 volt regulator.

Try using two external power sources, like Post#2.

  1. 5vdc for Arduino in the USB port (or 9vdc to 12vdc in the barrel jack)
  2. (?)vdc for motors, servos, other high-demand devices.

Tie ground potentials together at a central point.