Go Down

Topic: Motor Control Problems (Read 272 times) previous topic - next topic

bubbles

Hi, my name is bubbles, (yes, hilarious my friends chose the name) and I have a project where I'm trying to run 5 motors at once. However, I seem to have trouble with the motors acting together.  There isn't a problem with the code or motors.  Can anyone help me out here? The code is attached below.

-Thank you Bubbles


#include <Servo.h>

Servo myservo1, myservo2, myservo3, myservo4, myservo5;

int pos = 0;   

void setup() {
  myservo1.attach(9);
  myservo2.attach(8)
  myservo3.attach(7); 
  myservo4.attach(6); 
  myservo5.attach(5); 
}

void loop() {
  for (pos = 0; pos <= 180; pos -= 2) {
    // in steps of 2 degrees
    myservo1.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos += 2) {
     myservo1.write(pos);             
     delay(15);                       
  myservo1.detach();
   }
 
  for (pos = 0; pos <= 180; pos -= 2) {
    // in steps of 2 degrees
    myservo2.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos += 2) {
     myservo2.write(pos);             
     delay(15);                       
  myservo2.detach();
   }
  for (pos = 0; pos <= 180; pos -= 2) {
    // in steps of 2 degrees
    myservo3.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos += 2) {
     myservo3.write(pos);             
     delay(15);                       
  myservo3.detach();
   }
  for (pos = 0; pos <= 180; pos -= 2) {
    // in steps of 2 degrees
    myservo4.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos += 2) {
     myservo4.write(pos);             
     delay(15);                       
  myservo4.detach();
}
  for (pos = 0; pos <= 180; pos -= 2) {
    // in steps of 2 degrees
    myservo5.write(pos);             
    delay(15);                       
  }
   for (pos = 180; pos >= 0; pos += 2) {
     myservo5.write(pos);             
     delay(15);                       
  myservo5.detach();
   }
}

jremington

#1
Jan 08, 2018, 12:36 am Last Edit: Jan 08, 2018, 12:39 am by jremington
Please edit your post to add code tags ("</>" button), as described in the "How to use this forum" post.

At least 95% of the motor and servo problems posted on this forum are due to inadequate power supplies. For servos, you MUST use a separate 5-6V power supply, capable of supplying at least 1 Ampere per servo, so 5 Amperes total. Connect all the grounds together.

Finally, unless you know what you are doing, leave out all lines like this:
Code: [Select]
myservo1.detach();

slipstick

You know that code that there isn't a problem with?

Code: [Select]
for (pos = 0; pos <= 180; pos -= 2) {  
How long does it take to get to 180 or more when you start at 0 and keep subtracting 2 from it?

At least you're consistent, every one is the same.

Steve

PaulS

Quote
and I have a project where I'm trying to run 5 motors at once.
That is NOT what the code you posted does.
The art of getting good answers lies in asking good questions.

Coding Badly


@bubbles, do not hijack.  Thread split.

@bubbles, do not cross-post.  Other thread locked: http://forum.arduino.cc/index.php?topic=521456.0


bubbles

Thank you for all of your help with these problems.  I have successfully corrected all the issues.

-bubbles

Go Up