Skip to content

Encoder Mobile Robot

Required setup: smabo-app + smabo-esp32

This page is the guide for the 'Encoder Mobile Robot' node on the roadmap below.

This guide assumes you have completed the Mobile Robot guide.

This page explains how to implement the "Encoder Mobile Robot" feature.


Specifically, you will:

  • Estimate the distance traveled with encoder DC motors (odometry)

In addition to the parts from Mobile Robot, you need the following.

Part Example (Japanese shop) Notes
Hobby metal gearmotor with encoder (DG01D-E) link Used instead of the TT motors from "Mobile Robot" (2 pcs)

Print the newly added parts on your 3D printer.

Because slicer software varies by printer model, only key points are noted here rather than step-by-step slicer instructions.


Print the following parts oriented as shown in the images.

  • smabo-hardware/stl/mobile_robot/DG01D-E/DG1D-E_bottom.stl 3D-printed encoder mobile robot part DG1D-E_bottom

  • smabo-hardware/stl/mobile_robot/DG01D-E/DG01D-E_stopper1_L.stl 3D-printed left motor stopper DG01D-E_stopper1_L

  • smabo-hardware/stl/mobile_robot/DG01D-E/DG01D-E_stopper1_R.stl 3D-printed right motor stopper DG01D-E_stopper1_R

  • smabo-hardware/stl/mobile_robot/DG01D-E/DG01D-E_stopper2_LR.stl 3D-printed motor stopper DG01D-E_stopper2_LR

Assemble the required parts as shown in the video below.

Note: the video also includes parts printed in previous steps.


Wire according to the tables below.

In the tables below, "Point A" and "Point B" are directly connected in the circuit.

Point A Point B Notes
Battery box (+) Breadboard + rail (right side) From here on, the right side is the 6 V rail
Battery box (-) Breadboard - rail -
Point A Point B Notes
ESP32 3.3V Breadboard + rail (left side) From here on, the left side is the 3.3 V rail
ESP32 GND Breadboard - rail -
Point A Point B Notes
TB6612FNG PWMA ESP32 pin set in config.json dc/pins/pwma Default pins:
- config.esp32-classic.json: GPIO 32
- config.esp32s3-devkitc1.json: GPIO 4
TB6612FNG AIN2 ESP32 pin set in config.json dc/pins/ain2 Default pins:
- config.esp32-classic.json: GPIO 33
- config.esp32s3-devkitc1.json: GPIO 5
TB6612FNG AIN1 ESP32 pin set in config.json dc/pins/ain1 Default pins:
- config.esp32-classic.json: GPIO 25
- config.esp32s3-devkitc1.json: GPIO 6
TB6612FNG STBY ESP32 pin set in config.json dc/pins/stby Default pins:
- config.esp32-classic.json: GPIO 26
- config.esp32s3-devkitc1.json: GPIO 7
TB6612FNG BIN1 ESP32 pin set in config.json dc/pins/bin1 Default pins:
- config.esp32-classic.json: GPIO 27
- config.esp32s3-devkitc1.json: GPIO 15
TB6612FNG BIN2 ESP32 pin set in config.json dc/pins/bin2 Default pins:
- config.esp32-classic.json: GPIO 14
- config.esp32s3-devkitc1.json: GPIO 16
TB6612FNG PWMB ESP32 pin set in config.json dc/pins/pwmb Default pins:
- config.esp32-classic.json: GPIO 12
- config.esp32s3-devkitc1.json: GPIO 17
TB6612FNG VM Breadboard + rail (right side) Motor power (6 V)
TB6612FNG VCC Breadboard + rail (left side) Logic power (3.3 V)
TB6612FNG GND Breadboard - rail The TB6612FNG has three GND pins; connect all of them to the breadboard's - rail
Point A Point B Notes
DG01D-E (left wheel) G Breadboard - rail -
DG01D-E (left wheel) H1 ESP32 pin set in config.json encoder/left/b Default pins:
- config.esp32-classic.json: GPIO 21
- config.esp32s3-devkitc1.json: GPIO 42
DG01D-E (left wheel) H2 ESP32 pin set in config.json encoder/left/a Default pins:
- config.esp32-classic.json: GPIO 19
- config.esp32s3-devkitc1.json: GPIO 41
DG01D-E (left wheel) V Breadboard + rail (left side) Encoder power (3.3 V); H1 and H2 also use this voltage
DG01D-E (left wheel) M+ TB6612FNG A02 -
DG01D-E (left wheel) M- TB6612FNG A01 -
DG01D-E (right wheel) G Breadboard - rail -
DG01D-E (right wheel) H1 ESP32 pin set in config.json encoder/right/a Default pins:
- config.esp32-classic.json: GPIO 22
- config.esp32s3-devkitc1.json: GPIO 2
DG01D-E (right wheel) H2 ESP32 pin set in config.json encoder/right/b Default pins:
- config.esp32-classic.json: GPIO 23
- config.esp32s3-devkitc1.json: GPIO 1
DG01D-E (right wheel) V Breadboard + rail (left side) Encoder power (3.3 V); H1 and H2 also use this voltage
DG01D-E (right wheel) M+ TB6612FNG B02 -
DG01D-E (right wheel) M- TB6612FNG B01 -

The wiring diagram for the ESP32-DevKitC (with the defaults in config.esp32-classic.json) is shown below.

Wiring diagram for the DG01D-E encoder motors and the ESP32

The completed robot looks like this.

The finished encoder mobile robot

Check that everything works with the steps below.

Follow the startup procedure here.

Then open the 'Config' tab in smabo-web.

In the 'Config' tab of smabo-web, enable:

  • 'dc_drive', and
  • 'encoder' inside 'dc_drive'

Enabling dc_drive and the encoder inside it in the smabo-web Config tab

In the 'Drive' tab, drive smabo with the controller. It works if:

  • the 'Position' values and the track in the 'Trail Map' change to follow smabo's actual position

Position and Trail Map in the smabo-web Drive tab


Next, the following node on the roadmap is explained: