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.
Step 1: Hookup
Things we use in this instructables:
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.
Step 2: Debug
The stabilizer shield demo download link:
Only upload the Stabilizer.ino to UNO, I2C.ino is a support file when Stabilizer.ino compile.
After we upload the demo to Iteaduino UNO, the rest work is to debug the hardware and software problems.
Now we will list some common problems we meet when we are making this project.
Stabilizer shield has been test strictly, so seldom hardware problems occur. But there are some tips.
1. The attitude data read normally, but motor doesn’t work. If this problem occurs, you’d better check the motor wire connection order. Please see the picture to learn what exactly each motor pin is.
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 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.
Main Contributor: Yun Li, hardware engineer from ITEAD studio.
Participated in the