Go Down

Topic: Micro SG90 servo motor issues (Read 214 times) previous topic - next topic

Joshy434

I'm doing a small robot arm project using 4 micro servo motors connected to my arduino Uno, a breadboard and a 6v battery power supply. My arduino is connected separately to a USB and USB servos are powered from the 6v battery pack. I have followed a similar project that was available on the internet because I'm pretty new to arduino and stuff like this. I am controlling my servos via a bluetooth app on my android device which is working but the only issue I am experiencing is that my servos keep randomly moving and jittering rapidly even when I'm not controlling their movement. Could this be something to do with my power supply or my wiring? Any help would be appreciated.

vinceherman


vinceherman

It could be power supply.
Bread boards do not carry large currents well.

You might consider soldering the power wires directly to the servo power wires (with a switch to be able to interrupt power when you shut down)

It could be problems with your code.  Can you post that here?  Use code tags.

slipstick

6V 3A should be enough for 4 SG90s. But connecting the power to them through a breadboard is asking for trouble. Breadboards can only handle low currents.

OTOH it might be the Arduino code or the bluetooth connection or the Android app or the mechanical design of the arm placing too much load on the servos (that's my current favourite guess). We don't know anything about any of them.

Steve

Joshy434

Hi, thanks for getting back to me. Here is the code I am using, it could be incorrect because I am relatively new to all this but I tried to compose this code based on the similar project which I mentioned previously.

Here it is:

Code: [Select]

#include <Servo.h>  //arduino library
#include <math.h>   //standard c library

#define PI 3.141

Servo baseServo; 
Servo shoulderServo; 
Servo elbowServo;
Servo gripperServo;

int command;

struct jointAngle{
  int base;
  int shoulder;
  int elbow;
};

int desiredGrip;
int gripperPos;

int desiredDelay;

int servoSpeed = 15;
int ready = 0;

struct jointAngle desiredAngle; //desired angles of the servos

//+++++++++++++++FUNCTION DECLARATIONS+++++++++++++++++++++++++++

int servoParallelControl (int thePos, Servo theServo );
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

void setup()
{
  Serial.begin(9600);
  baseServo.attach(9);        // attaches the servo on pin 9 to the servo object
  shoulderServo.attach(10);
  elbowServo.attach(11);
  gripperServo.attach(6);
 
  Serial.setTimeout(50);      //ensures the the arduino does not read serial for too long
  Serial.println("started");
  baseServo.write(90);        //intial positions of servos
  shoulderServo.write(150);
  elbowServo.write(110);
  ready = 0;
}

//primary arduino loop
void loop()
{
  if (Serial.available()){
    ready = 1;
    desiredAngle.base = Serial.parseInt();
    desiredAngle.shoulder = Serial.parseInt();
    desiredAngle.elbow = Serial.parseInt();
    desiredGrip = Serial.parseInt();
    desiredDelay = Serial.parseInt();

    if(Serial.read() == '\n'){               // if the last byte is 'd' then stop reading and execute command 'd' stands for 'done'

        Serial.flush();                     //clear all other commands piled in the buffer
          //send completion of the command
        Serial.print('d');     
    }
  }
 
  int status1 = 0;
  int status2 = 0;
  int status3 = 0;
  int status4 = 0;
  int done = 0 ;
 
  while(done == 0 && ready == 1){ 
    //move the servo to the desired position
    status1 = servoParallelControl(desiredAngle.base, baseServo, desiredDelay);
    status2 = servoParallelControl(desiredAngle.shoulder,  shoulderServo, desiredDelay);
    status3 = servoParallelControl(desiredAngle.elbow, elbowServo, desiredDelay);     
    status4 = servoParallelControl(desiredGrip, gripperServo, desiredDelay); 
   
    if (status1 == 1 & status2 == 1 & status3 == 1 & status4 == 1){
      done = 1;
     
    }
       
  }// end of while
 

 
 
}

//++++++++++++++++++++++++++++++FUNCTION DEFITNITIONS++++++++++++++++++++++++++++++++++++++++++

int servoParallelControl (int thePos, Servo theServo, int theSpeed ){
 
    int startPos = theServo.read();        //read the current pos
    int newPos = startPos;
    //int theSpeed = speed;
   
    //define where the pos is with respect to the command
    // if the current position is less that the actual move up
    if (startPos < (thePos-5)){
         
       newPos = newPos + 1;
       theServo.write(newPos);
       delay(theSpeed);
       return 0;
           
    }
 
   else if (newPos > (thePos + 5)){
 
      newPos = newPos - 1;
      theServo.write(newPos);
      delay(theSpeed);
      return 0;
         
    } 
   
    else {
        return 1;
    } 
   
 
}

Joshy434

The other thing I've noticed is that if I power on the servos and the arduino, the servos seem to behave erratically for about 5 mins and then seem to calm down and allow me to control them via the app with no problems at all. Could this be my coding?

Go Up