Balancing Robot (Arduino)

PLEASE NOTE: This project is in its infant stage. The code has little to no documentation and I have not uploaded the CAD files for the frame.

Over Winter break (2013), my friend David Ingraham and I built a balancing robot. It operates on the same principles as the popular Segway two wheeled transportation system. That is, it accelerates and decelerates the wheels in order to keep the entire system upright.  We used a 3D printed frame along with some components I had lying around. The code incorporates a PID controller and a Kalman filter. The PID controller code used was from the Arduino PID Library and the Kalman filter was based off this project. The primary purpose of the project was to learn how to write and use a Kalman filter. The code is still under development, and we will be upgrading the drivetrain soon brushed DC motors and encoders). See the video at the bottom of the post for more information.

The hardware:

1 x Arduino Mega 2560

1 x USB host shield (for communication with a PS3 controller. Is not necessary. For information see this post)

1 x Bluetooth dongle (for communication with a PS3 controller. Is not necessary. For information see this post)

2 x Parallax continuous servos

1 x Dual Use Gyro and Accelerometer Sensor Board (This consists of an ADXL345 3-axis accelerometer (get it at Sparkfun) and a ADW2207 analog gyroscope, both of which can be purchased separately. Any analog gyroscope can be substituted for the ADW2207, but new code would have to be written (or found) in order to use a different accelerometer).

1 x Bluetooth transceiver (for telemetry)

1 x 2S (2 cell) lithium polymer battery

1 x Lipo battery low voltage alarm

3 x Potentiometers (for tuning PID controller)

1 x Frame of your choice. Should be relatively tall.

1 x Assortment of zip-ties

1 x Assortment of wires and jumpers

1 x Wheels of your choice. Should have a diameter of approximately 7 inches.

Frame with servos and electronics:2013-12-30 11.19.43

Holes in frame allow zip-ties to hold servos in place. Accelerometer and gyroscope are mounted between the servos:
2014-03-10 16.24.21

Arduino and shield close-up:
2014-03-10 16.24.07

Battery and tuning potentiometers:
2014-03-10 16.23.57

Power harness:
2014-03-10 16.25.58

2014-03-10 16.23.51

The code:

As zip file containing the Arduino and Processing code can be found here.



8 thoughts on “Balancing Robot (Arduino)

  1. Hi Mukut,

    Correct, the MPU6050 has a built in state estimator. You can get rid of all code for reading the gyro, reading the accelerometer, and doing the Kalman filter calculations. Instead, in PID.ino, rather than setting Input = kalmanOutput2, set Input equal to the angle state estimated by the MPU6050 built in attitude estimator (the attitude angle that lies in the plane parallel to the robot wheels). As far as I can remember, that’s all you need to do. Quite a large portion of the code was related to the tasks that can be removed, so the code should get much simpler. Please let me know if you have any questions. I’m sure a lot of other people would be interested in using the MPU6050 for similar projects, so it would be great if you could post your code somewhere if you get it working.



  2. Hello friend, I am using a MPU6050 so I think that I don’t need the Kalman Filter. Only the PID loop is enough. And I am using DC Geared Motors so what change do I need to do in the code?

  3. Nice!!!
    You have a lot of potential! Don’t study Control Theory. You already are competing with the graduate students that study controls. 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s