Files for RED, the balancing robot

Nov 7, 2014 Update – I made a public repository in GitHub to hold all of the files for RED. You can find it here:

CAD Files

RED was designed in SolidWorks. I know a full license of SolidWorks is expensive, but it is the most widely used tool for designing robots. If you are a student, you can get an educational version of SolidWorks for about $200, which is very reasonable.

This version has some a few problems:
– The belts don’t turn because the pulleys are fully defined.
– The design as a whole is under defined.

Despite these problems, you can still use the drawing to see what parts are needed and how the parts fit together. I’ll fix the problems when I get time.

In case you don’t have aceess to SolidWorks, here are some images of the important parts:

pulley lower 1

pulley lower 2

pulley upper 1

pulley upper 2

A SolidWorks pack and go file is available in my GitHub repository:

Arduino Files

The code for RED is contained in two sketches: robot.ino and motors.ino. Most of robot.ino is related to initializing the MPU-6050. I should really move it to a separate file. Most of the motors.ino file is for reading the wheel encoders. I am using an interrupt on each edge of both phases of the quadutrature signals for each wheel. That’s a lot of interrupts. The Arduino Due can keep up. I don’t know if a slower Arduino, such as the Uno, can keep up with so many interrupts. This is one reason I chose the Arduino Due.

In addition to the two sketches, I used the following libraries: I2Cdev, MPU6050, PID_v1, and PS2X_lib. The PS2X_lib did not work with the Arduino Due, so I made some modifications to make it work. One thing I discovered is that a lot of libraries are not yet ported to the Due. If you choose a Due, be prepared to make changes to code that works for all the AVR based Arduinos. Thus, I would not recommend the Due for a beginner.

The Arduino files are available in my GitHub repository:

Parts List

Item Vendor Part Number Qty Unit Extended
1 6″ Heavy Duty Wheels ServoCity 595610 2 9.99 $ 19.98
2 24″ Aluminum Channel ServoCity 585466 1 15.99 $ 15.99
3 12″ Aluminum Channel ServoCity 585454 2 9.99 $ 19.98
4 9″ Aluminum Channel ServoCity 585450 2 7.99 $ 15.98
5 6″ Aluminum Channel ServoCity 585466 2 5.99 $ 11.98
6 Pinion Pulley 16T 0.25″ ServoCity 615378 4 8.99 $ 35.96
7 Shaft Coupler 0.25″ to 6mmServoCity 625106 2 4.99 $ 9.98
8 Bearing 0.25″ ServoCity 635042 6 0.995 $ 5.97
9 Motor 37D 30:1 Pololu 1443 2 39.95 $ 79.90
10 Motor Mount ServoCity 555128 2 4.99 $ 9.98
11 Flat Single Channel BrackeServoCity 585468 2 1.29 $ 2.58
12 Hub Spacer 0.5″ ServoCity 545384 2 1.59 $ 3.18
13 Shaft Clamp Collar 0.25″ ServoCity 625102 4 2.495 $ 9.98
14 D-Shaft 0.25″ x 1.75″ ServoCity 634066 2 1.39 $ 2.78
15 Shaft Spacer ServoCity 633105 4 0.14 $ 0.56
16 Aluminum Clamp Colar 0.25″ServoCity 6157K12 2 4.99 $ 9.98
17 D-Shaft 0.25″ x 2.25″ ServoCity 634070 2 1.59 $ 3.18
18 Hub Adapter 1.5″ x 0.770″ ServoCity 545388 2 4.99 $ 9.98
19 Clamping Hub 0.25″ x 0.770ServoCity 545588 2 7.99 $ 15.98
20 Socket Head Screw #6 x 0.2ServoCity 632106 1 1.69 $ 1.69
21 Socket Head Screw #6 x 0.3ServoCity 632110 1 1.89 $ 1.89
22 Timing Belt XL 17″ ServoCity B375-170XL 2 4.95 $ 9.90
23 Arduino Due SparkFun 11589 1 49.95 $ 49.95
24 Dual MC33926 Motor Driver Pololu 1213 1 29.95 $ 29.95
25 MPU-6050 Breakout SparkFun 11028 1 39.95 $ 39.95

Other Misc Parts
#6 Nuts
Hookup wire
PS2 Remote control


Balancing robots have been around for many years. The first balancing robot I encountered, nBot, was created by David Anderson. His robot remains one of the best even after many years. He describes his robot on his website:

Back in 2010, Kas started a thread on the Arduino blog called Balancing robot for dummies. This was around the same time as I was building my first balancing robot, Blinky. I didn’t use an Arduino in Blinky, but I learned a lot from that thread. It is still an excellent source of information for building a balancing robot.

The only way that I was able to create the code for RED in only a few weeks is because of the work of others, particularly those who created open source Arduino libraries, such as Jeff Rowberg’s I2Cdevlib,¬†Brett Beauregard’s PID library, and Bill Porter’s PlayStation 2 controller library.¬†Many thanks!

24 comments to Files for RED, the balancing robot

  • Red was lookin good on 10-29-2014 and keep up the efforts. Impressive.

  • Bernd

    Very impressed,I am in the process of building my own

  • Griswald Brooks

    Did you use the encoder feedback in your PID algorithm?

    • Osman Eralp

      Yes, I used the derivative of the wheel position as a damping term in the PID equation. I’ll get the files posted as soon as I can. Please check back in a couple of days.

      • Griswald Brooks

        But I mean did you use the encoder feedback to estimate the angle of the beam or just for motor control?

        • Osman Eralp

          Just for motor control. The tilt angle was measured using the MPU-6050 gyro accelerometer combination. The encoders on the motors I used are incremental encoders. They cannot be used to measure a tilt angle.

          • Griswald Brooks

            So then did you use a Kalman filter or a Complementary Filter for your estimator?

            • Griswald Brooks

              Sorry to be grilling you for so much information, but we were also in the competition, and we work in a robotics lab and we were having more trouble than expected getting the bot to stabilize.

            • Osman Eralp

              Neither! I used the I2Cdevlib. One of the advantages of the MPU-6050 is that it can fuse the sensor reading inside the chip. The I2Cdevlib gives you access to the DMP. In the future, I plan to switch to an ST gyro, so I would need to implement my own sensor fusion. When that happens I will plan to the the FreeIMU library which I am porting to an STM32 microcontroller.

  • I’ve posted it on my website about robotics

    Will the robot Red have Home page like Blinky? )

    Fine robot!

  • Is the arduino code available yet? Red is pretty cool. Can red be cool or should I say Red is red hot?


  • Bob Clark

    Thanks for posting your files and resource materials! I also made an attempt for this contest, but this was my first balancing robot and I couldn’t get it tuned in time. I am really looking forward to seeing how Red works and hope I can learn enough to get mine working, also.

    • Osman Eralp

      I spent as much time tuning the PID parameters as I did writing the rest of the code. It’s a lot of trial and error. I wish there was an easier way!

  • Thanks for posting your build files. Really cool to see how you did it. I’ve been toying around with making our little furry robot into a two wheel balancer.

  • elad

    it is great project.
    i download the arduino code from your link and i wonder if you can provide also the wire conection for the Arduino to all other devices.
    waiting to your reply

  • Jason

    Do you have a wiring diagram for this project?

  • Mike

    I see on Github you have a robot.ino and motors.ino. Do you have two microcontrollers? I didn’t see where maybe robot.ino called motors.ino, but I only read through the code once.

  • Martin

    Hi, great work.
    I am trying to do the same thing, but my robot wont stabilize for more than 5 seconds at best. I think it is because the motors only work for larger pwm value, (0-255), it only turns at 80. Do you have any recommendations? I have tried with many different dc motors, but no succes.

    • Osman Eralp

      Ya, turning on at 80 would result in too large of a dead zone. It would be difficult to compensate for that. You are probably alternating your motors between drive and coast. Try alternating between drive and brake.

  • riadh

    hello sir am going to build an self balancing robot with mpu6050 gyro and dc motors first i let it blancing that i wanna let the robot go forward and backward coulde you help me ??

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>