How a four-legged robot walks
This robot is built on Sesame, a charming open-source quadruped by dorianborian (frame and joints released under the Apache License 2.0). We use its printed frame, joints and wiring layout unchanged, and add our own MicroPython firmware: walking gaits, calibration, a phone page and a balance mode with a tilt sensor.
Two servos per leg
| Servo | Job |
|---|---|
| hip (R1, R2, L1, L2) | swings the leg forward and back |
| leg (R4, R3, L3, L4) | lifts the foot and puts it down |
Eight MG90S servos, a LOLIN S2 Mini board, a small OLED screen as a face, and an IMU (accelerometer + gyroscope) that feels which way the robot is tilted.
A step is a cycle
Watch one leg while a dog walks. It does two things, again and again:
- Swing (half of the cycle): the foot is up and moves forward.
- Stance (the other half): the foot is down and moves backward relative to the body, which pushes the body forward.
We describe where a leg is in its cycle with a phase from 0 to 1. In our code:
is the stride (25°), the lift (40°). The cosine makes the hip start and stop smoothly instead of jerking; the sine makes the foot rise and land softly.
The trot: diagonal pairs
If all four legs lifted together, the robot would fall. In a trot, the diagonal legs move together: front-right with back-left, front-left with back-right. One pair is at phase 0 while the other is at 0.5. So at every moment two diagonal feet are on the ground, and the body is supported between them.
Turning is the same trot with longer steps on one side. Walking backwards reverses the direction of the hip swing.
Feeling the tilt
The IMU measures two things. The accelerometer feels gravity, so it knows which way is down, but every footstep shakes it. The gyroscope measures how fast the robot rotates, smoothly, but if you add up its readings the angle slowly drifts. A complementary filter mixes both: 96 % “previous angle plus the gyro’s change”, 4 % “what the accelerometer says”. In balance mode, the legs on the low side push down and the legs on the high side pull up, so the body stays level on a tilted board.
What is in this guide
- How a four-legged robot walks (this chapter, free)
- Parts and printing the Sesame frame
- Assembly, wiring and power
- The code: gaits, calibration and balance
- Troubleshooting and what next
The Sesame project’s own build and wiring guides are linked from this guide; we follow their mechanical build exactly.


