Servos[movement issue ]

///////////////
// 9-04-2020 //
//           //
///////////////


//#include <Servo.h>
#include <VarSpeedServo.h>


//Servo myServo;
VarSpeedServo myServo1;
VarSpeedServo myServo2;

VarSpeedServo myServo4;



int ServoPin1 = 3;
int ServoPin2 = 5;

int ServoPin4 = 6;

int communication_with_board_2 = 2;

int initial_Servo1 = 94;
int initial_Servo2 = 19;
int initial_Servo4 = 88;

int mydelay = 5;
int mySpeed1 = 5;
int mySpeed2 = 127;


void setup() {
  //Serial.begin(9600);
  pinMode(communication_with_board_2, OUTPUT);
  pinMode(13, OUTPUT);


  myServo1.attach(ServoPin1);
  myServo2.attach(ServoPin2);
  myServo4.attach(ServoPin4);


  myServo1.write(initial_Servo1, mySpeed1);
  myServo2.write(initial_Servo2, mySpeed1);
  myServo4.write(initial_Servo4, mySpeed2);

  digitalWrite(communication_with_board_2, HIGH);
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);

}

void loop() {

  myServo1.write(62, mySpeed1);
  delay(5000);

  myServo1.write(111, mySpeed1);
  delay(5000);

  myServo1.write(94, mySpeed1);
  delay(2000);


  myServo2.write(10, mySpeed1);
  delay(3000);

  myServo2.write(28, mySpeed1);
  delay(3000);

  myServo2.write(19, mySpeed1);
  delay(4000);


  myServo1.write(111, mySpeed1);
  delay(5000);

  myServo2.write(10, mySpeed1);
  delay(4000);


  myServo1.write(94, mySpeed1);
  delay(5000);

  myServo2.write(19, mySpeed1);
  delay(3000);

  myServo1.write(62, mySpeed1);
  delay(5000);

  myServo2.write(10, mySpeed1);
  delay(3000);

  myServo2.write(28, mySpeed1);
  delay(3000);

  myServo2.write(19, mySpeed1);
  delay(3000);

  myServo1.write(94, mySpeed1);
  delay(5000);

  ///////////////////////////
  myServo4.write(50, mySpeed2);
  delay(500);

  myServo4.write(88, mySpeed2);
  delay(500);

  myServo4.write(50, mySpeed2);
  delay(500);

  myServo4.write(88, mySpeed2);
  delay(2500);

  myServo1.write(100, mySpeed1);
  delay(2500);

  myServo1.write(111, mySpeed1);
  delay(2500);

  myServo2.write(10, mySpeed1);
  delay(2000);


  myServo2.write(28, mySpeed1);
  delay(2000);

  myServo2.write(19, mySpeed1);
  delay(2000);

  //////////

  myServo1.write(62, mySpeed1);
  delay(2500);

  myServo1.write(80, mySpeed1);
  delay(2500);

  myServo1.write(94, mySpeed1);
  delay(2500);

  ///////////////

  myServo2.write(10, mySpeed1);
  delay(2000);

  myServo2.write(28, mySpeed1);
  delay(2000);

  myServo2.write(10, mySpeed1);
  delay(2000);

  ////////////////

  myServo4.write(27, mySpeed2);
  delay(1000);

  myServo4.write(88, mySpeed2);
  delay(100);

  myServo4.write(27, mySpeed2);
  delay(250);

  myServo4.write(88, mySpeed2);
  delay(250);



  myServo4.write(27, mySpeed2);
  delay(250);

  myServo4.write(88, mySpeed2);
  delay(250);


  myServo4.write(27, mySpeed2);
  delay(250);

  myServo4.write(88, mySpeed2);
  delay(250);


  myServo4.write(27, mySpeed2);
  delay(250);

  myServo4.write(88, mySpeed2);
  delay(250);

  myServo4.write(27, mySpeed2);
  delay(250);

  myServo4.write(88, mySpeed2);
  delay(250);

  myServo4.write(27, mySpeed2);
  delay(250);

  myServo4.write(88, mySpeed2);
  delay(250);



}

re-edit your post using the pencil-button

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

What your program is doing is setting a new servoposition and make the microcontroller blocked for the amount of milliseconds given in each following up delay()-command.

Is this a description of what you want the servos to do
or
is this a description of what you observe and is something different than you want the servos do do?

In the code you have posted I quote you

In your code the servos indeed obey your servo-commands.

If somebody should give any kind of advice a more detailed description of what you want your servos to do is needed.

best regards Stefan

hi stefan , ty for answering....
Yes they indeed obey my servo write commands BUT ... when i start arduino and power up with +5v the three Servos lets say they MOVE by themselves for 1-2 seconds without my servo write commands they stop and settle down to zero lets say. And after that they move to the specific locations i have told them .....
ty in advance

Hi, @spectrum1982gr
Please do not edit essential information from your original post.

All we have now are snippets of your post copied to replying posts.

Following members looking at this thread will have little to no idea what your code is suppost to do and what it does do.

Tom... :smiley: :coffee: :coffee: :coffee: :australia:

so what is your

question ??!

The last posting just describes what you can see running your program.
the more important thing is what do you not like about your servos doing exactly what your program is telling them do do?

Hi,
Can you please post a link to data/specs of the servos?
Can you please post a circuit diagram?
What power supply are you using to power your project?

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

1 Like

Move your write(initialxxxx) commands in setup() to BEFORE the attach() commands. That should help. If you still see odd early movements then try putting a short delay() after each attach() to get over the fact that your power supply is probably inadequate to move 3 servos at once.

Steve

1 Like

Hi stefanL38
my question is simple...... Yes the program does move servos to the position i have told them BUT...
When i power up arduino and servos with an external power supply over 5A they do erratic movement lets say they move left and right they stop and after that they move to the values i have told them to do. The program works and servos are doing exactly what are ment to But AT power up they move for 1-2 seconds by their own will do an erratic movement and they start up normally
ty for answering

Hi slipstick (STEVE), ty for answering
my power supply is 450w from a pc its new and its working and i have changed other New power supplys as well
i am using 12v rail to power up arduino and 5v rail to power up servos
i will put a short delay after each attach() ( how much delay ? 1000ms? )
ty in advancc

hi TomGeorge ty for answering,
servos are SG90 (china) and MG90 again (china )
the circuit digram is simple i use 3 pwm pins to drive servos
the power supply i am using is from a pc its new 450w and a good brand i am using two rails to power up . one is 12v(YELLOW) going to Vin of arduino and the second is +5v(RED) going to servos. i have also replaced it with other ones ( i have 5 new PC power supplys) 450w
ty in advance

Some microcontrollers switch on off some of the IO-pins at power-up.
Some servos show the behaviour you have described if they don't get a proper input-signal.
To avoid all this one solution is to start the microcontroller first let the microcontroller start creating servopulses
If creating proper servoignalpulses is running then switch on the power of the servos. This requires a relay or MOS-FET that is able to switch the maximum current that can occur. Most medium-size MOS-FETs are able to do this.
If your microcontroller shall switch the MOS-FET directly from an IO-pin it has to a type with a very low gate-source-threshold-voltage and where the diagram showing gate-source-voltage over drain-source-current show a high enough current at 3V.

The type IRF3708 is such a type.
Be aware that MOS-FETs are sensitive to elctro-static discharge
slurping with plastic shoes over a carpet and then touching a MOS-FET
even if you don't feel the spark the MOS-FET will be destroyed.
best regards Stefan

1 Like

ty StefanL38
ty advance

here is an excerpt from the IRF 3708 Datasheet

Showing Drain to source current at different gate-source-voltages
and R_DS_On-resistance over gate-source-voltage

another important thing to check is power-dissipation caused by the R_DS_On-resistance

Let's say gate-source-voltage is only 3V
this means R_DS_On-resistance is around 0,012 Ohm. Let's say 0,013 Ohm
So power-dissipation is

P_diss = R_DS_On * current * voltage
P_diss = 0,013 Ohm * 5A * 6V = 0,39W

Thermal resistance of the IRF3708 Junction to ambient 62°C / W
so 62°C / W * 0.39W = 24 °C which means MOS-FET gets warm but is not overheating.
best regards Stefan

1 Like

ty stefan

You don't need 12V. Run the Arduino from the 5V rail too. Connect to the 5V pin. The power supply seems fine but you're not connecting the servos via a breadboard are you? They can only take very low currents.

A delay of 100 or 200 should be enough. But have you moved the write()s to before the attach()s? That was the important part. Please post your latest code and save us having to ask so many questions!

Steve

1 Like

ty in advance

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