Check program

Dear,

I am new to this and a strange phenomenon happens to me when I disconnect the USB from the Arduino Uno.

I have a small program with two HS311 servomotors.

Between these two servos, I programmed three routines that are repeated in a loop.

The problem is that when I deploy it works fine until I disconnect the USB cable. When I take out the USB cable, the program does anything. It seems to be deprogrammed.

Has this happened to you?
Will there be something I am doing wrong?

I would appreciate any suggestions to understand what happens to me.

Thank you.

How are the servo motors powered?

How are you powering the Arduino board when the USB cable isn't connected?

Hello, thanks!

Servos are powered from arduino board

I have Arduino with a 9V power source.

cessariuss:
Will there be something I am doing wrong?

if you were to show us the code, the wiring, the type of Arduino you are using and how things are powered - that would help us help you...

for example if you have a while (!Serial);  // wait for serial port to connect. Needed for native USBline in the setup you might be stuck in an infinite loop when you unplug the USB cable depending on your arduino...

Servos are powered from arduino board

those servos need ~200mA each when moving with no load... that's a lot of power going through your board... if there is a load, you might be in trouble.....

Dear thank you very much for your help.

Attached connection diagram and code.

 // #include <Servo.h>

Servo servo1; // SERVO HORINZONTAL
Servo servo2; // SERVO VERTICAL

int PINSERVO = 6;
int PINSERVO2 = 11;
int PULSOMIN = 800;
int PULSOMAX = 2300;


void setup() {

  servo1.attach(PINSERVO, PULSOMIN, PULSOMAX);
  servo2.attach(PINSERVO2, PULSOMIN, PULSOMAX);
}

void loop() {

  //***********PRIMERA SECUENCIA (BARRIDO) ************************


  servo1.write(60);
  delay(1000);

  servo2.write(90);
  delay(1000);

  servo1.write(120);
  delay(1000);

  servo2.write(95);
  delay(1000);

  servo1.write(60);
  delay(1000);

  servo2.write(100);
  delay(1000);

  servo1.write(120);
  delay(1000);

  servo2.write(105);
  delay(1000);

  servo1.write(60);
  delay(1000);

  servo2.write(110);
  delay(1000);


  delay(3000);

  //***********SEGUNDA SECUENCIA (ALEATORIO)************************



  servo1.write(140);
  servo2.write(110);
  delay(500);
  servo1.write(40);
  servo2.write(90);
  delay(500);
  servo1.write(140);
  servo2.write(120);
  delay(500);
  servo1.write(40);
  servo2.write(90);
  delay(500);


  delay(3000);
  //***********TERCERA SECUENCIA (SIERRA)************************


  servo2.write(90);
  servo1.write(120);
  delay(500);

  servo2.write(110);
  servo1.write(100);
  delay(500);

  servo2.write(90);
  servo1.write(90);
  delay(500);

  servo2.write(110);
  servo1.write(80);
  delay(500);

  servo2.write(90);
  servo1.write(70);
  delay(500);

  servo2.write(110);
  servo1.write(60);
  delay(500);

  servo2.write(90);
  servo1.write(50);
  delay(500);

  servo2.write(110);
  servo1.write(40);
  delay(500);

  delay(3000);



}

.

Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

————————

can you post a picture ? are you sure the grounds are properly connected ?
as mentioned, that's a lot of current going through your Arduino if the servomotors do any work

Thanks a lot for the suggestion. I have corrected the post. :slight_smile:

Checked the connections, they are as shown as in the diagram that I attached.

Should I add an independent power source for servos?

Your image

cessariuss:
Should I add an independent power source for servos?

Check first if the jack power supply is working. What kind of 9V is it ? (The 9V rectangular battery won’t do, is it a 9V DC power supply connected to main ? what power ?)

You can connect both usb and the jack if you have a good Arduino => get stuff printed to Serial

Your power supply is totally inadequate for even one servo, and you can damage the Arduino by trying to use the 5V output.

Use a separate 4xAA battery pack for the servos, and be sure to connect the grounds.

J-M-L:
Your image

Check first if the jack power supply is working. What kind of 9V is it ? (The 9V rectangular battery won’t do, is it a 9V DC power supply connected to main ? what power ?)

You can connect both usb and the jack if you have a good Arduino => get stuff printed to Serial

The power source is 9V DC 650mA and is connected as shown in the diagram, to the 9V input (not usb).

The power source is a 220V AC transformer that lowers the voltage to 9 V DC.

I have also tried powering only with USB. Connected via USB to the PC the program works fine. The fault occurs only when the Arduino is energized with the 9V power source (transformer).

The power source is 9V DC 650mA and is connected as shown in the diagram, to the 9V input (not usb).

As I stated, this is totally inadequate, and you may destroy the Arduino if you continue in this way.

The servo power supply must provide AT LEAST 1 Ampere at 6V per servo. Some servos require 3 Amperes each.

jremington:
Your power supply is totally inadequate for even one servo, and you can damage the Arduino by trying to use the 5V output.

Use a separate 4xAA battery pack for the servos, and be sure to connect the grounds.

Thanks for the info.
I'll try how you tell me.

jremington:
As I stated, this is totally inadequate, and you may destroy the Arduino if you continue in this way.

The servo power supply must provide AT LEAST 1 Ampere at 6V per servo. Some servos require 3 Amperes each.

ok then everything points to energy.

Thank you very much for your good contributions!

The HS311 Stall Current Draw is 800 mA, so your power supply should be able to supply 2 Amperes, minimum.

Do not run this current through a breadboard, the tracks will burn. Solder the servo connections to the power supply leads.