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.

Video

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.
https://easyeda.com/sharmaz747/self-balancing

Note :- KINDLY CROSS CHECK ON YOUR OWN BEFORE ORDERING PCB..
Self balancing robot pcb


self balancing robot pcb details

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

I2C:

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




Programming

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.

https://play.google.com/store/apps/details?id=com.ezio.multiwii

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.

78 Comments

  1. Manuel

    Thank you for your contributions.
    I will ride this bot.
    Can you tell me the engine characteristics.
    Voltage
    Pair
    Degrees
    Mold
    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

    Hi,
    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

  18. Rikard

    cant make this work, the app is not like the one on pictures, allso stepper motor just vibrate like crazy..

    • sandeep

      Hope you have downloaded correct app, you must have to do calibration before …..

  19. Rikard

    i have followed this instruction, and used the QR code..

  20. rajkumar

    hey sir, can we use adruino uno and Ln298 driver for motor ?
    do we need to can the codes for the driver circuit
    plz reponse fast

  21. Zeel mendpara

    Hello sir, I use Arduino Uno and A4988 Driver for motor. I upload code in UNO but Motor is not working but when i use different code for testing purpose, Motor is work so what is the problem??

    • sandeep

      By just uploading code to arduino motor will not supposed to move, request you to read completed post to clear some basic doubts.

      • Zeel mendpara

        I implement all the step like calibration, auto tune, pid implementation. Still motor is not working.

  22. Gamze Komsuoglu

    Hello sir Firstly
    I thank you for you share this Project with us .

    However I can’t compile this Project in arduino.
    It gives me error.It says that C:\Users\Useer\AppData\Local\Temp\cc6yuTgb.ltrans0.ltrans.o: In function `main’:

    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup’

    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop’

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Compile error for Arduino Nano card
    no headers files (.h) found in C:\Program Files (x86)\Arduino\libraries\jrowberg-i2cdevlib-f89153

  23. Syed Sulaiman

    What do I do with the ms1,ms2 and ms3 jumpers??
    What stepping resolution do I choose ??

    • sandeep

      I have shorted all of them (MS1, MS2, MS3) if you found motor skipping steps or generating less torque you may only shirt ms1 & ms2

  24. Rikard

    Damn this project pisses me off, i got the boards today, and i follow instructions, all the right components, guess what, it aint working, the led on BT, its faint red, i tryied with 3, and its the same..
    when turning power on, the stepper motor just spins, dosent matter if i tilt the board, nothing change..

  25. Rikard

    well, if u look at board, i think one line is missing for either + or -, the BT dont get enoouh power or something, the led is very faint..
    i havent calibrated anything?

  26. Rikard

    I was righht in my conclution, the BT needed power, and soldering another + wire, it now have power, the PCB is not correct made, u need update the files and correct them..

    • sandeep

      Yes I have noticed it now you need to add a jumper for +5V from arduino 5V pin to BT module vcc pin, I’ll update it thanks for let this know..

      • Rikard

        np. But i still cant make it work at all, the software aint showing correct on mobil, i dont have the same, even i use the QR code, allso the stepper just spin, and nothing more, even if i flip the board with gyro, nothing happens

  27. Kaunain

    hey good project, i have followed your tutorial and tried to make my own but i am facing issues
    i have change the baud rate of bluetooth to 115200
    i havent calibrated anything else
    i put the pid value as shown and i understand that they are unique but in the beginning i put them just to get a feel of the response of the bot
    my problem is that the wheels just spins in 1 direction and rarely it looks like wheels might be stabilizing
    my id is [email protected]
    can you help me asap??

    • sandeep

      You must have to first calibrate the bot by placing it on flat surface, without calibration bot doesn’t understand what is up/down/right/left position.
      after calibration the wheel movements make some sense, unless until it was random.

  28. titmous

    Hello sir. Before thank you for this project.
    But i need help. My ardiuno gives me error.It says that

    C:\Users\BAYARK~1\AppData\Local\Temp\ccXhnrcS.ltrans0.ltrans.o: In function `main’:

    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:43: undefined reference to `setup’

    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:46: undefined reference to `loop’

    collect2.exe: error: ld returned 1 exit status

    exit status 1
    Error compiling for board Arduino Nano.
    🙂

    • sandeep

      you folder name must be same as .ino file name, remove master if written in folder name

      • Víctor Manuel Sánchez Rodríguez

        I have the same problema…
        Can you help me pese?..

    • Víctor Manuel Sánchez Rodríguez

      have you solved the problem?

  29. delmiro cantillo

    hola amigo ya tengo armado todo las conecciones y estructura, pero los motores no tienes estabilidad yo los calibro conecto a bluetooth y no tiene control de si— como puedo hacer q se estabilice ?

    [email protected]

  30. Mohamd

    hi sandeep ,
    i follow yours very well and got fun really
    i am trying to do that bot , i did the same design except i got a dummy nano CNC shield v4.0 from another project to be used instead of alot of soldering and also it has i2c and serial for blutooth , it already assign different pins for stepper motor step , direction and enable signal also
    i got the firmware of balancing wii , but iam trying to modify to got compatible with the mentioned pcb

    too much code i should review to get it comptent with the card , wouldyou help in that
    thanks

  31. Raj

    Hello, can you please send the old gerber file, or maybe if u fixed the new pcb, because there is short on +5v and grond.

  32. Abdulla

    Hi man I have a problem the step motors not moving, They produce noise but no movement what so ever? can you help me figure this out, I have spent hours adjusting the PID settings in the EZ GUI, but no noticeable results.

    Thank you

    • sandeep

      have you calibrate the bot ?

      • Abdulla

        Yes I have. I guess my question is, how did you set up the pid settings, did you set it up manually or did it show up for you after the calibration?

  33. Mohamed elsakhawy

    Hi ,
    Thanks for the good project
    I am doing this project and enjoyed it really but I have a PCB used for the CNC using nano , any motor driver 4988 or 8825. But step and direction pins are different than the sketch

    I have 17HS08-100S4 motors with DRV8825 drivers and this PCB owns its I2c and blutooth place to use.
    I reviewed the software for making it compatible to the card pins for 3 days but output.CPP to config to output again to change all the pin statemnts
    I need help in that , would you ?
    Thanks

  34. Nagaraj

    How to interface this program to arduino mega 2560????

  35. Dev

    Hello, i want to ask you if the pcb is working properly that you provided in the description.

  36. Jens

    hi, I found out that the bleutooth module doesn’t get power. I connected this pin with the power on the a4988. I have also a question. Can you use the bot without the app, just for balancing ? My moter makes noise but istn’t move. I have read in the commands that you have to calibrate before it wil work. I saw in your code that you set a default PID values. So I wanted to know if I can use this project without the app.

    Thanks

  37. Jens

    Hi
    I found out that there is nog power to the bluetoothmodule, but i saw in the commants that this is already noted. I want to know if you can use the bot just for balancing without the app. I saw that there are default PID values. But my motors juist vibrate without rotate. I saw also in the comments that you have to calibrate it. But I will use this for a project in school. So can I use you’re bot without the app ?

  38. Adolfo Deluca

    Hi, thanks for the step bye step.
    I need ask something about the circuit, and please , apologize me if it’s a fool question , but, in the circuit I can’t see the connection beetwen the resistor and the GND or the step pin of the motor driver, or the connector in the HC-05 .
    thanks.

  39. Ramon

    Dear

    Thanks for sharing this project to us.
    I have a little problem.
    I will connect my bot to the app but when I click on connect the app said wrong MAC address.
    What can I do to fix it ?

  40. Rishi

    Hi sir!!!
    code is not uploading in the nano. i tried many times but here is the error that it is showing. please update the gerber file, i got wrong one printed!!

    HERE IS THE ERROR:
    An error occurred while uploading the sketch
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x66
    avrdude: stk500_recv(): programmer is not responding
    and so on till 10 times of attempting.

  41. Balogh Ádám

    Hello,
    Can you write down the steps of the calibration?

  42. Balogh Ádám

    Hello,
    Can you write down the steps of the calibration?
    Thank you.

  43. dhrutidhara Behera

    sir can you tell me what should be the the parity bit and stop bit when changing the baud rate from @9600 to @115200 .
    please help , its urgent.

Leave a Reply

Enter Captcha Here : *

Reload Image

Theme by Anders Norén