Home > Arduino, Balanduino, Bluetooth, Guides, TKJ Electronics > Full size DIY Balancing Robot

Full size DIY Balancing Robot

It has been quite a while since my last blog post, but I am finally ready to reveal what I have been working on the last months. Ever since I made my first balancing robot: http://blog.tkjelectronics.dk/2012/03/the-balancing-robot/ and the Balanduino I wanted to build myself a full size version which I would be able to ride just like a regular Segway.

Finally I decided to make one together with a good friend of mine Mads Friis Bornebusch in a course at my university DTU (Danish Technical University/Technical University of Denmark).

Video demonstration

Mechanical construction
The main frame is an aluminium checker plate that is 500x360x7mm which the motors are bolted onto. This width was chosen, so it would be able to go through a normal door opening. The motors used are two MY1020Z 500W, 24V, 12.6Nm brushed DC motors.

I ordered them from Germany, as I needed them right away, but you should be able to get them much cheaper by ordering them directly from China.

Below is an image of the aluminium checker plate after we have drilled the holes for the 8mm steel bolts. Note that these are countersunk, so they are flush with the surface. I would recommend using lock nuts to ensure that the bolts will stay in place – you can also use Loctite instead.

Aluminium checker plate - ready to mount the motors

Motor with hub

Countersunk bolt

Motor bolted onto frame


After that we drilled four countersunk 10mm holes. These are used to bolt two SKF Y bearings to the middle of the frame. Inside these are mounted a 300mm ½″ steel water pipe with some custom made fittings for the 25mm bearing.

Custom fitting on the pipe

Finished assembly


In one end is mounted a 10kΩ potentiometer which is used to tell the position of the steering rod. It is mounted to a hole in the endcap secured using some epoxy. The potentiometer is then bolted to a square aluminum bracket secured to the main frame using screw holes we made.
In the other end is mounted a 90° bracket – note that we have welded a solid iron rod inside the rod, at the bracket, as it broke off during testing. All pipes are just ½″ steel water pipe that you should be able to get at your local hardware store.

Potentiometer for steering mechanism

Potentiometer for steering mechanism

90° bracket

90° bracket

Mounted to the other end of the 90° bracket is the steering rod. This is 1050mm long with a T-bracket in the other end. Two 180mm pieces with an endcap are then used as the handlebar. I decided to put some tape used for bicycles around the handlebars to give them a more comfortable grip.

Two springs from an old washing machine are connected from the edge of the frame to 230mm up on the steering rod. This ensures that the steering rod will always center itself. The hose clamps are there to ensure that both are equally tight.

Spring mechanism

Spring mechanism

On the handlebar is also a deadman button which is connected to the reset pin on the motor drivers. This needs to be held in while riding it and will prevent the motors from turning if it is released.

Deadman button

Deadman button

In order to mount the wheels onto the motors we made a custom motor hub.
Note that the cylinder going out from the hub is meant to add support, as it will fit around the motor shaft. We did this as we were worried that the load might damage the gearing inside the motors.

The 3D-drawings are available at the Github repository.

Finished motor hub

Finished motor hub

The electronics

The heart of the main board is a 16MHz Arduino Pro Mini running at 5V it reads a MPU-6050, 3-axis accelerometer and gyroscope in order to estimate the angle. This is done by reading the accelerometer and gyroscope at 500Hz. The measurements are then fusioned together using the Kalman filter I wrote some time ago.
It then uses the angle as an input to a manually tuned PID-controller which will output the PWM value needed to keep the robot balanced.

A Bluetooth SPP module is connected to the microcontroller as well. This allows it to communicate with an Android phone via Bluetooth using an application I have written.

Two inputs on a LM324 operational amplifier is used as a buffer. This buffers the signal coming from the deadman switch. This is needed as there is a 20kΩ pull-up resistor on each of the motor drivers reset inputs. The diode D1 is there to ensure that the microcontroller will never be able to drive the signal going to the reset pins on the motor drivers high.
Furthermore one input is also used to buffer the voltage measurement read from the batteries.

One input is used as a inverted amplifier in order to amplify the signal coming from the potentiometer connected to the steering mechanism. The 10kΩ potentiometer is used to adjust the output until it is roughly 2.5V.

A buzzer is also connected. This is used for basic feedback, as it will beep when the robot is turned on and will be turned on in case the battery voltage gets too low.

Headers for signal going to the two motor drives are also available.

Main board schematic

Main board schematic


Below is a picture of the finished PCB. Note that the MPU-6050 is mounted using some double sticky foam – this is to reduce vibrations.
The final PCB can be found at the following link: https://github.com/Lauszus/BalancingRobotFullSize/tree/master/PCB.

Etched PCB

Main board almost done


In order to control the two motors you will need two high power motor drivers. We decided use the Pololu High-Power Motor Driver 24V/23A. Each motor driver is rated at 23A continuous current without a heatsink. We have mounted heat sinks on the motor drivers to ensure that they can handle the current, as the motors have a peak current of 26.7A according to its specification. In this setup the motor drivers does not even get hot.

Motor driver front

Motor driver back


In order to control the motors you simply apply a PWM signal to PWMH and control the direction using the DIR input. This allows you to easily control the motors with only two pins. Note that PWML is not used in the final setup. Furthermore the motor driver has two “Fault flag indicators” labeled FF1 and FF2. These will be drive high in case of a fault. The motor driver can be reset by driving the RESET pin low – this is done if the deadman button is released.
Finally it also features a current sense output. The current sensor is powered by soldering a jumper on the PCB – more information can be found at the product page.

I decided to use this motor driver, as I can control it directly using the I/O on the microcontroller instead of using a serial interface which is also used on some motor drivers. I did not want to use this, as the serial communication is slow compared to just controlling it directly using the pins on the microcontroller.

Also note that the microcontroller and motor driver are both grounded via the same battery. If you intend to power the microcontroller from a separate battery. You will need to solder a wire to GND as well.

Below is a picture of the motor drivers before and after we mounted the heatsink. Note that we cut away the heat shrink at the MOSFETs and applied some cooling paste before mounting the heatsink to the motor drives using some long bolts.

Motor drivers

Motor driver with heatsink


To power everything we decided to use three 6S LiPo 3000mAh batteries in parallel giving a total capacity of 9000mAh.
I have not actually made an endurance test, but they seem to last a pretty long time – it lasted from 10am to 4pm at a conference with only two batteries.

As the maximum voltage of the LiPo batteries is 25.2V (4.2V per cell) you can not simply connect the batteries directly to the VIN/RAW pin on the Arduino Pro Mini. Instead we are using a LM2596 step down switch mode regulator in order to step down the voltage to 8V. This is then stepped down by a 7805 5V linear regulator which is located on the main PCB.

It is very important that all you apply a good amount of solder to all your connections, so they can handle the high power needed. Below is a picture of the custom parallel cable I made. This was done by first applying solder to a 10AWG wire. Three 12AWG wires were then soldered to one end and a wire was wrapped around them in order to keep them in place. The same thing was then done for the other side. Finally a wire was wrapped around the entire joint and solder was applied. This will require a good soldering iron and a large tip in order to reflow the entire soldering joint.

Before connectors and heat shrink

Finished battery cable


Below is a picture of the three batteries connected to the parallel cable I made. The three female XT60 connectors are connect to the two motor drivers and the last one is connect to the LM2596 switch mode regulator.

Batteries with parallel cable

Batteries with parallel cable

The finished PCB is then mounted inside a electronic enclosure on the bottomside of the robot. It is mounted using double sided sticky foam in order to reduce the vibrations to the MPU-6050.

Electronics mounted inside enclosure

Electronics mounted inside enclosure


Robot bottom side

Robot bottom side


Robot overview

Me driving the robot


The code

Flowchart of the code

The code was inspired by the Balanduino code: https://github.com/tkjelectronics/Balanduino and the basic structure is basically the same. It is written in C/C++ using some libraries and functions from the Arduino platform – these are the Wire (I2C) library and the timekeeping functions millis and micros.

A flowchart of the main loop of the code can be seen to the right.

At first the microcontroller is powered on by connecting the battery to the LM2596 regulator. Then it initializes an input which makes it able to read the current status of the deadman button. After that it sets the pin connected to the buzzer to output and reads the different values from the EEPROM including PID-values, Kalman values etc. If it detects that the EEPROM values should be restored (if the structure of the values have changed due to a value being added or removed to the configuration struct) it will turn on the buzzer for 1 second and proceed afterwards.
The next step is to initialize the UART (Universal asynchronous receiver/transmitter) at 57600 baud rate, the pins connected to the motor drivers and configure the MPU-6050 at a sample rate of 500Hz and set the accelerometer ±2g and the gyroscope range to ±250deg/s. It then calibrates the steering and finally turns on the buzzer for 100ms and initializes the timers it uses for timekeeping.

Now the main loop is running. As it can be seen on the flowchart it will run forever until power is removed. The first step is to check if any of the diagnostic pins on the motor driver are high, this means that there is some kind of fault. If that is the case it will turn on the buzzer to alert the user that something is wrong. The next is to check if any new IMU data is available. The MPU-6050 is configured so it will hold its INT pin high if there are new measurements available.
If there is no new data from the IMU it will check if any data is available at the serial port. This is used to configure PID-values, Kalman values, the amount of turning etc.
If new measurements are available it will read the sensors and calculate the angle using the Kalman filter. Then it reads the steering input from the potentiometer and checks if the robot is upright and the deadman button is pressed. If that is not the case it either means that the robot has fallen over or the user has let go of the button. In this case it will turn off the motors. If not it will calculate new PWM-values for the motors using a PID-controller.

To turn the robot a value is simply added to one motor’s PWM value and subtracted from the other. This value depends on the value read from the potentiometer connected to the steering rod. The specific code can be found inside PID.cpp.

Finally the battery voltage is checked. If the battery is too low it will start the buzzer. After this final step it will go back to the start of the loop.

One key difference between this hardware and the Balanduino is that there is no encoders on the full size version, so it is actually not possible for it to balance on its own.
This also makes it harder to estimate the speed of the robot. This is instead estimated by integrating the PWM value. This is used to tilt the robot backwards as the speed increases to prevent it from falling over.

To control the robot you simply lean forward/backward which will make the robot start to travel in the given direction. You tilt the steering rod to either side in order to turn. The full source code is available at Github: https://github.com/Lauszus/BalancingRobotFullSize.


Android application

In order to easily tune the PID-values and get data from the robot I wrote an Android application.

Below is a picture showing an overview of the Android application.

At the first screen the user is able to see the current draw of the motors, the turning value, battery level, run time and finally the PWM-value on a custom speedometer.

The next screen allows the user to adjust the PID-values, target angle and adjust how fast the robot should be able to turn.

The third screen shows the current position on a map. The position is obtained using the built-in GPS module on the Android device.

The fourth and final screen shows a graph of the current angle calculated using the accelerometer, gyroscope and the angle estimated using the Kalman filter. It also allows the users to adjust the Kalman filter coefficients.

The communication between the microcontroller and Android application is done via Bluetooth. In order to make sure that the data is parsed properly a protocol for this was implemented. It consist of a constant string header, then one byte to indicate the command and then one byte indicating the length of the data to follow. After the data there is a simple checksum. This checksum is calculated by taking XOR of each byte in the message excluding the header. The full serial protocol can be seen in the source codes: Protocol.cpp, BluetoothChatService.java and BluetoothProtocol.java

The phone is mounted on a smartphone dock that is simply zip tied to the steering rod.

Application screenshots

Application screenshots


Further documentation

Part of the assignment was to write a very brief six pages paper. The paper can be found at the following link: GRP12_AUT2_Two_wheeled_robot.pdf. I would really recommend you read through it if you are new to the concept of balancing robots as it explains the basic of how two wheeled balancing robot works and some of the theory behind it.

Furthermore we also did a presentation. A link to the poster is available as well: POSTER_GRP12_AUT2_Two_wheeled_robot.pdf

Future improvements
The final product turned out just as we planned, but there is still room for some improvements that we left out due to time constraints.

First of is to replace the current tires, as they are made of solid rubber. I believe it would help replacing these with some pneumatic tires instead in order to reduce vibrations on rough terrain.

Furthermore I would like to mount some encoders, so it would be able to balance on its own. This would allow me to remote control it! This would also allow me to measure the speed of the robot precisely instead of just integrating the PWM-value. Which should make it travel a bit smoother.

If I had to built it again I would consider making a slot for the steering rod, so it did not land on it if the robot fall over. It would also be nice if I could take the steering arm off in order to ease transportation.

I have also considered replacing the deadman switch with some kind of weight enabled mechanism, so you did not have to hold in the deadman button while riding it.

An obvious improvement would also be to upgrade the motors as they are not nearly as powerful as the ones on the Segway – these are 1500W each. This would enable it to handle rough terrain better and allow it to go faster. I would like to try some hub brushless motors so the ride could be as smooth as possible.

Finally I still need to mount the batteries and motor drivers inside some enclosures in order to protect them from water and physical damage.


If you got any questions or comments. Please do not hesitate to leave them below. Also if you want a picture of some details on the robot just tell and I will upload it!

Part list

Update 9th Juni 2015
I would also recommend the following motor driver as well: 30A 5-25V Single Brushed DC Motor Driver.

Update 8th November 2015
A 3D model of an enclosure for the new motor driver (see update above) is now available at the Github repository. I printed this on my Prusa i3 3D printer using PLA, a layer height of 0.2 mm and an infill of 20%.

Motor driver enclosure bottom

Motor driver enclosure lid

  1. Anonym
    August 26th, 2014 at 07:02 | #1

    Jeg er dybt imponeret. 🙂
    Hvor svært kan det være at efterligne en Segway?
    Håber at I får lidt mediedækning for det er den slags der kunne motivere andre unge til at lave lignende “skøre” ting.
    Godt gået guys.

  2. August 26th, 2014 at 07:13 | #2

    Haha ja præcis 😉 Mange tak!

  3. tirupathi reddy
    August 26th, 2014 at 09:18 | #3

    Hi, nice project, for the given battery specification, how much distance we can travel.
    Thank you

  4. August 26th, 2014 at 18:11 | #4

    @tirupathi reddy
    I’m not sure, as I haven’t tested it, but my guess would be about 10km. But you could easily use more batteries if you like.

  5. roscoopc
    September 8th, 2014 at 21:57 | #5

    Good work! Whit the motor datasheet (450 rpm, 6,7:1 gear ratio) and the wheel diameter I have calculated a maximum speed slightly higher than 4 km/h. It’s correct? If the robot has so much torque is possible enlarge the wheels…
    Ps I’m planning my robot 😉

  6. September 8th, 2014 at 22:04 | #6

    No we have measured a maximum speed of approximately 15 km/h 🙂

  7. kang
    September 21st, 2014 at 15:36 | #7

    hi, Good work! i’m studying on control system and i have studied the segway’s mechanism.
    I have a question about your work.
    Does your wheel system have tilting motion?
    i can’t know the solution of my question in your video.
    please, let me know.

  8. September 21st, 2014 at 20:33 | #8

    What exactly do you mean by tilting motion? The wheels are bolted directly to the motors.

  9. scphil
    September 29th, 2014 at 21:31 | #9

    Hi, ever thought of doing a kick start for the full size? I am looking to see if there is any way to build this for disabled (sitting position)? I assume it would work as long as there is adequate balancing? Any idea what would happen with stairs ? / curbs ?

  10. September 29th, 2014 at 22:13 | #10

    We haven’t any specific plans to do a Kickstarter, but you can never say never 😉

    You can already buy a kit to convert a regular Segway to a balancing wheelchair: http://www.allychair.com/. I believe it can handle smaller curbs fine, but differently not stairs.

  11. tk
    October 1st, 2014 at 11:43 | #11

    Hi…. very fun project. could you tell me change this” Pololu High-Power Motor Driver ” in to DIY IR2184 driver….Thank you

  12. October 2nd, 2014 at 00:40 | #12

    Please post a link to the exact driver you are talking about?

  13. tk
    October 2nd, 2014 at 05:40 | #13

    Hi….this link is use ir2184 driver …. http://www.open-electronics.org/discover-openwheels-electronics-and-test-it/
    Because in my cities easily purchase ir2184 .
    Thank you for your answer.

  14. October 4th, 2014 at 08:41 | #14

    Yes that MOSFET seems to be fine.

  15. Thamanoon
    October 18th, 2014 at 06:16 | #15

    Hi, Thank you for your tutorial. I will make a new one with stm32f3discovery board. Can I use android appication to control stm32f3discovery via bluetooth?

  16. October 18th, 2014 at 06:17 | #16

    What do you mean by control? My application simple sends out a data via Bluetooth which are then received on the UART port on the ATmega328P.

  17. October 21st, 2014 at 20:47 | #17

    I decided to build balancing robot with heart from this tutorial, but with completly different body. Posts are written in polish, but I’m also publishing a lot of photos, so I think that will be understandable :). Maybe someone will be inspired with that. Visit: https://www.facebook.com/ZbLaB

  18. October 22nd, 2014 at 03:41 | #18

    Thanks for sharing ZbLab 🙂

  19. Brice Daunay
    October 30th, 2014 at 20:53 | #19

    I am very impressed by you machine . I have been looking for a long time for a DIY. Segway
    I will be interested in building a more powerful machine with you.
    I have an extensive knowledge in composit carbon fiber and will be keen in building a frame and a houssing for the new machine to host all yor mechanical and electronic parts
    I have reserch some more powerfull electrical wheels 1000 to 2000 w with brshless motos and controleurs. http://www.goldenmotor.com/
    would you be interested

  20. November 1st, 2014 at 01:46 | #20

    @Brice Daunay
    That sounds like a great plan! I have send you an email 😉

  21. scampa123
  22. December 23rd, 2014 at 18:43 | #22

    By reading the description of the encoder it is clearly a two-phase octogonal encoder with AB output. This means that you could attach and use this with the Balanduino and balancing robot code without any modifications, as this is the same we use.
    So if you can get this encoder attached to your mechanical mount it should work.

    And that is correct, you will need an encoder for each motor!

    Best regards
    Thomas Jespersen

  23. Rafael Caballos
    January 13th, 2015 at 20:23 | #23

    Your work is impressive. It is one of the simplest segway clones I’ve ever seen. I’d like to make a similar one in our school. I already have motors (although less powerful, around 200W) wheels, arduinos, mpu6050, and bluetooth. But the motor drivers you say are a bit expensive for me. I found cheaper ones in ebay but I do not know if I can use them. Could you please tell me if I could, for example:
    or this:

    Thank you very much for your help.

  24. January 14th, 2015 at 11:21 | #24

    @Rafael Caballos
    Thank you for your kind words. Unfortunately I don’t think 200W is enough. You should aim for at least 350-400W.

    You can always try to use them, but in my experience motor drivers from eBay are often much less powerful compared to their claimed specs.

  25. Rafael
    January 14th, 2015 at 23:25 | #25

    Thank you for your help and sorry for the email. I did not pretend to be impatient.


  26. January 15th, 2015 at 13:07 | #26

    No problem. Don’t hesitate to contact me again if you have any further questions. I’m on vacation currently, so that is why it took me longer than normal to get back to you 🙂

  27. scampa123
    January 17th, 2015 at 03:39 | #27

    Hi Lauszus,

    I was wondering what pin 8 on SV3 is connected to on the motor controller board. From what I can tell you were making the same connections on both motor controllers, and SV3 is one of the connections from the motor controller to the main board. SV3 has the 8th pin which says VBAT. I also see that SV4 only utilizes the 7 pins…

    So what is VBAT on SV3 on the main board? Is that something from the motor controller board??


  28. January 17th, 2015 at 10:43 | #28

    VBAT is connected directly to the battery. It is marked V+ on the motor driver: https://www.pololu.com/product/1456.

    It is used to monitor the battery voltage – as you can see VBAT is connected to a voltage divider and then connected to the microcontroller (see VSENSE on the schematic).

  29. scampa123
    January 17th, 2015 at 13:55 | #29


    Thank you for the quick response!!

  30. January 27th, 2015 at 18:40 | #30


    do you make board from this project? I made one by myself, “segway” runs, but I have problem with android application (or data transfer via BT) – and I can’t find why. Please, let me know, when you finish your board.

  31. Vijay
    February 9th, 2015 at 12:35 | #31

    Thanks for this Tutorial – I am going to replicate the same for my learning – Do you suggest me any changes

  32. vijay
    February 9th, 2015 at 15:13 | #32

    This model is having a extra rod to drive when compared with balduino….how does this self balance when there is a extra weight one side

  33. February 9th, 2015 at 16:53 | #33

    The design files are available here: https://github.com/Lauszus/BalancingRobotFullSize/tree/master/PCB.

    I would recommend that you find another motor driver, as it has actually burned for the second time now.

    You can simply adjust the variable called targetAngle in the code. This was also how I mounted a GoPro on the Balanduino: https://www.youtube.com/watch?v=p2ip31PooXQ.

  34. vijay
    February 10th, 2015 at 13:46 | #34

    Thanks Lauszus for the link. Are there any more notes in connecting the electronic circuits used for this machine…..Iam a s/w engr but a starter in learning arduino

  35. joel leon
    April 9th, 2015 at 10:17 | #35

    Hello Kristian,
    We have just built the structure of our segway clone and are trying to go with the electronics. We have built the main board and have all the components, but face a problem: with just the schematics some components are difficult to find where they go. Could you have some picture (apart from the picture in this page) that shows us where to solder the components?

    Thank you for your help and congratulations for your great work

  36. April 9th, 2015 at 12:49 | #36

    Unfortunately no. You need to figure it out yourself 😉

    @joel leon
    All the PCB files are available at the Git repository: https://github.com/Lauszus/BalancingRobotFullSize/tree/master/PCB.

    You need Eagle to open them: http://www.cadsoftusa.com/.

  37. Joel
    April 10th, 2015 at 11:04 | #37


    Sorry to read that.
    Anyway, in the picture of the board with the components, there is a blue component with square shape on the top right corner which I can’t identify in the schematics. Is it a potentiometer? The only one I see in the schematics is R3, a 10K potentiometer ad I think it is the one attached to the steering rod. Am I right? Could you tell me if it is a different component?
    Thank you

  38. April 14th, 2015 at 15:16 | #38

    Why are you sorry? All the PCB files are available?
    Yes that is a potentiometer.

  39. May 7th, 2015 at 14:27 | #39

    Where did you get your nice wheels ?

  40. May 7th, 2015 at 17:58 | #40

    I got them from an old mobility scooter, but you can also find similar wheels online.

  41. joel
    May 19th, 2015 at 08:15 | #41

    We are going ahead with our segway clone. At this moment we have a problem with the connection of the Pololu motor drivers. In the pictures I can see 7 wires connected, and in the schematic motor 1 has 7 and motor one has 6 wires connected, but the name of the wires are not the same, for example, wire 2 is not connected, while in the picture it seems that they are all continued, without gaps. Another problem we have is that it seems the GND is not connected between the main board and the Pololus. Can you clarify us these terms, please?
    Thank you very much

  42. May 23rd, 2015 at 17:14 | #42

    The reason why one of them has 6 pins connected and the other has 7, is because VBAT is connected to one of the motor drivers. This allows us to monitor the state of the battery.

    They are all sharing the same GND as they are all connected to the same battery. That is why a connecting to GND is not necessary.

  43. Willie
    July 1st, 2015 at 01:03 | #43

    Hey, I’ve noticed there is a VBAT connection to be made to the driver, is it required? Also what pin on the driver is it, because none have that label, my guess is either VCS or V+? Or is it something different?

  44. July 3rd, 2015 at 22:27 | #44

    No it is not required, but I would recommend monitoring the battery voltage in another way then like to connecting a battery alarm: http://hobbyking.com/hobbyking/store/__18987__HobbyKing_8482_Lipoly_Low_Voltage_Alarm_2s_4s_.html.

    VBAT on the PCB corresponds to V+ on the motor driver.

  45. Willie
    July 13th, 2015 at 03:23 | #45

    Alright, I’m probably going to sound like an idiot, and I’m probably missing something that’s really obvious. But I’ll explain the situation. I’ve wired up everything exactly as you did. I’ve uploaded the arduino software, which wasn’t very straight forwad(there were compiling problems,and serial adapter problems). Fyi, I have arduino experience I’ve made a 3d printer from scratch with one. And I made sure my board was in the exact same orientation as the way you did it. And yet, I can connect the batteries(which are charged, I’m not that stupid). The arduino led will come on, the MPU-6050 led will come on, and the bluetooth module light will start blinking. I can connect to the module with my phone and make the bluetooth light go solid. But that’s it, there are never any beeps from the buzzer and the motors never make any noise or move at all. And yes I am depressing the deadmans button and I have the robot held in a vertical position. Any help would be appreciated. Thanks

  46. July 16th, 2015 at 23:29 | #46

    If there is never any beeps from the buzzer, then it means that it failed somewhere doing initialising.

    Is there any output in the serial terminal?

  47. Willie
    August 17th, 2015 at 03:59 | #47

    This is my serial output:

    i2cRead fail
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cReaNÆC/`1hh”neÀG@? îCn`àì)???zq?Ì)??Q?:R? îC.“Ì)???zq?Ì)??QIgHWNË.`0`h#NeÀc`H)”neÀì!??-?zq?Ì)???:P? îCn`Àì)???zq?Ì)???:P? îCn“ì)???zq?Ì)??QCgHWNK.“Ì)???:ÐH(“ne

    The string was a lot longer than that, I just cut off about 95% off it. It just keeps putting out a a string of “random” characters. I say “random” because it seems to have some what of a pattern just looking at it.

    Fyi, I’m using an Offficial Arudino USB2SERIAL to connect the board to my computer. It uses 602 bytes (29% of the memory) when uploaded, is that correct? I’ve set the board as “Arduino Pro or Pro Mini”, Processor “ATmega328(5v, 16MHz), and Programmer “AVRISP mkII”. Also I’ve tried this from a completely different computer and got the same results.

    Any ideas or help would be appreciated, thanks.

  48. August 17th, 2015 at 14:05 | #48

    Make sure you have set the baud rate to 57600 in the serial monitor.

    Also those errors mean that it couldn’t find the sensor.

  49. Willie
    August 17th, 2015 at 23:27 | #49

    After correcting the baud rate from 9600 to 57600, the serial output is just:

    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2
    i2cRead failed: 2

    Which keeps on going forever.

    When you say “Also those errors mean that it couldn?t find the sensor.” what sensor exactly are you referring to? Thanks

  50. August 17th, 2015 at 23:39 | #50

    How have you connected the MPU-6050? Are you sure that you are using the right address? By default it is set to 0x68: https://github.com/Lauszus/BalancingRobotFullSize/blob/0cb9cb50e50909b8e86c9eeb608befbfa4238936/IMU.cpp#L30 as it assumes that AD0 is pulled low on the MPU-6050. Try setting it to 0x69.

  51. Willie
    August 19th, 2015 at 05:31 | #51

    I have it connected the way the schematic shows. I have it plugged directly into the board as you did on yours. I even tried a second MPU-6050 in case it was faulty but it still has the same problem. I tried a second arduino pro mini I had sitting around, still same problem. I tried switching the address as you said in your last response, still the same problem. Any other ideas? Thanks

  52. August 19th, 2015 at 12:34 | #52

    Could you try to run the code found here: http://playground.arduino.cc/Main/I2cScanner?

  53. Willie
    August 20th, 2015 at 05:37 | #53

    I ran the code and the serial monitor just keeps saying:

    No I2C devices found

    Just an fyi, also put the arduino and mpu6050 on a breadboard to test it by themselves together without the rest of the circuit, but I still got the same result. So then I tried my second arduino pro mini and the other mpu6050 and still, the same result (in circuit or on breadboard). Do you think my MPU-6050’s could be defective or something, they were both bought at the same time?

  54. August 20th, 2015 at 09:17 | #54

    How have you connect the MPU-6050? It sounds like you haven’t wired it correctly.

  55. Willie
    August 21st, 2015 at 04:25 | #55

    So, while I can’t say yet if it operates completely properly yet(because I haven’t got any of the electronics mounted, and I haven’t made the vertical bar), I can say it works, it beeps, the wheels spun, for the short time I was shorting the deadman wires together. 🙂

    Now to explain what I had been doing wrong the whole time, and it does relate to my wiring as you thought in your last response to me. While breadboarding I had been connecting the SDA and SCL wires to pins 8 and 9 on the arduino, because in the schematic I saw them in the bottom left corner of the arduino board, it never crossed my mind to count how many pins were on each side of the board(physically and by the schematic). Then I found 4 holes in my Arduino that I never put pins in, cause the board never came with pins to do those holes, just pins for the two sides. So i just thought they were for something else that didn’t matter to me. Then i looked the main board and there were 4 holes in the same spot that I didn’t put headers on because I didn’t know I needed those. So after a little more soldering and taking I2CScanner off and putting the normal code back on, and it fired right up.

    It might be a few more weeks or so before I finish building it, but when I do, I’ll email you some pictures of it, because I designed it little differently than yours and I thought you might want to see it.

    But seriously, thanks for all the help Kristian, I know you didn’t have to help me, but you went out of your way to help, and it’s definitely appreciated. Thanks man

  56. August 21st, 2015 at 14:44 | #56

    Good to hear you got it working! Looking forward to seeing the pictures 🙂

    You’re very welcome. It’s nice to see other people find what I do useful!

  57. Willie
    August 22nd, 2015 at 02:16 | #57

    Ok, I hooked it up for a little bit today, I had someone hold it in the air while I tilted the board around(which isn’t currently mounted, I’m still try to figure out what kind of way I’m going to enclose my electronics). Upon powering it up, both motors immediately spun in the same direction to make it go forward if I remember correctly. So I tried to tilt the board some to slow them down and then reverse direction, but it was unresponsive, it just kept trying to go forward no matter what I did. After about 10 seconds of running, I heard a loud pop (like a firecracker) and then saw fire. One of the big black transistors on one of the motor drivers had fried and it was on fire for a few seconds. At that time one motor stopped, and the other was still spinning, so I disconnected the battery to kill the whole thing. Any idea what might have caused that? I’ll be looking over it more in depth sometime to see if there were any shorts in the wiring of that driver. But I don’t believe there are because I hot glued the driver wires after soldering them to help prevent shorting.

  58. August 22nd, 2015 at 15:25 | #58

    Have you mounted a heatsink? I have attached a heatsink to both my motor drivers. Alternatively you can use the following motor driver: http://www.robotshop.com/eu/en/30a-5-25v-single-brushed-dc-motor-driver.html which works quite well.

  59. Willie
    August 26th, 2015 at 18:40 | #59

    How exactly are those other ones wired, do they use less wires or more or the same. I see where to wire the main power and the motors you use the screw terminals, but where do all the signal wires get soldered to? Do you use the white connector? Or is any soldering done by the two test buttons? Thanks

  60. August 26th, 2015 at 22:16 | #60

    You connect three pins: GND, DIR and PWM and yes you use the white connector. Also consult the user manual: http://www.robotshop.com/media/files/pdf/md30cusersmanual.pdf.

    Since it do not have diagnostic wires and current sense functionality you can just leave them out.

  61. August 27th, 2015 at 18:45 | #61

    I had the same problem with burning transistors. You have to avoid turning on 500W motors without temporary construction that let stand wheels on ground. I think that in this situation (maybe I’m wrong) big current are floating across transistor and it causes fire. When wheels are on ground robot start balancing and everything is OK. Also for test you can connect little 24V motors to test without burning risk or reduce voltage to 12V.

    Have you got any troubles with chainging parameters in android app? When I’m trying to change something (with estabilished BT connection) by sliders, aplication are closing.

    Also my balancing robot doesn’t react on steering potentiometer.

  62. Willie
    September 22nd, 2015 at 04:04 | #62

    I haven’t got the app to pick up any readings. Haven’t used too much. But have you tried turning your gps on, it needs that to be on to run.

    The new drivers work good, they don’t catch fire like the others, lol. But, I’m having the same problem I discovered with the old ones, the motors just want to spin in one direction. After further investigation, I disconnected the drivers and just ran the board without them. By doing that I can read a constant 5.36v on the DIR and PWM wires that would run the drivers. There is no square wave on any of those 4 wires, just a constant 5.36v. Any ideas on the cause of that? Fyi, moving the board doesn’t effect it. Thanks

  63. September 30th, 2015 at 13:52 | #63

    Yes the new ones are better in my experience as well. The only downside is that they are physically larger.

    Hmm that sounds strange. Here is some code I used to test the motors: https://gist.github.com/Lauszus/54275ab9c83a29b9ba16. Can you try that and report back?

  64. Willie
    October 13th, 2015 at 03:48 | #64

    I haven’t tried the “Motor Spin Test” code yet. But I have figured things out a little more. Just an fyi I don’t have the wheels attached or the board attached(electronically it is, just not physically) I hold the board in my hand. But I can short the deadmans switch and it will power the wheels, and it seems like it wants to go full speed in either direction mostly. Until tilting past +45 or -45 degrees which kicks in the failsafe. There does seem to be a very very small area, what seems like less than 1 degree within being flat where I can have slow rotation and make it go forward and backwards. But then exceeding that like estimated 1 degree it wants to go full speed, either direction I make it go in. And I can tell steering works cause I turn the steering pot some and bring it carefully to a flat position and see the wheels spin in opposite directions until tilting a little further which will make both spin in the same direction. Basically it just seems really really sensitive. Do you think mounting it solid and putting it all together mechanically that it will operate properly? That like maybe when it’s attached the sensitivity will be reduced because of the upright bar being attached allowing more precise tilting? Would you still recommend loading the “Motor Spin Test”? Or finishing it mechanically? Or something else? Thanks

  65. October 13th, 2015 at 12:56 | #65

    It sounds like everything is working 🙂 Remember that even 10 degrees of tilt is actually quite a lot when you stand on the platform!

  66. Rusakow Sergej
    October 15th, 2015 at 18:55 | #66

    Hi Kristian! We liked your work. We watch with astonishment. Children want Full size DIY Balancing Robot. The problem is there is no Firmware (.hex) for Arduino Pro Mini. In programming, I’m not good. Please help with the firmware, thank you?

  67. October 20th, 2015 at 14:06 | #67

    @Rusakow Sergej
    First download the code from here: https://github.com/Lauszus/BalancingRobotFullSize now download the Arduino IDE: https://www.arduino.cc/en/Main/Software. Now simply click on “BalancingRobotFullSize.ino”. Now you should be able to compile and upload the code.

  68. Willie
    October 22nd, 2015 at 03:27 | #68

    Did you ever get a chance to watch the video link I emailed you? I wanted to know if the way the board was responding to the tilting was normal.

  69. November 2nd, 2015 at 15:20 | #69

    Sorry for not getting back to you Willie! Everything looks alright. Remember that you will properly reach full speed very quickly. This is normal and should work when you assemble it, but the direction might need to be reversed, but it is hard to say without having everything hooked up.

    Btw I just bought a 3D printer and is working on a enclosure for the Cytron motor drivers. Just thought you might be interested if you got access to a 3D printer 🙂

  70. November 8th, 2015 at 18:30 | #70
  71. Ocean
    December 12th, 2015 at 16:30 | #71

    Can I use the same motors without hub for other wheels? (I couldn’t find similar wheels for hub)

  72. Sergei Volgograd
    December 23rd, 2015 at 08:01 | #72

    Hi Christian! Thank you for the great work!
    I have a problem starting BalancingRobotFullSize compilation stops at 45 step
    Turning 45 double = (double)analogRead(STEER_PIN) / 204.6 – 2.5; // First convert reading to voltage and then subtract 2.5 V, as this is the center of the steering wheel
    but in libraries no Pins.cpp I must have done something wrong?
    Thank you

  73. December 24th, 2015 at 10:10 | #73

    Yes sure 🙂

    @Sergei Volgograd
    Please copy paste the full error message.

  74. Sergei Volgograd
    December 25th, 2015 at 18:03 | #74

    Hi Christian!I copied the error message.

    C:Program Files (x86)Arduinohardwaretoolsavrbinavr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -IC:Program Files (x86)Arduinohardwarearduinocoresarduino -IC:Program Files (x86)Arduinohardwarearduinovariantsstandard -IC:Program Files (x86)ArduinolibrariesWire -IC:UsersuserDocumentsArduinolibrariesKalman -IC:UsersuserDocumentsArduinolibrariesMotor -IC:UsersuserDocumentsArduinolibrariesIMU -IC:Program Files (x86)ArduinolibrariesEEPROM -IC:UsersuserDocumentsArduinolibrariesProtocol -IC:UsersuserDocumentsArduinolibrariesPID C:UsersuserAppDataLocalTempbuild1722252235920414119.tmpBalancingRobotFullSize.cpp -o C:UsersuserAppDataLocalTempbuild1722252235920414119.tmpBalancingRobotFullSize.cpp.o
    BalancingRobotFullSize.ino:22:36: error: BalancingRobotFullSize.h: No such file or directory
    BalancingRobotFullSize.ino:23:18: error: Pins.h: No such file or directory
    BalancingRobotFullSize.ino:31:2: error: #error “Please update the Arduino IDE to version 1.5.7 or above – see: https://github.com/arduino/Arduino/pull/2148
    BalancingRobotFullSize.ino: In function ‘double getTurning()’:
    BalancingRobotFullSize:45: error: ‘STEER_PIN’ was not declared in this scope
    BalancingRobotFullSize:46: error: ‘cfg’ was not declared in this scope
    BalancingRobotFullSize.ino: In function ‘void setup()’:
    BalancingRobotFullSize:53: error: ‘deadmanButton’ has not been declared
    BalancingRobotFullSize:56: error: ‘buzzer’ has not been declared
    BalancingRobotFullSize:59: error: ‘checkEEPROMVersion’ was not declared in this scope
    BalancingRobotFullSize:60: error: ‘readEEPROMValues’ was not declared in this scope
    BalancingRobotFullSize:62: error: ‘buzzer’ has not been declared
    BalancingRobotFullSize:64: error: ‘buzzer’ has not been declared
    BalancingRobotFullSize:75: error: ‘buzzer’ has not been declared
    BalancingRobotFullSize:77: error: ‘buzzer’ has not been declared
    BalancingRobotFullSize.ino: In function ‘void loop()’:
    BalancingRobotFullSize:99: error: ‘dataReady’ has not been declared
    BalancingRobotFullSize:109: error: ‘deadmanButton’ has not been declared
    BalancingRobotFullSize:109: error: ‘cfg’ was not declared in this scope
    BalancingRobotFullSize:120: error: ‘VBAT_PIN’ was not declared in this scope
    BalancingRobotFullSize:122: error: ‘buzzer’ has not been declared
    BalancingRobotFullSize:124: error: ‘buzzer’ has not been declared

  75. December 26th, 2015 at 14:35 | #75

    @Sergei Volgograd
    You need to download ALL files in the directory. Also please update the Arduino IDE to the newest one available: https://www.arduino.cc/en/Main/Software.

  76. January 23rd, 2016 at 12:37 | #76

    Hi Kristian! I can use your code with my Sabertooth dual 25A motor driver – https://www.dimensionengineering.com/products/sabertooth2x25 ?

  77. Sergei Volgograd
    January 23rd, 2016 at 18:59 | #77

    Hi Christian! On your advice I reinstalled the Arduino IDE and downloaded again all the files from the directory, but no result. I ask you to forgive me for being so inquisitive , but I can’t find in the directory the code file library Pins.cpp how you can solve this problem.

  78. January 24th, 2016 at 22:49 | #78

    @Andrey Chanov
    I posted this gist: https://gist.github.com/Lauszus/3f727b1fa3ca692a8bdb some time ago for another guy. It might be a bit outdated, but the principle should be the same.

    @Sergei Volgograd
    There is no such file called “Pins.cpp” which one are you referring to?

  79. January 30th, 2016 at 13:09 | #79

    Kristian Sloth Lauszus! possible to @Sergei Volgograd make a comment on Russia ?

  80. January 30th, 2016 at 13:22 | #80

    @Sergei Volgograd !It means this:
    1. pokes centuries link https://yadi.sk/d/vt5uej-3ipRBK are uploading an archive
    2. In the folder where you installed arduinovaya development environment has a subfolder libraries copy in the archive and unpack it. Must be added to the existing catalog of catalogs KalmanFilter
    3. Unpack the archive BalancingRobotFullSize-master.zip
    4 rename kataloug which he unpacked in BalancingRobotFullSize
    5. Run the arduinovy ??compiler and open the directory in the previous step BalancingRobotFullSize.ino
    6. compile
    7. upload to Arduino, pre-configured in the Arduino programming environment type and COM port to which it is connected.
    8. drink beer and rejoice 🙂

  81. January 30th, 2016 at 13:28 | #81

    @Sergei Volgograd!
    if you are from Russia! Write me an email, I will say what to do!victor2603@mail.ru

  82. February 1st, 2016 at 04:59 | #82

    Kristian Sloth Lauszus !I did all I y kompiliruetsya.tolko sees smartphone data not Arduino .no idut.mozhet in smarfone have nastroiki Bluetootn?

  83. February 1st, 2016 at 21:08 | #83

    You are welcome to write in any language you like 🙂

    I am not sure what you are asking? But the Android app is available here: https://github.com/Lauszus/BalancingRobotFullSizeAndroid.

  84. sanja
    February 4th, 2016 at 16:19 | #84

    ?onstantly falling on the android program! At connection to error!?

  85. sanja
    February 4th, 2016 at 16:21 | #85

    at connection android to error?

  86. February 6th, 2016 at 11:31 | #86

    Checked on 3 phones connect with the phone when the program closes with the wrong!

    If at the start of the program to disable monent tx arduino in information is information . But in the transition from the menu pid program for android closes with an error.

  87. February 6th, 2016 at 14:48 | #87

    Can you try to compile the code yourself and then see if it works? Also the log trace will give you some information of the crash.

  88. February 6th, 2016 at 17:01 | #88

    I’m not sure that I can razobratsya compilation android.
    I’m more than poyayu software programmer 🙂
    If you are difficult to check what was going on.
    After all Balanduino program works fine and without a glitch…

  89. February 6th, 2016 at 17:14 | #89

    Are you talked about this project or the Balanduino?

    You can find information on how to compile the Android code here: http://developer.android.com/sdk/index.html and here: http://developer.android.com/tools/studio/index.html.

  90. February 6th, 2016 at 17:27 | #90

    Balanduino works perfectly!

  91. February 8th, 2016 at 11:52 | #91

    With recompile the project provides a lot of mistakes! Kristian, – You run it on your phone?

  92. February 8th, 2016 at 15:33 | #92

    I have the situatsiya.ne can launch prilozhenie.postoyanno climbs mistake!

  93. February 8th, 2016 at 15:36 | #93

    Yes it’s working fine on my phone. What errors are you getting?

    I am not sure what you mean?

  94. February 8th, 2016 at 16:51 | #94

    application error. can I properly install on android
    .and as sdelat.irstruktsion?

  95. February 8th, 2016 at 18:35 | #95

    Sanja !If Russian write me an email victor2603@mail.ru !

  96. February 9th, 2016 at 19:58 | #96

    Cannot set up guest memory ‘android_arm’: Invalid argument

  97. February 9th, 2016 at 20:59 | #97

    Sorry but the error message your are referring to has nothing to do with my code? Are you trying to set up an emulator?

  98. February 10th, 2016 at 21:45 | #99

    Sorry but I don’t speak Russian. Can you use Google translate to translate it?

  99. February 11th, 2016 at 13:44 | #100

    February 10th, 2016 at 12:02 | #48 Reply | Quote

    Kristian Sloth Lauszus
    February 10th, 2016 at 21:45 | #49 Reply | Quote
    Sorry but I don?t speak Russian. Can you use Google translate to translate it? ostanovleno.eror android app.

  100. February 11th, 2016 at 13:50 | #101

    all the time is reset Bluetooth Authentication .net application

  101. February 11th, 2016 at 19:45 | #102

    I gathered in the studio when you press antdroid error and closing the application starts .

  102. February 12th, 2016 at 13:42 | #103

    Kristian Lauszus !new hc-5..hc-6 app is not working you have an older unit.

  103. February 12th, 2016 at 13:59 | #104

    When connecting to a Bluetooth goes to the dump with an error …
    And the program even without a connection at the entrance to the GRAPH menu> Update also falls ..
    The only thing that I have made this data is received on the INFO menu .. time konekt rx disable bluetooth. Then I tuck and data are …

  104. February 17th, 2016 at 05:25 | #105

    Application screenshots
    You is not working bluetooth old. Once you are no longer working ukogo ???

  105. February 23rd, 2016 at 20:54 | #106

    HELO !I’ve got a problem using your software.It does not work untill the RX wire is disconnected. After that the cell phone starts receiving data via blue tooth and I put the RX wire back but when I try going from “info” menu to another one the program failes and there is “error” starts indicating.What am I doing wrong or there is something wrong with the software? Any help from you will be much appreciated.Thank you in advance.

  106. sanja
    February 23rd, 2016 at 21:12 | #107

    Victor the project does not work , do not waste time…

  107. February 25th, 2016 at 09:04 | #108

    Please do not come with some claims, as that is clearly not true. Why would I invest so much time in publishing and documenting everything if it did not work?

    You can also see the app working in the video here: https://youtu.be/80EKp2fpPDo?t=1m42s.

    I have removed the APK from the Github repository as you guys clearly had problems with it. Please compile the code yourself and then provide the debug log that is the only way I can see what is going on.

    Please know that I did this project more than one and a half years ago, so you can’t just expect me to drop everything I am currently working on just to debug your problem, as I got the app on my own phone and its working fine.

  108. February 25th, 2016 at 09:04 | #109

    Please compile and upload the APK yourself, as this is the only way we can see why it crashes.

  109. sanja
    February 27th, 2016 at 10:11 | #110

    a new compiled apk file!
    it does not work and does not work!!!
    in communication with the device – THE PROGRAM closes with an error !

  110. March 2nd, 2016 at 22:36 | #111

    that is our theme became one meste.I seeking normal ank very mnogo.ya think that it is necessary to solve the realties! a lot of people behind this project!

  111. March 2nd, 2016 at 22:38 | #112

    das ist unser Thema wurde zu einem meste.I normalen ank sucht mnogo.ya sehr denken, dass es notwendig ist, die Miet-Objekte zu lösen! eine Menge Leute hinter diesem Projekt!

  112. saas
    March 4th, 2016 at 18:27 | #113

    is it important transmission ratio of motor or diameter of wheels? does it work with other motors that have different transmission ratio?

  113. March 8th, 2016 at 23:43 | #114

    Please provide the logcat, so I can see what it going on. Please see: http://developer.android.com/tools/help/logcat.html.

    Yes, but you should make sure that the motors have enough torque. You will properly also have to tune the PID values again for your robot.

  114. nhattinh92
    March 12th, 2016 at 11:21 | #115

    How i can make it work with Module BTS7960 43A Motor Driver. Help me pls ….

  115. April 14th, 2016 at 20:42 | #116

    I think I have found out why the app kept crashing on your phones! The problems was that conversion from floats to String and visa versa made the app crash for some non-english language. This commit should fix the issue: https://github.com/Lauszus/BalancingRobotFullSizeAndroid/commit/5a95cd3a8295d62069868582097f8efbab9bdf08.

    Please download the source code again: https://github.com/Lauszus/BalancingRobotFullSizeAndroid and it should work 🙂

  116. April 25th, 2016 at 07:21 | #117

    Upon reaching the values ??of the speed and the maximum value of pwm segway before falling in . How can I fix this? Thank you.

  117. April 25th, 2016 at 19:14 | #118

    Try to increase the value here: https://github.com/Lauszus/BalancingRobotFullSize/blob/master/PID.cpp#L43 from 0.004 to 0.005.

  118. Asya_XXX
    May 6th, 2016 at 23:28 | #119

    A very interesting project! How much money have you spent? (approx) Thanks!

  119. May 7th, 2016 at 11:54 | #120

    About $650 🙂

  120. February 4th, 2018 at 14:01 | #121

    Hello! Soldered the board, connected everything except the drivers of the engines. When turning on once peep. Bluetooth connects to the mobile and the program, but the program does not see data from the board. Blutuz working HC-06. Can you help? Thanks in advance!!!

  121. February 19th, 2018 at 11:59 | #122

    Please make sure that TX is connected to RX and vice versa.

    Also make sure that the baud rate of the Bluetooth module is configured to run at 57600. This can be done by sending:


    To the board via the Serial monitor.

  122. February 19th, 2018 at 12:17 | #123

    I just updated the code, so it automatically sets the name, pin and baud rate when the board is powered on the first time: https://github.com/Lauszus/BalancingRobotFullSize/commit/bf9c3014ce788e06863dfdde101fb71dc4c82b9d.

    Please reupload the code and see if that solves the issue.

  123. Paul Doyle
    September 16th, 2019 at 14:42 | #124

    Hi Kristian love this project i have previously built the Balanduino and really enjoyed the build and it works flawlessly. I am currently working on a self balance unicycle and am wondering can i just use your code from this project without modification or will i need to remove the steering part of the code as i will only be using 1 500w motor.

  1. December 5th, 2017 at 22:03 | #1