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.
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.
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.
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.
- Arduino Nano…………………………….1 no.
- MPU605 Gyro sensor……………….1 no.
- Nema 17 Stepper motors………….2 nos.
- 100mm Wheels…………………………..2 nos.
- A4988 Stepper driver IC…………..2 nos.
- HC-05 Bluetooth module………….1 no.
- 4mm MDF board.
- 150mm M5 threaded rods——–4 nos.
- some nuts and bolts
DIY Self Balancing Robot Electrical 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.
Note :- KINDLY CROSS CHECK ON YOUR OWN BEFORE ORDERING PCB..
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)
Below is the basic construction image of self balancing robot
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
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.
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.
Click on “CONNECT” button to connect with bluetooth.
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.