Wiring diagramTB6612FNG driver · AO1 → Left motor · 1; TB6612FNG driver · AO2 → Left motor · 2; TB6612FNG driver · BO1 → Right motor · 1; TB6612FNG driver · BO2 → Right motor · 2; TB6612FNG driver · PWMA → Arduino Nano · D5; TB6612FNG driver · AIN1 → Arduino Nano · D7; TB6612FNG driver · AIN2 → Arduino Nano · D8; TB6612FNG driver · PWMB → Arduino Nano · D6; TB6612FNG driver · BIN1 → Arduino Nano · D4; TB6612FNG driver · BIN2 → Arduino Nano · D2; TB6612FNG driver · STBY → Arduino Nano · D9; TB6612FNG driver · VM → Holder, 2 × 18650 · +; Holder, 2 × 18650 · + → Arduino Nano · VIN; TB6612FNG driver · GND → Holder, 2 × 18650 · −; Holder, 2 × 18650 · − → Arduino Nano · GND; TB6612FNG driver · VCC → Arduino Nano · 5V; Left edge sensor · VCC → Arduino Nano · 5V; Left edge sensor · GND → Arduino Nano · GND; Left edge sensor · DO → Arduino Nano · A0; Right edge sensor · VCC → Arduino Nano · 5V; Right edge sensor · GND → Arduino Nano · GND; Right edge sensor · DO → Arduino Nano · A1; HC-SR04 sensor · VCC → Arduino Nano · 5V; HC-SR04 sensor · TRIG → Arduino Nano · D12; HC-SR04 sensor · ECHO → Arduino Nano · D11; HC-SR04 sensor · GND → Arduino Nano · GND; Start button · 1 → Arduino Nano · D3; Start button · 2 → Arduino Nano · GNDArduino NanoD5D7D8D6D4D2D9VIN5VA0GNDA1D12D11D3TB6612FNG driverPWMAAIN1AIN2PWMBBIN1BIN2STBYVCCVMGNDAO1AO2BO1BO2Left motor12Right motor12Holder, 2 × 18650+−Left edge sensorVCCGNDDORight edge sensorVCCGNDDOHC-SR04 sensorVCCTRIGECHOGNDStart button12

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.

NewRobotics

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'.

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.

Difficulty
Intermediate
Time
4 h
Age
12+
Parts
12, 9 on the site

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.

    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.

    • TB6612FNG driver AO1 → Left motor 1
    • TB6612FNG driver AO2 → Left motor 2
    • TB6612FNG driver BO1 → Right motor 1
    • TB6612FNG driver BO2 → Right motor 2
    • TB6612FNG driver PWMA → Arduino Nano D5
    • TB6612FNG driver AIN1 → Arduino Nano D7
    • TB6612FNG driver AIN2 → Arduino Nano D8
    • TB6612FNG driver PWMB → Arduino Nano D6
    • TB6612FNG driver BIN1 → Arduino Nano D4
    • TB6612FNG driver BIN2 → Arduino Nano D2
    • TB6612FNG driver STBY → Arduino Nano D9
  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.

    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.

    • TB6612FNG driver VM → Holder, 2 × 18650 +
    • Holder, 2 × 18650 + → Arduino Nano VIN
    • TB6612FNG driver GND → Holder, 2 × 18650 −
    • Holder, 2 × 18650 − → Arduino Nano GND
    • TB6612FNG driver VCC → Arduino Nano 5V
  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.

    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.

    • Left edge sensor VCC → Arduino Nano 5V
    • Left edge sensor GND → Arduino Nano GND
    • Left edge sensor DO → Arduino Nano A0
    • Right edge sensor VCC → Arduino Nano 5V
    • Right edge sensor GND → Arduino Nano GND
    • Right edge sensor DO → Arduino Nano A1
  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.

    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.

    • HC-SR04 sensor VCC → Arduino Nano 5V
    • HC-SR04 sensor TRIG → Arduino Nano D12
    • HC-SR04 sensor ECHO → Arduino Nano D11
    • HC-SR04 sensor GND → Arduino Nano GND
  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.

    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.

    • Start button 1 → Arduino Nano D3
    • Start button 2 → Arduino Nano GND
  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.

    Text
    Arduino Nano
    D5                 ->  TB6612 PWMA
    D7                 ->  TB6612 AIN1
    D8                 ->  TB6612 AIN2
    D6                 ->  TB6612 PWMB
    D4                 ->  TB6612 BIN1
    D2                 ->  TB6612 BIN2
    D9                 ->  TB6612 STBY
    D12                ->  HC-SR04 TRIG
    D11                ->  HC-SR04 ECHO
    A0                 ->  TCRT5000-L DO
    A1                 ->  TCRT5000-R DO
    D3                 ->  BTN, BTN -> GND
    5V                 ->  TB6612 VCC, HC-SR04 VCC, TCRT5000-L/R VCC
    VIN                ->  BAT+
    GND                ->  BAT-, TB6612 GND, HC-SR04 GND, TCRT5000-L/R GND
    
    TB6612 AO1, AO2    ->  M-L
    TB6612 BO1, BO2    ->  M-R
    TB6612 VM          ->  BAT+
  9. Upload the code

    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 driver
    const int PWMA = 5;   // left motor speed (PWM)
    const int AIN1 = 7;   // left motor direction
    const int AIN2 = 8;
    const int PWMB = 6;   // right motor speed (PWM)
    const int BIN1 = 4;   // right motor direction
    const int BIN2 = 2;
    const int STBY = 9;   // HIGH = driver on, LOW = both motors off
    
    // Sensors and controls
    const int TRIG = 12;          // HC-SR04 trigger
    const int ECHO = 11;          // HC-SR04 echo
    const int EDGE_LEFT = A0;     // front-left TCRT5000 (DO)
    const int EDGE_RIGHT = A1;    // front-right TCRT5000 (DO)
    const int START_BUTTON = 3;   // to GND, uses the internal pull-up
    const int LED = 13;           // the Nano's own LED
    
    // Settings to tune
    const int WHITE = LOW;        // most TCRT5000 modules read LOW over white; use HIGH if yours read the other way
    const int SEE_CM = 40;        // closer than this = the opponent (the ring is 77 cm across)
    const int MAX_PWM = 180;      // 6 V motors on a 7.4 V pack: about 5-6 V on average
    const int SEARCH_PWM = 110;   // spinning speed while searching
    const unsigned long START_DELAY_MS = 5000;   // the 5 seconds the rules ask for
    
    int 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 m
    int distanceCm() {
      digitalWrite(TRIG, LOW);
      delayMicroseconds(2);
      digitalWrite(TRIG, HIGH);
      delayMicroseconds(10);
      digitalWrite(TRIG, LOW);
      unsigned long 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 LED
    void waitForStart() {
      drive(0, 0);
      digitalWrite(STBY, LOW);
      while (digitalRead(START_BUTTON) == HIGH) {
        digitalWrite(LED, (millis() / 500) % 2 ? HIGH : LOW);   // slow blink: ready
      }
      unsigned long 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 ring
      if (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 power
      if (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.

  • NewRobotics
    Advanced4 h12+

    A PID Line Follower Robot

    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.

    8/8 parts on the site
  • Robotics
    Intermediate2 h12+

    A Car That Avoids Obstacles

    A two-motor robot car drives forward, spots a wall from afar with its ultrasonic “eye”, stops, looks left and right and turns where the way is clear.

    8/8 parts on the site
  • Robotics
    Intermediate1 h 30 min12+

    A Line-Following Car

    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.

    7/7 parts on the site