Help with noob level robotic arm

Hello all.
This is my first post in this forum. I felt the need to ask here because I'm having a problem with the simple robotic armi I built on my own (You can see some pictures of it below).



It's pretty simple: Two Steppers to control the arms and one Servo to control the "hand" by pulling and releasing a sewing thread.
To control the two Steppers I'm not using any library and I choose them to go forward or backward with a couple of buttons for each motor.
They are controlled using an ULN2003 Driver Board.
The board has 4 pins (IN1-IN2-IN3-IN4) to control the electromagnets (You can find the picture of a Stepper and a driver board below).


So I simply alternately power these 4 pins to make the motor spin.
I obviously put a delay in the code between the activation of an electromagnet and its successive.
As initial value for this delay I used 50 ms, that worked pretty well, but I wanted to try a smaller delay, because with 50 ms the two arms move, but they are visibly laggy.
I tried with 10 ms and everything was smoother, but here the problem arrived.
The vertical arm moves fast and smooth (as I want it to do) right and left with no problems, but the horizontal arm can only move down (fast and smooth) but not up.
If I push the button to move it up it starts shaking but doesn't go up.
I obviously thought that a delay of 10 ms couldn't be handled by that arm when it needed to go up, so I changed back the delay value to 50 ms so that the vertical arm could still move fast and smooth and the horizontal one slow and laggy (I could accept this compromise).
But here came another problem.
Infact, also if the delay for the horizontal arm was set again to an "acceptable value" it gave me the same problem (it starts shaking when I try to move it up). No problems for the vertical arm again.
It seems that the only way to make it work is to set every delay (also for the Stepper that controls the vertical arm) to 50 ms and this doesn't make any sense to me because the two Steppers are separated and I can't get why a delay value set for the first motor should affect the second one in this way.
I've also tried powering the two steppers separately (with two different power supplies), and I've also tried powering the horizontal arm Stepper with 12V (these Steppers have a bridge to choose the voltage), but nothing changes.
Can you explain me why this happens and, if possible, how to fix it in order to have a smooth and fast movement on both arms?
Feel free to ask me more pictures to explain everything better.
Thanks :smiley:

EDIT: This is the part of the code I'm using to move the horizontal arm. It's pretty easy to understand I think, but I still haven't wrote it down using functions, cause I first want to make it work like I want.

 if(backward2 == 1) { //if BACKWARD2 button is pushed makes second stepper motor spinnign backward
    digitalWrite(SECONDMOTOR1, LOW); //makes the second stepper spin backward
    digitalWrite(SECONDMOTOR2, LOW);
    digitalWrite(SECONDMOTOR3, LOW);
    digitalWrite(SECONDMOTOR4, HIGH);
    delay(50);
    digitalWrite(SECONDMOTOR1, LOW);
    digitalWrite(SECONDMOTOR2, LOW);
    digitalWrite(SECONDMOTOR3, HIGH);
    digitalWrite(SECONDMOTOR4, LOW);
    delay(50);
    digitalWrite(SECONDMOTOR1, LOW);
    digitalWrite(SECONDMOTOR2, HIGH);
    digitalWrite(SECONDMOTOR3, LOW);
    digitalWrite(SECONDMOTOR4, LOW);
    delay(50);
    digitalWrite(SECONDMOTOR1, HIGH);
    digitalWrite(SECONDMOTOR2, LOW);
    digitalWrite(SECONDMOTOR3, LOW);
    digitalWrite(SECONDMOTOR4, LOW);
    delay(50);
    /*this little part of the code is used to adjust the width of the "hand", 
      because the servo is mounted on the vertical arm, so every time the horizontal arm moves up or down
      the sewing thread is pulled or released. By adjusting the servo angle every time the horizontal arm moves the problem is less visible.
    */
    if(servoAngle > 0) {
      servoAngle--;
      myservo.write(servoAngle);
    }
    digitalWrite(SECONDMOTOR1, LOW); //turns off first electromagnet           
  }
  if(forward2 == 1) { //if FORWARD2 button is pushed makes second stepper motor spin forward
    digitalWrite(SECONDMOTOR1, HIGH); //same but spins in the other sense
    digitalWrite(SECONDMOTOR2, LOW);
    digitalWrite(SECONDMOTOR3, LOW);
    digitalWrite(SECONDMOTOR4, LOW);
    delay(50);
    digitalWrite(SECONDMOTOR1, LOW);
    digitalWrite(SECONDMOTOR2, HIGH);
    digitalWrite(SECONDMOTOR3, LOW);
    digitalWrite(SECONDMOTOR4, LOW);
    delay(50);
    digitalWrite(SECONDMOTOR1, LOW);
    digitalWrite(SECONDMOTOR2, LOW);
    digitalWrite(SECONDMOTOR3, HIGH);
    digitalWrite(SECONDMOTOR4, LOW);
    delay(50);
    digitalWrite(SECONDMOTOR1, LOW);
    digitalWrite(SECONDMOTOR2, LOW);
    digitalWrite(SECONDMOTOR3, LOW);
    digitalWrite(SECONDMOTOR4, HIGH);
    delay(50);
    if(servoAngle < 180) { //same code to adjust hand's width
      servoAngle++;
      myservo.write(servoAngle);  
    }
    digitalWrite(SECONDMOTOR4, LOW); //same as above           
  }

Please display your image(s) in your post so we can see it(them) without downloading it(them). See this Simple Image Guide

...R

Robin2:
Please display your image(s) in your post so we can see it(them) without downloading it(them). See this Simple Image Guide

...R

Modified the post. Thanks for the hint :smiley:

Make simpler version of your program that just moves one stepper motor and post that code. It will make it easier to help.

This is code I use to move a 28BYJ stepper motor

void moveOneFullStep() {

 static unsigned long prevStepMicros;
 static char stepSequence = 0;

 if (firstStepOfSequence == true) {
 prevStepMicros = micros();
 firstStepOfSequence = false;
 }

 if (micros() - prevStepMicros < tableStepIntervalMicros) {
 return;
 }
 else {
 stepCount ++;
 prevStepMicros += tableStepIntervalMicros;
 }

 if(tableDirection == 'F'){
 stepSequence++;
 }else{
 stepSequence--;
 }

 if(stepSequence>3){
 stepSequence=0;
 }
 if(stepSequence<0){
 stepSequence=3;
 }



 switch(stepSequence){
 case 0:
 digitalWriteFast(stepperPin1, HIGH);
 digitalWriteFast(stepperPin2, HIGH);
 digitalWriteFast(stepperPin3, LOW);
 digitalWriteFast(stepperPin4, LOW);
 break;
 case 1:
 digitalWriteFast(stepperPin1, LOW);
 digitalWriteFast(stepperPin2, HIGH);
 digitalWriteFast(stepperPin3, HIGH);
 digitalWriteFast(stepperPin4, LOW);
 break;
 case 2:
 digitalWriteFast(stepperPin1, LOW);
 digitalWriteFast(stepperPin2, LOW);
 digitalWriteFast(stepperPin3, HIGH);
 digitalWriteFast(stepperPin4, HIGH);
 break;
 case 3:
 digitalWriteFast(stepperPin1, HIGH);
 digitalWriteFast(stepperPin2, LOW);
 digitalWriteFast(stepperPin3, LOW);
 digitalWriteFast(stepperPin4, HIGH);
 break;
 }
}

You can use the normal digitalWrite() where I have used digitalWriteFast(). Or you could install the digitalWriteFast library.

In my code the variable tableStepIntervalMicros has the value 12000.

...R

Hi, Can you show us the label on the steppers? There are both 5V and 12V versions out there...

Robin2:
Make simpler version of your program that just moves one stepper motor and post that code. It will make it easier to help.

This is code I use to move a 28BYJ stepper motor

void moveOneFullStep() {

static unsigned long prevStepMicros;
static char stepSequence = 0;

if (firstStepOfSequence == true) {
prevStepMicros = micros();
firstStepOfSequence = false;
}

if (micros() - prevStepMicros < tableStepIntervalMicros) {
return;
}
else {
stepCount ++;
prevStepMicros += tableStepIntervalMicros;
}

if(tableDirection == 'F'){
stepSequence++;
}else{
stepSequence--;
}

if(stepSequence>3){
stepSequence=0;
}
if(stepSequence<0){
stepSequence=3;
}

switch(stepSequence){
case 0:
digitalWriteFast(stepperPin1, HIGH);
digitalWriteFast(stepperPin2, HIGH);
digitalWriteFast(stepperPin3, LOW);
digitalWriteFast(stepperPin4, LOW);
break;
case 1:
digitalWriteFast(stepperPin1, LOW);
digitalWriteFast(stepperPin2, HIGH);
digitalWriteFast(stepperPin3, HIGH);
digitalWriteFast(stepperPin4, LOW);
break;
case 2:
digitalWriteFast(stepperPin1, LOW);
digitalWriteFast(stepperPin2, LOW);
digitalWriteFast(stepperPin3, HIGH);
digitalWriteFast(stepperPin4, HIGH);
break;
case 3:
digitalWriteFast(stepperPin1, HIGH);
digitalWriteFast(stepperPin2, LOW);
digitalWriteFast(stepperPin3, LOW);
digitalWriteFast(stepperPin4, HIGH);
break;
}
}




You can use the normal digitalWrite() where I have used digitalWriteFast(). Or you could install the digitalWriteFast library.

In my code the variable tableStepIntervalMicros has the value 12000.

...R

I've added the part of the code that makes the horizontal arm move to the post.
I've read your code and focused on the last part where you alternate power on different stepper pins.
I only power one per time, while you power two pins per time. What's the difference?

terryking228:
Hi, Can you show us the label on the steppers? There are both 5V and 12V versions out there...

Hi, thanks for the answer. I can't upload more attachments, but the label exactly says:

STEP MOTOR
28BYJ-48
5V DC

Hi,
Hmmm... OK.

There is some possible info here: SmallSteppers - ArduinoInfo

Scroll and find "STEP SEQUENCES:" Run the stepper REALLY SLOW and check the sequences. I have helped a few people who had wrong connections and the steppers SORT OF worked..

Juts one more thing tho check.

AND: You really need separate 5V power supply to those steppers!

terryking228:
Hi,
Hmmm... OK.

There is some possible info here: SmallSteppers - ArduinoInfo

Scroll and find "STEP SEQUENCES:" Run the stepper REALLY SLOW and check the sequences. I have helped a few people who had wrong connections and the steppers SORT OF worked..

Juts one more thing tho check.

AND: You really need separate 5V power supply to those steppers!

I'm already using a separate 5V power supply for the steppers, but thank you anyways for the hint!
The only difference is that I'm doing all of this without the library and that I only power one electromagnet per time.
I'll try powering two electromagnets per time and see if something changes.
If not, I'll finally try using the stepper library.

Ok... I'm an idiot...
The problem was so stupid and obvious... but also hard to find.
The constant referring to the second electromagnet of the second stepper motor has value = 50, the pin on my Arduino Mega.
When I changed all the 50 ms delays to 10 ms I used the option to find and replace all the results of the research...
Researched value was 50
Replaced value was 10
So... also the value of the constant was changed and so the second electromagnet of the second stepper motor didn't work anymore.

Now everything is working fine.

I'm sorry for opening a post (so long) for this stupid thing, but I really couldn't notice it...

Thanks to all the people who helped me.

Great that you got it working. And thanks for reporting back here when you found the issue.
Global search and replace can bite hard. I tend to avoid it, replacing each instance one at a time.

Hi F_P,

It sounded to me like there was a wiring / coil problem, but I couldn't figure out how it got changed..

so the second electromagnet of the second stepper motor didn't work anymore.

Mystery Solved.

...Don't LIKE Mysteries...