Introduction: Self Balancing Robot ArduinoUno/mpu6050/l298n
This is a two wheel self balancing robot
Step 1: Materials and Tools
The components are :
1) Sensor : 1 of Mpu6050 Gy521 Cost : 1$-2$ USD
2) Brain : 1 of Arduino Uno clone Cost 3$-4$ USD
3) Motor driver :1 of Module L298N Cost : 1-2$ USD
4) Batteries + batteries holder(prefer to have at least 1 with 3.5mm jack to power arduino uno) : can use AA, 9V or 18650 or phone power bank Cost : $5 to $20
The cheapest options are to use 2x 9V batteries or 8x AA batteries, I used 18650 because I have some around.
5) Frame: 3d printed with PLA weight = 300grams Cost : 5-10$ USD
6) Motor : 2 of TT gear motor 200rpm Cost : $4 to6$ USD
7) Ceramic Capacitor : 2 of value around 0.1mF
8) M3 screws or other mean to fit the board and motors
https://www.thingiverse.com/thing:2457928
The frame structure is quite simple and can be constructed by other methods and material easily.
Total cost : About $25 to 50$ USD
Tools :
Soldering iron or other method of connecting wire and capacitor to motors
Step 2: Wire Connections
Wire the connections as shown in the picture
1) First Battery connect to 3.5 power jack of the arduino ( can be a 9V battery or 4x AA batteries or other as long as in the range of 6 to 12V).
2) MPU6050 Gy521 connect to the Arduino Uno (same pin for Arduino Nano) :
Vcc ------- 3.3V
GND ------- GND
SCL ------- A5
SDA------- A4
INT-------PIN2
3) Second battery connect to L298N module :
Positive + ------- to +12V
Negavtive - ------- to GND
4) Second battery connect to Arduino Uno :
Negative - ------- to GND
5) L298N to Arduino Uno:
ENA ------- PIN10
INT1-------PIN8
INT2-------PIN7
INT3--------PIN6
INT4-------PIN5
ENB-------PIN9
6) Motors to L298N OUT1 and OUT2
7) 2 capacitor to two motor (solder or attach)
TO BE CONTINUE ...........
Step 3: Software :
You will need to install I2Cdev library and MPU6050 libraries :
https://github.com/jrowberg/i2cdevlib/tree/master/...
https://github.com/jrowberg/i2cdevlib/tree/master/...
Credit to :
https://randomagglomeration.blogspot.com
https://www.youtube.com/user/jmhrvy1947
Load the "balancebot.ino" file with arduino IDE and upload
Attachments
Step 4: Comment and Troubleshoot
1)The heavy weight components (batteries in this case) should be place on top of the robot.
2)Using one power supply source for both arduino and motor will still work, however when motor draw too much current might cause the arduino turn on and off. Hence why two separated power supply were used.
3)The system can still work without the capacitors added to motor, however the motors can produce noise into the system, try without capacitors if you dont have them available.
4) When start the robot, make sure both motors are running in the same directions(either forward or backward, if you notice motors run in opposite direction, swap 1 of the motor pair wire from out1 or out2 on the L298N board.
5)The IMU mpu6050 is not perfectly position, when start the robot, observe and adjust so that when the robot in straight up balance position neither motor turns or only turn slightly. To adjust: physically tilt the IMU mpu6050 until reach the desire position, fit with tape or glue gun or other mean to fix the IMU mpu6050. Other option is to calibrate the software
13 Comments
5 weeks ago
Thank you so much this one is perfect I Have looked for one that the right balance bot and one that is not one bazillion dollars
1 year ago
Hello,
The robot is moving very fast. it only moves forward. How can I fix?
3 years ago
Pls create code send me my project self balancing Robot. Some board
1). Arduino Nano
2). blutuooth module
3).mpu6050
4).two gear motor
5).l2982adual motor driver module
Pls send me code
Question 4 years ago on Step 3
The program is not working. It is showing some errors
Question 4 years ago on Step 2
How does Balancing Robot working?
5 years ago
Thank You. Managed to make this work. Used Nano 328 and was ok and a power supply to run motors about 8 volts worked well, less than 5 would not. Played around with settings for some time without a result but after thinking for a while I realized wheels were going in the wrong direction to self right. Swapped wire polarity to motors and it worked, very pleased. Made a bracket to hold MPU 6050 so it could be moved in different places to get it in the right plane and angle.
I would like some information to help me get this to turn when tilting the MPU6050 in the direction I would like it to go if possible, Thanks
Setting used were:(in comments settings tried)
// use calibration program to get your own values
mpu.setXGyroOffset(44);//(220 44 22 100);
mpu.setYGyroOffset(-21);//(76 -21);
mpu.setZGyroOffset(-30);//(-85 -30);
mpu.setXAccelOffset(-50);//(1788 -1875 17 -20 40 30); // 1688 factory default for my test chip
mpu.setYAccelOffset(-1426);
mpu.setZAccelOffset(2215);
Reply 4 years ago
how it working
4 years ago
Mine is showing "MPU6050 connection failed" *, what to do please help, i checked the wiring but it is still showing connection error...
Initializing I2C devices...
Testing device connections...
MPU6050 connection failed *
Initializing DMP...
DMP Initialization failed (code 1)
Please help me with this
Question 4 years ago on Step 4
How can i attach hc05 module to communicate with android!
Tip 4 years ago
This is not working..
Question 5 years ago on Step 2
What should the maximum PID values be? I haven't been able to get mine to balance yet. It is kind of close but mostly it just falls over. I have updated the offsets based on the calibration code.
Question 5 years ago on Step 1
\Users\Administrator\Downloads\balancebot_new\balancebot_new.ino:745:44: warning: extra tokens at end of #endif directive
#endif /* _MPU6050_6AXIS_MOTIONAPPS20_H_ *// I2Cdev library collection - Main I2C device class header file
i got this error pls explain what error is this
5 years ago
my one not working brother