How to Program a Quadruped Robot with Arduino

Robotics Technology
How to Program a Quadruped Robot with Arduino

Legged robots are great! They can handle terrain better than their wheeled counterparts and move in varied and animalistic ways. However, this makes legged robots more complicated, and less accessible to many makers.

Let’s get a four-legged robot (also known as a quadruped) walking. I will take you through a common walk style (called gait) and show you how to program it on an Arduino.

Read articles from the magazine right here on Make:. Don’t have a subscription yet? Get one today.

A Word on Quadrupeds

You will find quadrupeds abundant in nature, because four legs allow for passive stability, or the ability to stay standing without actively adjusting position. The same is true of robots. A four-legged robot is cheaper and simpler than a robot with more legs, yet it can still achieve stability.

Passive vs. Active Stability

A chair is passively stable, because it does not need any control or adjustment to stay upright. A standing human is actively stable because your body requires constant position control to stay standing.

When a quadruped is standing on four legs it is passively stable. When walking, it has options. It can maintain passive stability while walking by keeping three legs on the ground, and reaching out with the fourth. It also can give up passive stability and use active stability to move faster (albeit less smoothly). These two types of walking gaits are called the creep and the trot. I am going to show you how the creep gait works.

Creep Gait

The creep gait is the easiest walking gait to use. The robot keeps three feet on the ground, and keeps its center of gravity (CoG) inside the triangle formed by those three feet. If the CoG goes outside this triangle for too long, it will fall over (Figure A).

Feature photo by Hep Svadja. Diagrams by Juliann Brown


Simple enough. The problem is how to maintain this stability while walking. The pattern in Figure B will save you hours of trial and error (trust me, I know). It is a simple type of passively stable creep gait.

Break Down Creep Gait

1. This is the starting position, with two legs extended out on one side, and the other two legs pulled inward.

2. The top-right leg lifts up and reaches out, far ahead of the robot.

3. All the legs shift backward, moving the body forward.

4. The back-left leg lifts and steps forward alongside the body. This position is the mirror image of the starting position.

5. The top-left leg lifts and reaches out, far ahead of the robot.

6. Again, all the legs shift backward, moving the body forward.

7. The back-right leg lifts and steps back into the body, bringing us back to the starting position.

Notice that at all times, the triangle formed by the legs on the ground contains the CoG. This is the essence of the creep gait.

When we look at this pattern, we can see it is essentially two sets of mirrored movements. Step, step and shift, followed by another step, step and shift on the other side.

YouTube player

Write the Code

The gait is fairly simple — but how do we actually turn that into code? Well, the first thing to do is decide the specific x,y positions of the legs at each position (Figure C).

Each leg has its own x- and y-axis. We can give the foot of each leg a position, in millimeters, relative to that axis. For example, the top-left leg has the position (-50,50). Now we can apply these positions to each stage of the creep gait. Keep in mind that the specific positions you want will depend on the length of your robot’s leg. For any arbitrary quadruped, you will need to do some measuring to find the right numbers. Figure D is an example of the positions.

Between each step, we only need to deal with the change in position denoted by the green arrows on the sequence above. So how does this translate to code? Let’s take a look at the Arduino code to implement it (which you can also view as a txt file).


Surprisingly simple, right? Let’s break it down further in Figures E through K.

With this approach you will have your robot walking in no time. If you use servomotors, you will need to master inverse kinematics first, which will let you translate servomotor angles into the positions described here.

Discuss this article with the rest of the community on our Discord server!
Josh Elijah

Josh Elijah runs a robotics startup creating educational robotics for makers. His current project is the QuadBot, an open source, animal-inspired robot to teach STEM principles to makers. This project is live on Kickstarter, find out more at

View more articles by Josh Elijah