I am a clumsy person using Arduino.
I want four micro linear actuators simultaneously control in the opposite direction. but micro linear actuators operate individually.
I would like to know if my code has a problem or if I need to configure additional hardware.
My plan is to control 4 motors in 5 phases.
1 step: No. 1 motor forward
2 step: No. 1 motor reverse, No. 2 motor forward
3 step: No. 2 motor reverse, No. 3 motor forward
4 step: No. 3 motor reverse, No. 4 motor forward
5step: No. 4 motor reverse
I want it to move with a time of 4 seconds per step.
I am using l16-50-63-6-r(L16-50-63-6-R),
Arduino uno, external power supply.
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
float servo1Pos = 0;
float servo2Pos = 0;
float servo3Pos = 0;
float servo4Pos = 0;
void setup() {
Serial.begin(9600);
servo1.attach(3);
servo2.attach(9);
servo3.attach(10);
servo4.attach(11);
}
void loop() {
servo1.write(0);
servo2.write(0);
servo3.write(0);
servo4.write(0);
// No. 1 motor forward
for (int i = 0; i <= 74; i ++)
{
servo1.write(i);
delay(54);
}
// No. 1 motor reverse, No. 2 motor forward
for (int i = 0; i <= 67; i ++) {
servo2.write(i);
servo1.write(74 - i*1.1);
delay(60);
}
// No. 2 motor reverse, No. 3 motor forward
for (int i = 0; i <= 70; i ++) {
servo3.write(i);
servo2.write(67-i*0.957);
delay(75);
}
// No. 3 motor reverse, No. 4 motor forward
for (int i = 0; i <= 50; i ++) {
servo4.write(i);
servo3.write(70-i*1.4);
delay(78);
}
// No. 4 motor reverse
for (int i = 50; i >= 0; i --) {
servo4.write(i);
delay(78);
}
}
I moved your topic to an appropriate forum category @junhyeokock.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
Please edit your post to add code tags, and explain the problem.
What do you expect the code to do, and what does it do instead?
the motors are not controlled simultaneously in steps 2, 3, and 4.
You send commands "simultaneously" to the motors, so what do they do?
Keep in mind that breadboards are not designed to handle motor currents (the tracks burn), and the motor power supply MUST be capable of handling the start/stall current for all the motors, simultaneously. Post a link to the actuator product page.
My power supply can produce up to 5A, so it doesn't seem to be a power supply problem.
at 1 step, No.1 motor moves forward at 74
So I made reverse movement 74 - i
It seems impossible that this loop could somehow move motor1 first, all the way to the end of its programmed motion, then move motor 2.
// No. 1 motor reverse, No. 2 motor forward
for (int i = 0; i <= 67; i ++) {
servo2.write(i);
servo1.write(74 - i*1.1);
delay(60);
}
Make sure that the motors, when driven alone, are actually capable of executing the given commands without hitting an internal end stop or limit switch.
If you attempt to try to drive a servo or linear actuator beyond its limits, it will either hit an end stop or a limit switch, which prevents further travel.
The motor drive electronics should not accept commands past that point, but some (especially cheap hobby servos) will actually be damaged by hitting the end stop.
In most cases, you must determine the allowed range of motion experimentally.
The only explanation I can think for that first loop to misbehave is that actuator 1 cannot be physically driven to the expected position for servo1.write(74). So it stops somewhere else until it receives position commands that it can execute.
I selected a linear motor considering the maximum distance to implement the movement.
The maximum movement distance of the motor I selected is 50mm, and the movement distance I implemented is 20mm. I don't think it's a problem related to limits.