Skip to content

Robotics

Build a sumo robot: states, an edge rule and a gyro turn

A sumo robot's brain is a state machine with one rule that beats all the others: if an eye sees the white edge, back off. The rest of the time it searches by spinning, charges when its range sensor sees the opponent, and after each retreat turns round by the gyro. Here's how to build that brain for a two-wheeled Arduino robot.

The ring and the sensors

  • RANGE on A2, looking ahead for the opponent: the lower the reading, the closer.
  • Two eyes on A0 and A1, looking down: the black ring reads about 250, the white edge about 940.
  • GYRO on A3, reading 512 at rest.
  • Two wheels on pins 9 and 10, and REVERSE on pin 11.

Four states

  • SEARCH: spin, one wheel at 180 and the other at 0. RANGE under 600: go to CHARGE.
  • CHARGE: both wheels at 255. RANGE over 800, the opponent has slipped away: back to SEARCH.
  • BACK: stop with REVERSE on. After 300 ms: TURN, with the heading reset to 0.
  • TURN: pivot, 255 and 0, adding up the gyro, until the heading reaches 180°: back to SEARCH.

The edge rule goes first

if ((state == SEARCH || state == CHARGE) &&
    (analogRead(A0) > 700 || analogRead(A1) > 700)) {
  state = BACK;
  since = millis();
}
switch (state) {
  // SEARCH, CHARGE, BACK and TURN
}

Put it before the switch, so whatever the robot was doing, the edge wins on the very same pass. 700 sits safely between the ring's 250 and the edge's 940. Check it in SEARCH only and the robot charges straight off the edge, because nothing in CHARGE looks at the eyes.

Live experiment

Watch a sumo brain fight

Two rovers in a black ring with a white edge. Run a bout with the edge rule always on, CHARGE giving up over 800 and TURN by the gyro, then break each one: the edge rule in SEARCH only, a CHARGE that never quits, or a timed 600 ms turn.

Try it yourself: free lesson

“Project: Sumo showdown” is the project that ends Waypoint Wharf, Robotics World 3. Free with an account. Lessons unlock in order, so you’ll do the 20 before it first.

Turn by the gyro, not the clock

A 600 ms pivot turns a different amount every time someone shoves you or a wheel slips on dust. Integrating the gyro, heading = heading + rate × dt, measures the turn itself, so 180° is 180° whatever the other robot is doing.

From simulator to ring

Real mini sumo robots, up to 10 × 10 cm and 500 g, fight on a black ring with a white border, the same plan as here. Typical builds use IR line sensors such as the QRE1113 underneath, short-range distance sensors in front, and an IMU for the gyro. Most rules make robots wait 5 seconds after the start before moving, and most bouts are won by finding the opponent first while keeping your own wheels on the black.

Free lesson

Now build it yourself

Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.

Try it yourself: free lesson

“Project: Sumo showdown” is the project that ends Waypoint Wharf, Robotics World 3. Free with an account. Lessons unlock in order, so you’ll do the 20 before it first.

Or start from the very first lesson, no account needed

Practice questions

Three quick questions from the lessons. Pick an answer to check it.

  1. Question 1 of 3The rover is charging and the left eye reads 900. It…
    Show the answer

    Answer: Goes to BACK at once: white means the ring's edge. The edge rule beats every other state. Black reads about 250 and white about 940, so 900 is the edge: back off before you drive out.

    • Why not “Stops for good”? Stopping for good loses the bout. BACK reverses briefly, then the robot turns and hunts again.
    • Why not “Turns left”? Turning on the edge can carry a wheel over it. The rule is to stop and reverse first.
    • Why not “Keeps charging: the opponent is still ahead”? The edge rule beats every state, CHARGE included. Pushing on past white drives the robot out.
  2. Question 2 of 3Why turn round by the gyro instead of pivoting for a fixed 600 ms?
    Show the answer

    Answer: A shove or a slippery patch changes how far 600 ms turns you; the gyro measures the turn itself. In a sumo ring the other robot is pushing you. Only a measured turn is the same every time.

    • Why not “600 ms is too long”? The trouble isn't the length. Any fixed time turns a different angle when the robot is pushed or slips.
    • Why not “The gyro is quicker to program”? A fixed delay is the quicker one to write. The gyro is worth the extra code because it's reliable.
    • Why not “It makes no difference”? On a still, clean floor they might match, but in a bout the other robot is pushing, so a timed turn varies.
  3. Question 3 of 3In APPROACH, RANGE jumps to 900. The rover goes to…
    Show the answer

    Answer: SEARCH: the target has slipped away. Over 800 means nothing is ahead any more, so it goes back to looking. Arrows can point backwards.

    • Why not “Nowhere: it stays in APPROACH”? A state with a way back for a lost target takes it. Over 800 means nothing is ahead, so it goes back to looking.
    • Why not “DONE”? DONE comes at the end of the job, not when the target is lost.
    • Why not “GRAB”? GRAB needs the target close, RANGE under 150. 900 means nothing is near.
Keep practising: free lesson

“Project: Sumo showdown” is the project that ends Waypoint Wharf, Robotics World 3. Free with an account. Lessons unlock in order, so you’ll do the 20 before it first.

Questions people ask

How does a sumo robot detect the edge of the ring?

With downward-facing infrared reflectance sensors near its front corners. The ring is black and its border white, so a reading that jumps from the black's level toward the white's means the robot is at the edge, and it must reverse at once.

What sensor should a sumo robot use to find its opponent?

A distance sensor pointing forward: an infrared rangefinder, a time-of-flight sensor or an ultrasonic one. Several in a fan let the robot turn toward the opponent instead of only charging straight ahead.

Why program a sumo robot as a state machine?

The robot has to keep reading every sensor while it does each job. A state machine runs a short pass of code many times a second, so the edge sensors are checked even in the middle of a charge, which a program built from delay() can't do.

Every topic