We haven't added a photo or video of the finished project yet. Meanwhile, here is the wiring: every wire on the pin the instructions use.
The cells' “+” goes through the holder's switch. Every GND is shared: the board's, the driver's, the sensors' and the cells'.D2 is the board's digital pin 2, A0 is an analogue pin, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.
A Mini-Sumo Robot with Arduino Nano
A small autonomous robot for the mini-sumo class (10 × 10 cm, up to 500 g): it waits 5 seconds after the start, finds the opponent with an ultrasonic sensor and pushes it out of the ring, while sensors underneath watch the white edge so it never drives out itself.
Written by the RoboHub team. A question? Write to us.
Variations
Choose a variation and the parts list updates.
Instructions
1
The rules and the plan
In mini-sumo a robot may be no wider or longer than 10 × 10 cm and no heavier than 500 g (height is free). The ring (dohyo) is a black circle 77 cm across with a 2.5 cm white band at the edge. The robot is fully autonomous: on the referee's signal you press its button, take your hand away, and it starts moving 5 seconds later. Whoever leaves the ring first loses the round.
Always read the organiser's rules before an event: details can differ.
2
The chassis and motors
Cut a plate a little under 10 × 10 cm for the chassis: 3–4 mm plywood, aluminium or a 3D print. Fix the two N20 motors with their mounts at the back and push the wheels onto the shafts. At the front, close to the floor, make an angled blade from thin steel or aluminium sheet: it slides under the opponent, but it must not scratch the ring. Put the battery holder in the middle and as low as you can: a low centre of gravity keeps the robot from being flipped.
3
The motor driver
Solder the header pins onto the Arduino Nano and the TB6612FNG: both come unsoldered. Connect the left motor to the TB6612's AO1 and AO2 and the right one to BO1 and BO2. The control pins: PWMA → D5, AIN1 → D7, AIN2 → D8, PWMB → D6, BIN1 → D4, BIN2 → D2, STBY → D9. Through STBY the code keeps the motors fully off until the start.
TB6612FNG driverAO1→ → Left motor1
TB6612FNG driverAO2→ → Left motor2
TB6612FNG driverBO1→ → Right motor1
TB6612FNG driverBO2→ → Right motor2
TB6612FNG driverPWMA→ → Arduino NanoD5
TB6612FNG driverAIN1→ → Arduino NanoD7
TB6612FNG driverAIN2→ → Arduino NanoD8
TB6612FNG driverPWMB→ → Arduino NanoD6
TB6612FNG driverBIN1→ → Arduino NanoD4
TB6612FNG driverBIN2→ → Arduino NanoD2
TB6612FNG driverSTBY→ → Arduino NanoD9
4
Power
Charge the two 18650 cells fully and put them in the holder: together they give 7.4 V. Switch the holder off. Connect “+” to the TB6612's VM and the Nano's VIN, and “−” to the TB6612's GND and the Nano's GND. The TB6612's VCC (its logic supply) goes to the Nano's 5V pin. Check the polarity twice before switching on: reversed “+” and “−” destroys both the board and the driver.
The N20 motors are made for 6 V while the cells give 7.4 V (8.4 V when full), so the code limits the motors' power with PWM: MAX_PWM = 180 is about 70 % of full, an average of 5–6 V. With 12 V N20 motors you can raise MAX_PWM to 255.
TB6612FNG driverVM→ → Holder, 2 × 18650+
Holder, 2 × 18650+→ → Arduino NanoVIN
TB6612FNG driverGND→ → Holder, 2 × 18650−
Holder, 2 × 18650−→ → Arduino NanoGND
TB6612FNG driverVCC→ → Arduino Nano5V
5
Edge sensors
Fix two TCRT5000 sensors under the front corners, facing the floor, 3–5 mm above it. Connect the left one's DO to A0 and the right one's to A1, both VCC to 5V and GND to ground. Put the robot on a black surface, then on a white one, and turn the sensor's little screw until the module's LED clearly differs between the two.
Left edge sensorVCC→ → Arduino Nano5V
Left edge sensorGND→ → Arduino NanoGND
Left edge sensorDO→ → Arduino NanoA0
Right edge sensorVCC→ → Arduino Nano5V
Right edge sensorGND→ → Arduino NanoGND
Right edge sensorDO→ → Arduino NanoA1
6
The opponent sensor
Mount the HC-SR04 at the front, above the blade, looking straight ahead. VCC to 5V, TRIG to D12, ECHO to D11, GND to ground. The ring is 77 cm across, so the code only counts something closer than 40 cm as the opponent and doesn't chase the audience or the walls.
HC-SR04 sensorVCC→ → Arduino Nano5V
HC-SR04 sensorTRIG→ → Arduino NanoD12
HC-SR04 sensorECHO→ → Arduino NanoD11
HC-SR04 sensorGND→ → Arduino NanoGND
7
The start button
Connect one leg of the button to D3 and the other to ground. No resistor needed: the code turns on the internal pull-up. Place the button where you can press it easily from above while the robot stands in the ring.
Start button1→ → Arduino NanoD3
Start button2→ → Arduino NanoGND
8
The pin table
Every connection from the steps above, in one table. Key: TCRT5000-L and TCRT5000-R are the left and right edge sensors, BTN the start button, BAT+ and BAT- the holder's terminals after its switch, and M-L and M-R the left and right motors.
Once it is built, go down the table and check each wire.
In the Arduino IDE choose “Arduino Nano” as the board and “ATmega328P” as the processor (if the upload fails, try “ATmega328P (Old Bootloader)”). Windows sometimes needs the CH340 chip's driver installed separately. Keep the holder switched off while uploading.
Arduino C++
// Mini-sumo robot: Arduino Nano + TB6612FNG + two N20 gear motors.// An HC-SR04 finds the opponent; two TCRT5000 sensors watch the white edge.// Rules: after the start button the robot waits 5 seconds before it moves.// TB6612FNG motor driverconstint PWMA = 5; // left motor speed (PWM)constint AIN1 = 7; // left motor directionconstint AIN2 = 8;
constint PWMB = 6; // right motor speed (PWM)constint BIN1 = 4; // right motor directionconstint BIN2 = 2;
constint STBY = 9; // HIGH = driver on, LOW = both motors off// Sensors and controlsconstint TRIG = 12; // HC-SR04 triggerconstint ECHO = 11; // HC-SR04 echoconstint EDGE_LEFT = A0; // front-left TCRT5000 (DO)constint EDGE_RIGHT = A1; // front-right TCRT5000 (DO)constint START_BUTTON = 3; // to GND, uses the internal pull-upconstint LED = 13; // the Nano's own LED// Settings to tuneconstint WHITE = LOW; // most TCRT5000 modules read LOW over white; use HIGH if yours read the other wayconstint SEE_CM = 40; // closer than this = the opponent (the ring is 77 cm across)constint MAX_PWM = 180; // 6 V motors on a 7.4 V pack: about 5-6 V on averageconstint SEARCH_PWM = 110; // spinning speed while searchingconstunsignedlong START_DELAY_MS = 5000; // the 5 seconds the rules ask forint searchDirection = 1; // 1 = spin right, -1 = spin left// Both motors at once, -255..255 each (negative = backwards)void drive(int left, int right) {
left = constrain(left, -MAX_PWM, MAX_PWM);
right = constrain(right, -MAX_PWM, MAX_PWM);
digitalWrite(AIN1, left > 0 ? HIGH : LOW);
digitalWrite(AIN2, left < 0 ? HIGH : LOW);
digitalWrite(BIN1, right > 0 ? HIGH : LOW);
digitalWrite(BIN2, right < 0 ? HIGH : LOW);
analogWrite(PWMA, abs(left));
analogWrite(PWMB, abs(right));
}
// Distance to whatever is in front, in cm; 999 when nothing answers within about 1 mint distanceCm() {
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
unsignedlong echo = pulseIn(ECHO, HIGH, 6000UL); // give up after 6 ms (about 1 m)if (echo == 0) return 999;
return echo / 58;
}
// Waits for the button, then counts the 5 seconds with the LEDvoid waitForStart() {
drive(0, 0);
digitalWrite(STBY, LOW);
while (digitalRead(START_BUTTON) == HIGH) {
digitalWrite(LED, (millis() / 500) % 2 ? HIGH : LOW); // slow blink: ready
}
unsignedlong pressed = millis();
while (millis() - pressed < START_DELAY_MS) {
digitalWrite(LED, (millis() / 100) % 2 ? HIGH : LOW); // fast blink: counting down
}
digitalWrite(LED, HIGH);
digitalWrite(STBY, HIGH); // motors on: go
}
void setup() {
pinMode(STBY, OUTPUT);
digitalWrite(STBY, LOW); // motors off from the first moment
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(EDGE_LEFT, INPUT);
pinMode(EDGE_RIGHT, INPUT);
pinMode(START_BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
waitForStart();
}
void loop() {
bool edgeLeft = digitalRead(EDGE_LEFT) == WHITE;
bool edgeRight = digitalRead(EDGE_RIGHT) == WHITE;
// 1. The edge comes first: never drive out of the ringif (edgeLeft || edgeRight) {
drive(-MAX_PWM, -MAX_PWM); // back off
delay(250);
if (edgeLeft && !edgeRight) {
drive(MAX_PWM, -MAX_PWM); // edge on the left: turn right
searchDirection = 1;
} else {
drive(-MAX_PWM, MAX_PWM); // edge on the right (or both): turn left
searchDirection = -1;
}
delay(200);
return;
}
// 2. Opponent ahead: push at full powerif (distanceCm() < SEE_CM) {
drive(MAX_PWM, MAX_PWM);
return;
}
// 3. Nothing seen: spin on the spot and look
drive(SEARCH_PWM * searchDirection, -SEARCH_PWM * searchDirection);
}
10
The first test
Put the robot wheels-up and switch it on. The LED blinks slowly: the robot is ready. Press the button: the LED blinks fast for 5 seconds, then stays on and the wheels start turning. Hold your hand in front of the HC-SR04: both wheels should turn forwards. If one turns backwards, swap that motor's two wires.
Then put the robot in a ring (or on black card with a white edge) and check that it backs off at the edge.
11
Tuning and tactics
SEE_CM is how far away the robot “sees” the opponent. SEARCH_PWM is how fast it spins while searching: spin too fast and the sensor misses the opponent. Don't raise MAX_PWM above 180: 6 V motors wear out fast on 7.4 V.
Bring the weight up towards 500 g with a steel plate mounted low: a heavier robot is harder to push. Wipe the dust off the tyres often: grip is half the fight.
12
If something doesn't work
The robot ignores the button: check that the button sits between D3 and GND.
It doesn't see the edge and drives out: move the sensors closer to the floor or set their screws again. If it backs off on black instead, change WHITE = LOW to WHITE = HIGH in the code.
It doesn't find the opponent: are TRIG and ECHO swapped? Is the sensor so low that it “sees” the ring itself?
The Nano restarts when the motors start: the cells are flat or a wire is loose. Charge them and check the connections.
One wheel doesn't turn: is STBY on D9? Measure the voltage on VM with a multimeter.
13
Safety and match day
Charge the 18650 cells only with a charger made for them, and don't leave them unattended while charging. Never use a damaged or swollen cell. Carry the robot to the ring switched off. File the blade's sharp edge so it can't cut your hand.
Between rounds switch the robot off and on again (or press the Nano's reset button), then press the start button again.
Five infrared sensors measure how far the robot has drifted off the line, and a PID controller corrects the motors smoothly and fast. Built for competitions: the track, the sensor bar, the code and how to tune it.
Two infrared sensors see a black line on the floor and the car follows it on its own, round the bends too. On a wide black strip it stops, as if at a finish line.