Arduino code does not work properly for an automated robotic arm

Dear all,
I have tried to run with muy pupils an Arduino project based on a code to move a robotic arm.

The project did run with an older Arduino Uno that I saw, but with several Arduino Uno I bought did not work.

We have checked all the items, and finally I have read if it has some relationship with the chip ATMEL. In both cases, the IDE 2.3.X was used, but the code worked in an older version that I have, which is not working properly.

I received info about the ATMEL older, which works:
MEGA 16U2
2241 TH
2241ESP

And the ATMEL I have, which does not work:
MEGA 16U2
2240 TH
22407JJ

I have checked all the issues, all connections are correct, serv motors and stepper motors are working correctly, and the last issue to consider is that one I comment to you.

Where is the problem. Could anyone help us to continue running the project? I am very grateful.

The code is the following:
//Nombre -> Robot GINER
//Proyecto -> Brazo robótico version1
#include <Servo.h>
#include <Stepper.h>
Servo servomotor3; //Servomotor pinza
Servo servomotor2; //Servomotor en medio
Servo servomotor1; //Servomotor abajo
Stepper motor(2048, 4, 6, 5, 7);
void setup() {
servomotor3.attach(11);
servomotor2.attach(10);
servomotor1.attach(9);
motor.setSpeed(5);
}
void loop() {
//Reinicio
servomotor1.write(0);
servomotor2.write(0);
servomotor3.write(0);
//motor.step(512);
delay(3000);
//COJE EL OBJETO
for(int i=0; i<=45; i++){
servomotor3.write(i);
delay(25);
}
delay(1000);
for(int i=0; i<=90; i++){
servomotor2.write(i);
delay(25);
}
delay(1000);
for (int i=0; i<=90; i++){
servomotor1.write(i);
delay(25);
}
delay(1000);
for(int i=45; i>=0; i--){
servomotor3.write(i);
delay(25);
}
delay(1000);
for (int i = 90; i>=0; i--){
servomotor1.write(i);
delay(25);
}
delay(1000);
for (int i = 90; i>=0; i--){
servomotor2.write(i);
delay(25);
}
delay(1000);
//GIRA CON EL OBJETO
motor.step(512);
delay(1000);
//DEJA EL OBJETO
for(int i=0; i<=90; i++){
servomotor2.write(i);
delay(25);
}
delay(1000);
for (int i=0; i<=90; i++){
servomotor1.write(i);
delay(25);
}
delay(1000);
for(int i=0; i<=45; i++){
servomotor3.write(i);
delay(25);
}
delay(1000);
//VUELVE A LA POSICION INICIAL
servomotor1.write(0);
servomotor2.write(0);
motor.step(-512);
delay(3000);
}

Please if you need additional information, do not hesitate to contact me.
Many thanks for your support.
Best regards,
Manuel

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

How are the servos and stepper powered ?

1 Like

Hi,
The servos and steepers are powered from a protoboard through a power supply of 5V.
This is also powering the Arduino Uno to the 5V pin and GND pin.
Servos and stepper connect through a pin to digital Arduino Pins (4, 9, 10, 11). There is another card for controlling the movement of the Stepper.
It is very strange that we can not supply power from the Protoboard Power supply, and we need to do it through wires as you can see on the picture.

However, it does not work properly. In the case of the older card, it is possible to supply power through the Protoboard Power Supply.

Use one or the other to power it, do not connect both.

Post an annotated schematic, that will help us help you and it will also help your students. Frizzes do not work for me.

In fact, I am powering only from the wires, and the Protoboard Power Supply is working as a bridge to supply both¡h sides of the Protoboard.

The schema is as follows:

Sorry my parts do not look like your picture (Frizzy wiring diagram). Good Luck!

I have achieved to move the robotic arm with the new card.

As you can see:

The unique problem now is that the arm does not return to the initial position after doing the job. Although the motor Stepper motor starts in the code as you can see with:
motor.step(512);

And it ends with motor.step(-512), but it does not return to the initial position.

As you can see:

Anybody knows, what is happening and how to solve?

Many thanks in advance,
Manuel

Finally it works!

The issue was in relation to the connection of the motor step to the board, the pins 4, 5, 6 and 7.

Many thanks for your comments, which help to investigate other sources of the problem.

Best regards,
Manuel

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.