Electric Diy Lab

Electronics DIY projects, Tutorial

Arduino project

DIY Self Balancing Robot

Self balancing robot

Self balancing robot

Hello friends this post is about DIY self balancing robot in this post I’ll show how you can build your own Self balancing robot.

I have tried to build the project but failed not get results as expected.
but this robot turn out quite good and accurate, though this is not perfect but best as compare to my previous bots.

I have use a custom made PCB, Arduno nano, MPU6050, A4988 driver, HC-05 bt module, MDF board and some hardware to build this self balancing robot,
detail material list you can found further in this post.
Balancingwii firmware and EZ-GUI android app is used in this project to control robot via Bluetooth connection.

So lets begin with some basic of self balancing robot.


Basics of self balancing robot

Self balancing robot is the bot balance itself on two wheels, by constantly correcting its position.
A Gyro sensor is used in self balancing robot, which continuously sends the robot orientation data to the controller.
on the basis of this data controller command the motor to run forward or reverse to maintain the position of robot up straight.

self balancing robot basics

This is the ideal position of self balancing robot, body is perfectly up staring on the wheel
There is zero angle between the Y axis and body of robot.

self balancing robot basics

When body tilt in forward direction then there is some angle between Y axis and body.
This angle is detected by MPU6050 gyro sensor, then this data send to Arduino.
Arduino now do PID calculation and command the stepper motor to run in
forward direction to minimize the tilt angle upto zero degree.

self balancing robot basics

Same thing happens if when robot tilt in backward direction, motor will rotate in backward direction and correct the tilt angle to zero.
The bot in continue running motor forward and reverse more then 400 times in second so its looks us like robot is stable at its place.

Components Required

  1. Arduino Nano…………………………….1 no.
  2. MPU605 Gyro sensor……………….1 no.
  3. Nema 17 Stepper motors………….2 nos.
  4. 100mm Wheels…………………………..2 nos.
  5. A4988 Stepper driver IC…………..2 nos.
  6. HC-05 Bluetooth module………….1 no.
  7. 4mm MDF board.
  8. 150mm M5 threaded rods——–4 nos.
  9. some nuts and bolts

DIY Self Balancing Robot Electrical drawing

Self balancing robot wiring drawing

Above image is the circuit drawing of self balancing robot.
I have prepare a PCB also you can download the Gerber file to order PCB or you can also edit the PCB in easyeda platform.

Self balancing robot pcb

self balancing robot pcb details

The basic and minimal connection you must needs are as follow.


  • A4 – SDA
  • A5 – SCL

Motor driver pins:

  • D5 – STEP1 (PORTD 5)
  • D6 – STEP2 (PORTD 6)
  • D7 – DIR1 (PORTD 7)
  • D8 – DIR2 (PORTB 0)
  • D4 – ENABLE (for both)

Robot construction

Below is the basic construction image of self balancing robot

Self balancing robot structure

I have cut three pices of size 130 x 65mm
from MDF sheet of 4mm thick

Here I drill some holes to mout stepper motors and insert M3 rod through all three MDF board.

Then I cut two pice of 20 x 20 mm aluminium angle of 42mm in size, this is used to mount stepper motor with platform.

Now I use some hardware to assemble the body of self balancing robot.

Here I have inserted M5 rod to the base platform and mounted nema 17 stepper motor with the help of 20x20x42 aluminium angles.

Now I place the middle and top platform on M5 threded rod and fix them with M5 nuts.
And place PCB on the middle platform on 10 mm spacers.

1500mah 11.7 V lipo batter is placed on base platform and hold it on place with a belt.

Now finally I secure the wheel on the shaft of stepper motor and tighten it with M3 bot.

In this way our robot assembly is completed.
Now we can move towards the programming of self balancing robot.


To start programming arduino first we need to download a firmware for balancing robot called balancingwii.
this firmware is based on Multiwii firmware used for quad-copter and multi-rotor flying drones. you can learn here more about Multiwii.
special thanks to Mahowik who develop this firmware.
Download the firmware balancingwii by clicking here, now click on green button clone or download.
The firmware will downloaded in your PC in ZIP format.

Now unzip the downloaded file, open the newly created folder and delete that three file highlighted in image, this we not need at all.
also the name of folder containing balancingwii.ino file both must be same other wise you will get compiling error.
now open the balancingwii.ino file in arduino and compile the code and upload it with out changing any thing.
Don’t forget to turn off BT module before uploading the code.

If your MPU6050 orientation is different then my one you need to change this line in config.h file
You can change here PITCH to ROLL

 #define CURRENT_AXIS    PITCH       // possible to choose ROLL or PITCH axis as current.

By default mostly all HC-05 BT module came with default 9600 baud rate.

but for this project note that the baud rate of your HC-05 BT module must be 115200 other wise you cannot able to connect with android app

You can change the baud rate of HC-05 bt module via AT command search it on google you’ll get many tutorial about it.

/* This is the speed of the serial interfaces */
    #define SERIAL0_COM_SPEED 115200
    #define SERIAL1_COM_SPEED 115200
    #define SERIAL2_COM_SPEED 115200
    #define SERIAL3_COM_SPEED 115200

If you feel your robot is less responsive then you can try to change this setting in config.h file, but be remember the values must be in constraint.

 #define MAX_SPEED           350  // should be <= 500
 #define MAX_TARGET_ANGLE    130  // where 10 = 1 degree, should be <= 15 degree (i.e. <= 150) 
#define MAX_STEERING        90   // should be <= 100

Android app

EZ-GUI app is we going to use here you can learn more about EZ-GUI from here
EZ-GUI app is available to download from play store for free by click the link below or by scanning the below QR code.


App configuration

Open the downloaded app and click on the three dot at top right corner of screen

Click on the settings.

Select on BT Device to select BT module
now click on NEXT button

Now select the firmware “Multiwii 2.40” from the list and click next next until you reach the home screen.

ez gui app

Click on “CONNECT” button to connect with bluetooth.

self balancing robot app

Clink on “AUX” button

Tick mark as shown above.

This is my PID settings.
It is not compulsory that this PID settings will work for you bot each and every bot is unique.
PID is depends on bot desing, center of gravity, wheel size, motor type, and more.
try different setting you will surely get sweet setting after some trials.
now back from this screen, and click on three dot at top right corner and go to “advance” and then go to “Untested” and then click on “Model control”

Now this is the screen to play with you bot, you can run you self balancing bot from the joystick,
play with this screen try different settings to learn more.

In this way our DIY Self Balancing Robot is ready to play. enjoy..
if you have any question please ask in comment section.


  1. Manuel

    Thank you for your contributions.
    I will ride this bot.
    Can you tell me the engine characteristics.
    I imagine that with the HC-06 it will work well
    thanks again
    greetings from Barcelona – SPAIN

  2. Stefan Scott

    Do you have a link of the tire you used for this project? (Or the brand)?
    Looking forward to trying this out!

  3. Dhanashri

    Can we make this one using matlab simulink

  4. Amine

    Good evening sir
    please i have a problem can you help me?
    after connection with the HC-05 an error message appears
    “Warning no data received”
    when I click on the “AUX” button, the AUX1 AUX2 AUX3 tables do not appear, but a message appears in the middle “Not enough information”
    please help me

    • sandeep

      Please note that the baud rate of your HC-05 BT module must be 115200 other wise you cannot able to connect with android app, search on google how to change default baud rate of HC-05 bt module via AT commands

  5. bob

    Can I use arduino Nano in this project

  6. bob

    Thank you last question can I use DRV8825 stepper motor driver

Leave a Reply

Enter Captcha Here : *

Reload Image

Theme by Anders Norén