Go Down

Topic: Arduino UNO three servos problem (Read 766 times) previous topic - next topic

tlogar

Hi!

I have a problem. I am making robot hand and now I'm testing servos. When I'm having attached only two servos everything works just fine. But when I connect the third one that doesn't work. I tried servos with other code and all of them works great. I have an external power supplay and I am using Towerpro mg995 and arduino UNO. I don't know what is the problem so I am asking you. I also added my code and schematic. Thank you.  :) 

#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

//Servo pozicija
int poz1 = 0;
int poz2 = 0;
int poz3 = 0;
int poz4 = 0;

//Joystick
int VRx1 = 0;
int VRy1 = 0;
int VRx2 = 0;
int VRy2 = 0;

//Potenciometer
int pot = 0;
int hitrost = 0;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600); //

  //Priklop servo motorjev
  servo1.attach(5);
  servo2.attach(6);
  servo3.attach(9);
  servo4.attach(10);

}

void loop() {
  // put your main code here, to run repeatedly:

  //Branje in normiranje vrednosti potenciometra DELUJE!
  pot = analogRead(A4);
  hitrost = map(pot, 0, 1023, 15, 75);
 
  //Branje in normiranje joystickov
  VRx1 = analogRead(A0);
  VRx1 = map(VRx1, 0, 1023, 0, 10);
  VRy1 = analogRead(A1);
  VRy1 = map(VRy1, 0, 1023, 0, 10);
  VRx2 = analogRead(A2);
  VRx2 = map(VRx2, 0, 1023, 0, 10);
  VRy2 = analogRead(A3);
  VRy2 = map(VRy2, 0, 1023, 0, 10);

  //Premikanje osi S DELUJE!
  if (VRx1 < 2 && poz1 > 0) {
    (poz1--);
    delay(hitrost);
  }
 
  if (VRx1 > 8 && poz1 <180) {
    (poz1++);
    delay(hitrost);
  }

  servo1.write(poz1);

  //Premikanje osi L DELUJE!
  if (VRy1 < 2 && poz2 > 0) {
    (poz2--);
    delay(hitrost);
  }

  if (VRy1 > 8 && poz2 <180) {
    (poz2++);
    delay(hitrost);
  }

  servo2.write(poz2);

  //Premikanje osi U
  if (VRx2 < 2 && poz3 > 0) {
    (poz3--);
    delay(hitrost);
  }

  if (VRx2 > 8 && poz3 < 180) {
    (poz3++);
    delay(hitrost);
  }

  servo3.write(poz3); 

}


PaulS

Code: [Select]
  VRx1 = analogRead(A0);
  VRx1 = map(VRx1, 0, 1023, 0, 10);
  VRy1 = analogRead(A1);
  VRy1 = map(VRy1, 0, 1023, 0, 10);
  VRx2 = analogRead(A2);
  VRx2 = map(VRx2, 0, 1023, 0, 10);
  VRy2 = analogRead(A3);
  VRy2 = map(VRy2, 0, 1023, 0, 10);

map() is pretty expensive way to divide by 10.

When switching analog pins being read from, the usual practice is to discard the first reading.

Quote
But when I connect the third one that doesn't work
Something happens. We can't see what happens, and you did not tell us what happens.

There is no reason to connect the servos to PWM pins. Servos are not driven using PWM.
The art of getting good answers lies in asking good questions.

tlogar

Well, when i connect third servo it just doesn't work. It even doesn't move for a little when I connect it to power. Can this mean that my power supply is not powerful enough?

PaulS

Quote
Can this mean that my power supply is not powerful enough?
If you switch the order around, and the third servo is always the one that causes the problem, yes.
The art of getting good answers lies in asking good questions.

tlogar


MarkT

Have you budgeted an amp per servo?  If not its going to be a power problem I reckon.

@PaulS
Quote
When switching analog pins being read from, the usual practice is to discard the first reading.
Only if the signal have a high source impedance.  If they are 10k or lower its unnecessary.

What is necessary is to ignore the very first analogRead() after powering up, since that
will be erroneous.  Very often you don't care about this, but it can throw-out startup-calibration
routines.   Mind you perhaps this is done in the Arduino runtime anyway these days, I haven't looked at
every version of the IDE !!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up