ESP32 Balancing Robot

by fpv99 in Circuits > Robots

7905 Views, 24 Favorites, 0 Comments

ESP32 Balancing Robot

294578.jpg

So, for some time I've been working on a good ESP32 based, stepper motors, WiFi connection balancing robot that could also have everything on the same PCB. After a few attempts, I finally have a good enough version, actually it's just a combination of a few amazing projects I found on the internet. This balancing robot drives very well, the code is based on electrical-pro's project, all components are on the PCB, everything is explained in this tutorial and you can also find the part list below. So, if you want to make a similar robot, follow this tutorial. Currently there is only an Android version of the controller app, it supports robot control and telemetry. For iPhone users, just open a browser and use the robot's control interface. So, let's see how this works and how to build it.

Supplies

T12JKyFcdcXXXXXXXX_!!0-item_pic.jpg
TB1szpFHFXXXXamXpXXXXXXXXXX_!!0-item_pic.jpg
O1CN01YADtqu1XYjVIaKmYl_!!2633382936.jpg
O1CN01dVSNaY1XYjWNmdJQc_!!2633382936.jpg
O1CN01J8xemo1XYjRXpr6dT_!!2633382936.jpg
O1CN012eUBO21XYjVLiPUp1_!!2633382936.jpg
O1CN01Q8JDir1XYjUDQQJs1_!!2633382936.jpg
TB25eT2kRjTBKNjSZFDXXbVgVXa_!!361121710.jpg
O1CN01eFfKdp1OVDsHimfDc_!!0-item_pic.jpg
O1CN01mvFvxy1OVDsEetUR9_!!0-item_pic.jpg
O1CN01Pa1mp01OVDsFGAC3C_!!0-item_pic.jpg
O1CN01TtIBuE1OVDsBCd33s_!!0-item_pic.jpg

We need a lot of parts but don't worry, nothing difficult to get. We need the ESP32 chip, the sensor, the motors, and a few other components such as resistors, capacitors and LEDs. Check each component below. If the link is not updated, just go on eBay and search for the component using the names below.

For the robot we need:

Robot Schematic

Circuit_New.jpg
1.jpg

The schematic is just a simplified version of electrical-pro's. First we have the power block where we regulate our 5V for the ESP32 module. The ESP32 chip provides 3.3V to INA219, MPU6050 and DRV8825. To control the motors we use 2 DRV8825s, which gets its power from the lipo battery. The lipo battery is just a typical 3S1P RC battery, these battery have a operating voltage between 12.6 to 11.1 volts, which is within the limit of our DC-DC converter in the power block. Get the PCB and the components and following the markings on the schematic, solder the PCB.

Soldering the PCB

pcb.jpg
2.jpg

This is a PCB I designed to hold all the components, except stepper motors. Print the PCB with services such as PCBWay or JLCPCB using the Gerber file.

Gerber file download link : https://supr.link/lIQMe

Before soldering the rest of the components, make sure we have a good 5V voltage, otherwise we might burn the ESP32 module because the default output voltage of my DC-DC converter is around 10V. So, connect the MP1584EN DC-DC converter to a power supply, slowly turn the voltage adjustment screw clockwise to lower the output voltage, stop when the output voltage reaches 5V.

Ok, at this point we can solder the rest of the components onto our PCB.

Programming ESP32

1.jpg
4.jpg
3.jpg
4.jpg
3.jpg

First, download the code here : https://supr.link/DZjwK. It's basically the same as the original code, only with a few modification to make it work with my schematic. To build the code successfully, you need to copy all the libraries in the "lib" folder to "C:\Users\My Username\Documents\Arduino\libraries".

Now is a good chance to configure the robot's AP. In the first few lines of "defines.h", you'll find variables ROBOT_NAME and AP_PASSWORD, if you have multiple robots, each robot should have a unique ROBOT_NAME.

After that, follow this tutorial to build and upload the code. For my ESP32, I had to select "ESP32 Dev Module" under Tools ->Board. If everything went as expected, you should see a “Done uploading.” message.

Also, don't forget to upload the sketch data, which are required for the control and setup pages to work correctly. In the Arduino IDE, go to Tools -> ESP32 Sketch Data Upload. When the process is complete, you should see "SPiFFS Image Uploaded" in the IDE.

Print and Build the Frame

Parts are modified from this beautiful frame designed by DaveGun. Original files are here.

All parts are assembled together using M3 8mm and 12mm bolts, which screw directly into the 3D printed parts, no nuts needed. Button head screws are recommended.

For the robot we need:

Install Controller App

294790.jpg
294984.jpg
control.jpg
index.jpg

Install Balancing Robot Controller from Google Play Store.

I designed this simple App to control the balancing robot. On the first startup, the robot will configure to AP(Access Point) mode with SSID "Balancing Robot" and password "12345678". Connect your WiFi to this access point. Once connection is established, open the App and should see telemetry data from the robot, including speed, voltage, power...etc, if not just press the Connect button to connect manually.

Note that connecting to a WiFi without internet might not work on some devices.


If you're using an iPhone, the built in web interface is the only way to control and setup the robot. After connecting to the robot's AP, open a browser and access the following pages:

For some reason, the control interface doesn't work correctly on Firefox.

Final Steps

5.jpg

Finally it's time to add the wheels and the battery. First, make sure you calibrate the gyro and accelerometer using Balancing Robot Controller App or web interface. Then check if the stepper motors rotate in the correct direction. There is a small arrow on the PCB pointing to the front of the robot, when you tilt the robot forward, both motors should spin forward. Once everything is setup correctly, put on the wheels and connect the battery, the robot should start balancing itself after a few beeps.

And Race!

The best way to control this robot is using the App. If there are multiple robots in the same space, make sure you setup different SSIDs for each robot. Have fun!

Reference

  1. https://github.com/electrical-pro/ESP32_Robot
  2. https://github.com/bluino/esp32_wifi_balancing_robot
  3. https://www.jjrobots.com/much-more-than-a-self-balancing-robot/
  4. https://www.thingiverse.com/thing:2863280