Sumo robot with front ToF array
Build it step by step
0 of 7 doneSet the sensor addresses
XSHUT sequence.
Test the edge sensors
Print values over black and white.
Test the motors
On blocks.
Add edge avoidance
Back up and turn.
Add the opponent search
Charge, turn or spin.
Test in a ring
A black board with a white line.
Tune speed and turn times
Against a real opponent.
How do you build a sumo robot with front ToF array?
Three ToF sensors find the opponent and edge sensors keep the robot in the ring. You need Arduino Nano, VL53L0X time-of-flight distance sensor × 3, TCRT5000 IR reflective sensor module × 2, TB6612FNG Motor Driver, N20 gear motor with encoder × 2 and Li-Po 2S 7.4 V 2200 mAh 25C (RC). It takes 7 steps and about 240 minutes.
- Level
- Intermediate
- Time
- About 240 min
- Parts
- 6
Wiring
| From | To | Why |
|---|---|---|
| Three ToF sensors SDA, SCL | Nano A4 and A5 | Shared I2C bus |
| ToF XSHUT left, centre, right | Nano D2, D3, D4 | Address setup |
| Edge sensors (front left, front right) | Nano A0 and A1 | Ring edge detection |
| TB6612 PWMA, AIN1, AIN2 | Nano D5, D7, D8 | Left motor |
| TB6612 PWMB, BIN1, BIN2 | Nano D6, D9, D10 | Right motor |
| TB6612 STBY | Nano D11 | Driver enable |
| LiPo 2S plus | Switch, then TB6612 VM and Nano VIN | 7.4 V supply |
| LiPo minus | All grounds | Common ground |
Code
The three VL53L0X sensors point left, ahead and right, and the TCRT5000 sensors face down at the front corners to see the ring's white border. The sketch checks the edge first, because falling out loses the match, and only then looks for the opponent: charge when the centre sees it, turn toward it when a side does, and spin to search otherwise. Check which way your edge sensors read; many modules go low over white, in which case flip the comparison. Wake the sensors one at a time with XSHUT and give each its own address. Test rules from a real contest: mini sumo has limits on size, about 10 cm square, and weight, about 500 g, and uses a five-second start delay. A 2S LiPo is a fire hazard if abused: use a balance charger on a fireproof surface, never charge it unattended, store it in a LiPo bag, do not run it flat, and fit a low-voltage alarm. Keep fingers away from wheels and blades; test with the robot on blocks. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Mini sumo: edge first, then charge the opponent, else search. Libraries: Adafruit_VL53L0X. Board: Arduino Nano.
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
Adafruit_VL53L0X tof[3];
const int XS[3] = {2, 3, 4};
const uint8_t ADDR[3] = {0x30, 0x31, 0x32};
const int EDGE_L = A0, EDGE_R = A1;
const int PWMA = 5, AIN1 = 7, AIN2 = 8, PWMB = 6, BIN1 = 9, BIN2 = 10, STBY = 11;
const int EDGE_LEVEL = 500; // reflective sensor reads higher over the white border line
const int SPD = 200; // cap below full to protect 6 V motors on 7.4 V
void drive(int l, int r) {
l = constrain(l, -255, 255); r = constrain(r, -255, 255);
digitalWrite(AIN1, l > 0); digitalWrite(AIN2, l < 0); analogWrite(PWMA, abs(l));
digitalWrite(BIN1, r > 0); digitalWrite(BIN2, r < 0); analogWrite(PWMB, abs(r));
}
int dist(int i) {
VL53L0X_RangingMeasurementData_t m;
tof[i].rangingTest(&m, false);
return m.RangeStatus != 4 ? m.RangeMilliMeter : 999;
}
void setup() {
int pins[] = {PWMA, AIN1, AIN2, PWMB, BIN1, BIN2, STBY};
for (int i = 0; i < 7; i++) pinMode(pins[i], OUTPUT);
digitalWrite(STBY, HIGH);
for (int i = 0; i < 3; i++) { pinMode(XS[i], OUTPUT); digitalWrite(XS[i], LOW); }
delay(10);
for (int i = 0; i < 3; i++) { digitalWrite(XS[i], HIGH); delay(10); tof[i].begin(ADDR[i]); }
delay(5000); // contest rule: five seconds before moving
}
void loop() {
if (analogRead(EDGE_L) > EDGE_LEVEL) { drive(-SPD, -SPD); delay(250); drive(SPD, -SPD); delay(250); return; } // back off and turn right
if (analogRead(EDGE_R) > EDGE_LEVEL) { drive(-SPD, -SPD); delay(250); drive(-SPD, SPD); delay(250); return; } // back off and turn left
int l = dist(0), c = dist(1), r = dist(2);
if (c < 300) drive(SPD, SPD); // opponent ahead: charge
else if (l < 300) drive(-120, 120); // opponent on the left: turn left
else if (r < 300) drive(120, -120); // opponent on the right: turn right
else drive(110, -110); // lost: spin and search
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| At the edge | Reverses and turns before leaving |
| Opponent ahead | Charges |
| Opponent at the side | Turns toward it |
| Nothing seen | Spins to search |
If it does not work
Drives off the ring
Check the edge comparison direction and level.
Sensors not found
Check XSHUT wiring and addresses.
Motors too fast
Lower SPD.
Resets under load
Check the supply wires and capacitor.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the sumo robot with front ToF array?
Arduino Nano, VL53L0X time-of-flight distance sensor × 3, TCRT5000 IR reflective sensor module × 2, TB6612FNG Motor Driver, N20 gear motor with encoder × 2 and Li-Po 2S 7.4 V 2200 mAh 25C (RC).
How long does the sumo robot with front ToF array take to build?
About 240 minutes for a intermediate maker, in 7 steps.
How do I know the sumo robot with front ToF array works?
At the edge: Reverses and turns before leaving. Opponent ahead: Charges. Opponent at the side: Turns toward it.
Drives off the ring: what should I check?
Check the edge comparison direction and level.
Sensors not found: what should I check?
Check XSHUT wiring and addresses.
Motors too fast: what should I check?
Lower SPD.
Resets under load: what should I check?
Check the supply wires and capacitor.
