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

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
}