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

Or you can directly download gerber file for the PCB from here.
click to download

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

  7. Wolfgang Wesphal

    the outline drawing: DIY Self Balancing Robot Electrical drawing, (Arduino, Nema17 …) is in very good quality printout. With which program did you create this overview? Thank you for your response!

  8. Gianni

    Hi, congratulations for the project. I have a question, if I use smaller wheels do I have to change some parameters? is the functionality affected?

    • sandeep

      Hello, you don’t need to change anything in CODE
      to achieve best performance only you need to set PID parameters

  9. Hemanth

    hi sir after it connect via app and set pid values and i go to advanced untest it can show notifications like “WARNING ERROR 12C” what it means? What can i do

  10. Hemanth

    Sir those connections are in correct position . plz tell me about the stepper motor connections to driver sir

  11. Hemanth

    Sir those are SCL&SDA connections are good but same error was obtained plz help sir

  12. Baba

    After connecting to mobile app..via Bluetooth…12c error is coming .we have checked the connections of mpu 5060 ..but the error is same.

  13. Baba

    I’ve sent the screenshot to your mail

  14. Jeremy

    Hi Sandeep. Please could you tell me how you derive the 5 volt supply for the Arduino, Bluetooth and Gyro module? The circuit diagram shows these modules connected directly to the 3S LiPo batter which will surely cause them to fail? Am I missing something??

    • sandeep

      Lipo battery supply power to arduino through Vin pin and GND pin ans all rest 5V modules gets power from arduino.. refer circuit drawing

      • Jeremy

        Thanks Sandeep. I have never used a Nano before and had no idea that it has a voltage regulator onboard!

  15. Eswara prasad

    Sir I need the Gerber file of the circuit ,in the given link i can’t download it
    My mail id:[email protected]

  16. Ganesh

    HI sir , project is very gud i have done all hardware connections perfectly and program was also compiled and uploded and ezgui app installed and bluetooth is connected but
    AT SEETINGS AUX WAS EMPTY AS NO DATA RECIEVED can u plzz give me a solution sir.

  17. Ganesh

    my baund rate is 115200 only sir

Leave a Reply

Enter Captcha Here : *

Reload Image

Theme by Anders Norén