i made the sunfounder slouth robot my self with arduino uno ! but ...

hello everyone !
i am trying to make a project which is the sunfounder sloth robot the photo here

but i didn't buy the kit i made it my self
instead of arduino nano i used arduino uno R3
but i used the same code which is this one

#include "VarSpeedServo.h"  //include the VarSpeedServo library
#include <NewPing.h>        //include the NewPing library
//#include <Servo.h>

VarSpeedServo RU;  //Right Upper
VarSpeedServo RL;  //Right Lower
VarSpeedServo LU;  //Left Upper
VarSpeedServo LL;  //Left Lower

NewPing sonar(4,3,200); 
                                                     //vel(min), delay_Forward(max) = (5, 2000) 
const int vel = 20, vel_Back = 10;                   //vel(mid), delay_Forward(mid) = (20, 750) 
const int delay_Forward = 750, delay_Back = 1000;    //vel(max), delay_Forward(min)= (256, 50)
                                                     //wonderful ---> (10, 700) (50, 500) (100, 100) (100, 300) (100, 500)
const int array_cal[4] = {90,90,90,90}; 
int RU_Degree = 0, LU_Degree = array_cal[2] + 5;

const int num1 = 6;
const int array_forward[num1][4] =  
{
    {0,-40,0,-20},        
    {30,-40,30,-20},
    {30,0,30,0},
    {0,20,0,40},
    {-30,20,-30,40},
    {-30,0,-30,0},
};

const int num2 = 5; 
const int array_turn[num2][4] =  
{     
    {-40,0,-20,0},
    {-40,30,-20,30},      
    {0,30,0,30},
    {30,0,30,0},
    {0,0,0,0},
};

//#define INSTALL
//#define CALIBRATION
#define RUN

void Servo_Init()
{
    RU.attach(9);   // Connect the signal wire of the upper-right servo to pin 9 
    RL.attach(10);   // Connect the signal wire of the lower-right servo to pin 10 
    LU.attach(11);   // Connect the signal wire of the upper-left  servo to pin 11 
    LL.attach(12);   // Connect the signal wire of the lower-left  servo to pin 12 
}

void Adjust()                            // Avoid the servo's fast spinning in initialization 
{                                        // RU,LU goes from array_cal[0] - 5 ,array_cal[2] + 5 degrees to array_cal[0],array_cal[2] degrees
    for(RU_Degree = array_cal[0] - 5; RU_Degree <= array_cal[0]; RU_Degree += 1) {
        RU.write(RU_Degree);             // in steps of 1 degree
        LU.write(LU_Degree--);           // tell servo to go to RU_Degreeition, LU_Degreeition in variable 'RU_Degree', 'LU_Degree'         
        delay(15);                       // waits 15ms for the servo to reach the RU_Degreeition
    }
}

bool TooClose()
{
    int tooclose = 0;
    for(int a=0; a<5; a++) {  
        delay(50);
        int din = sonar.ping_in();
        if (din < 7 && din > 0) tooclose++;
    }
    if (tooclose < 5) return 1;   
    return 0;
}

void Forward()
{
    for(int x=0; x<num1; x++) {                    
        RU.slowmove (array_cal[0] + array_forward[x][0] , vel);    
        RL.slowmove (array_cal[1] + array_forward[x][1] , vel);
        LU.slowmove (array_cal[2] + array_forward[x][2] , vel);
        LL.slowmove (array_cal[3] + array_forward[x][3] , vel);
        delay(delay_Forward);
    }
}

void Backward()
{
    for(int z=0; z<4; z++) {    
        for(int y=0; y<num2; y++) {                  
            RU.slowmove (array_cal[0] + array_turn[y][0] , vel_Back);   
            RL.slowmove (array_cal[1] + array_turn[y][1] , vel_Back);
            LU.slowmove (array_cal[2] + array_turn[y][2] , vel_Back);
            LL.slowmove (array_cal[3] + array_turn[y][3] , vel_Back);
            delay(delay_Back); 
        }
    }
}

void setup()  
{
#ifdef INSTALL
    Servo_Init();
  
    RU.slowmove (90 , vel);
    RL.slowmove (90 , vel);
    LU.slowmove (90 , vel);
    LL.slowmove (90 , vel);
    while(1);
#endif

#ifdef CALIBRATION 
    Servo_Init();  
    Adjust();
    
    RL.slowmove (array_cal[1] , vel);
    LL.slowmove (array_cal[3] , vel);
    delay(2000);
    while(1);
#endif

#ifdef RUN 
    Servo_Init();
    Adjust(); 
       
    RL.slowmove (array_cal[1] , vel);
    LL.slowmove (array_cal[3] , vel);
    delay(2000);
#endif
}

void loop() 
{ 
    while(TooClose()) Forward();    
    Backward();    
}

but when i upload the code the robot start doing crazy mouvements
which do not look like walking at all
if there is something wrong in the code or something can't work with arduino uno please tall me
thanks for any help !

If the servos move then your selection of arduino models is probably good.

What did you expect the robot to do?
What does it actually do?

Hint - the terms 'crazy movements' and 'not look like walking' are not much help.
Want to confirm that each of your 4 servos work?
Go get the SWEEP tutorial.
Modify it to use the pin that your first servo is attached to and upload it.
Does the servo move back and forth as expected?
Repeat for the other 3 servos.

What are you using to power the servos?
You can often use the arduino 5v pin to power 1 unloaded servo, but when you try to power multiple servos (like your 4) and when you try to have the servos move while carrying a load (like your walker) you need to power the servos from a separate source.

Can you post pics of your walker? It sounds like a cool project!

thanks for your replay
the robot should walk by mouving the two upper servo and the two lower servo exactely like what does the sunfounder sloth do but mine is not walking at all the servos are mouving very quickly in the same time and it does not walk

my servos are working i tested them but i really did not understand what do you mean by "the sweep tutorial"

i am using the 5v pin of the arduino to power the four servos , how can i use a separate power source ? you mean that i should attach each servo to a battery it is a lot !

of course i can post pictures of it , it is a robot that walks and speak i will post the pictures here

The duplicate topic has been deleted from Project Guidance

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

UKHeliBob:
The duplicate topic has been deleted from Project Guidance

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

i am sorry , i did not know thanks for telling me
all my respects

i am using the 5v pin of the arduino to power the four servos , how can i use a separate power source ?

A pack of 4 AAs with a common ground to the Arduino