Secondary Menu

Making a Mini Self-balancing Car in Two Steps

Introduction: Making a Mini Self-balancing Car in Two Steps

A self-stabilizing motor that will never fall sounds great. Many geeks playing arduino has come out of many self-stabilizing projects like self-stabilizing platform, motorbike etc. In this instructable we will introduce an amazing arduino shield that can help you make a self-stabilizing project easily. The stabilizer shield use L298P chip that is a high voltage, high current dual full-bridge driver designed to accept standard TTL logic levels and drive inductive loads such as relays, solenoids, DC and stepping motors. Besides, stabilizer shield has a standard XBee socket, so that you can use Bluetooth to control a self-balancing robot car moving forward and back.

Next step of this project:

Adjust demo, accurate the PID parameters to make the car self-stabilizing more stable

Use Smartphone to control the car move forward and back or even turn around.

Stay tuned!

Step 1: Hookup

Stabilizer is a plug-and-play arduino shield. Plug the shield in Iteaduino UNO mainboard, after assemble the car, you just need to connect motors to stabilizer shield by wires. Then the hardware hookup is done.

When you use one pulse output signal, you can only measure the motor speed. If you use two pulse output signals, you can measure the motor speed and direction in the same time.

2. You can’t upload the demo to UNO when the XBee and jumper have already plugged in stabilizer shield. Since the serial ports have been taken, you’d better unplug jumper first, and then upload the demo.

3. When you want to make the XBee communicate with PC, you should plug jumpers in the B side. Since the serial ports have been taken, you’d better upload an empty application to arduino, and then they can be communicated normally.

Software Problems

Software debugging is very important. It divides into four parts.

First, read the MPU6050 accelerometer and gyroscope data through I2C to get the attitude data.

Second, Kalman filtering, namely integrate the data from accelerometer and gyroscope to reach to the real angle of inclination.

Third, calculate the speed and direction of wheels respectively. We use PID algorithm to calculate and control car’s movement, so that the car can keep self-balancing.

Forth, motor driver. The results of PID algorithm will turn into commands to drive the motor moves. You can see more codes details in the demo.

Tips for software debugging

1. Pay attention to data filtering of accelerometer and gyroscope. We use three-axis accelerometer and three-axis gyroscope. Refer to the top picture of our project, X is the car movement direction, Y is the direction of wheel and axle. The accelerometer data shall be collected between the X axis and Z axis, and turn the radian into angle. The direction of gyroscope shall keep in Y.

2. The angle direction calculated by accelerometer must be in accord with the angle direction calculated by gyroscope, if not, the car can’t be self-balancing.

3. When calculate the position of wheels, you should pay attention to the direction as well.

Step 3: Note

To debug the parameter of PID is the most important thing in this project. A decimal point or a number will decide whether the car can be self-balancing moved forward.

Meanwhile, the Bluetooth function has been written in the demo, but here we didn’t show up. Welcome more makers to hack this shield.

Last, I record a short video. The self-balancing car looks so stumble. I think maybe he has a very gentle temper or maybe he is gonna power off. : P What do you guys think? Hope you enjoy this project.

You seems have a very deep thought about the code. Recently, I try to modify the code and hope to make the self-balancing car to stand still and never fall, but it seems a little hard. No matter how hard I try, it will swing, and you know just like the video, move forward... So any suggestion?

I could see the code ok - I wondered if you could publish a PDF or something of the Kalman filter equations explaining your model, error covariance matrix and so on. What is your A,B,C,D matrices and so on. How did you get the noise variances.This would be a great help to people I think in understanding.

Two files - Stabilizer.ino & I2C.ino have been compressed in a zip. There is no need to upload I2C.ino to UNO.

You can use Arduino UNO to replace Iteaduino UNO.

Yun Li develop this stabilizer shield aiming at simplifying his self-balancing car project, and he just share a part of it to us. The complete datasheet of this project can be found in its wiki page: http://wiki.iteadstudio.com/Stabilizer_Shield

There is no need to buy a kit, any DC motor with encoder will be OK. Just pay attention to the Pin order of the DC motor.

The code can be verified without connecting to motors. When you open the stabilizer.ino, I2C.ino will appears as well. Then Choose the board Arduino UNO. If I2C.ino didn't appear, the verification will be failed.

Yes, I've seen a Chinese guy doing that before, and his robot car can self-balancing even a bottle of water placed on top, then he use a controller to make the car move around. He upload the video in youku.com - the chinese youtube. I've stunned and hope to copy what he has done.