Caveat Emptor: (I don't want to put you off building one but I also don't want you to be disappointed.)  This Instructable is now 2 years old.  Many of the parts it uses are out of date (there's no drop-in replacement for the now-discontinued gyro, for example) and I've had reports that the code is hard to compile.  If you're not comfortable with the principles behind the electronics, code and the maths involved in PID control then you probably shouldn't attempt to build one.  Also, it's a tricky project to debug once built so it's really not a good first project.  If you're not happy to spend 2 days watching your bot list, jiggle, zoom across the room and fall over before you get it to balance then steer clear!

This instructable shows how I built my ArduRoller balance bot. It balances quite well on the spot and responds to most knocks pretty quickly but sometimes giving it a more gentle push sends it gliding across the room at a constant speed. I'm still working on that.

There's a video of the bot in action at http://www.flickr.com/photos/fasaxc/5944650602/.

Step 1: Parts

Here are the parts I used:

1 x Arduino Uno
1 x Sparkfun Ardumoto motor driver shield
1 x Sparkfun BlueSmirf Bluetooth modem
1 x 150 degree/s gyro
1 x 1.7g Accelerometer
2 x Arduino header kits
2 x screw terminals
2 x 24:1 gear motor
1 x set of 70mm wheels
2 x JST connectors
2 x LiPo batteries
1 x basic LiPo charger
3 x Multi-turn 10k potentiometers
1 x SPST switch (Radioshack)
1 x Laser-cut bamboo chassis via Ponoko  (link should allow you to make one from my shared design)
1 x LED
1 x Normally-open push switch
1 x packet of Sugru to make the bumber
Assorted M2-04 machine screws (6mm - 16mm) (found on Amazon)
M2-04 nuts to match machine screws above
Assorted straight and right-angle break-away headers
Assorted jumper wires
Solid core wire
Stranded core wire
Instamorph (aka Polymorph) low-melt-point thermoplastic


Chassis: the motors didn't quite fit the mounts I made so I had to sand them down and rebuild them with instamorph.  I think the sensor bundle suffers from too much vibration, it might have been better to make it more solid rather than sticking out as it does.

Accelerometer: I originally tried building the bot with only an accelerometer for tilt sensing and no gyro.  It turns out that approach is a non-starter -- the accelerometer gets overwhelmed by the acceleration due to the motors so it can't be used to estimate tilt while the bot is accelerating.  OTOH, using only a gyro would make the bot susceptible to drift over time so you really need both.

Gyro: I used a 150 degree/s rate gyro.  From looking at the telemetry from my bot, I'm pretty sure it sometimes clip if you give the bot a knocks so if I was starting over I'd probably look for a 300 degree/s model.  

Wheels: the wheels are a little fragile, after a few knocks I noticed cracks around the axle so I strengthened them with instamorph.

Motors: I also tried sparkfun's 100:1 gear motors but they weren't fast enough.  The 24:1 versions have plenty of torque and speed.

Bluetooth: I use the bluetooth modem for telemetry right now but I'm also planning to use it for remote control from my Android phone.  If you omit it then the robot will still work but tuning it will be harder.

Pots: I added 3 10k multi-turn pots to the design to allow me to easily tweak internal values.  Using 3 might have been overkill since I tend to tweak only one thing at once.

Instamorph:  Amazing stuff.  It's a tough, white plastic (resembling solid nylon) at room temperature but if you heat it in boiling water it turns into a pliable goo that's really easy to work with your hands.  A heat gun is great for working with it too, allowing you to melt small areas. 
<p>Hi. Why did you choose this vertical design over a stacked design?</p>
hi i want make my balacing robot with atmega16
hi who help me in my balacing robo projects with adxl335 moduel thanks<br>my email :hamedmosavi125@gmail.com
Hi. Very nice project which I am trying to replicate using IDE, your main.cpp sketch, an Arduino ProMini , L298H bridge, ADXL335 and LPR550AL which are similar to your gyro and accelerometer. I also blanked out the first six include statements. <br>This is what I get: <br>wheels turn in opposite directions and when pressing the calibrate switch on pin8 nothing happens. Can you help me to get to the calibration part working along with the serial monitor? thanks <br>PS I can monitor the Xacc and Yacc and the gyro using another program.
This is how I tested my gyro and accelerator so far: <br>hardware arduino promini, ADXL335 5V gyro 500degr-sec 2mv, <br>LPR550AL 5V accel 3g 10Kpots set at about 50% <br>LED on pins 8 and 13 <br> <br>sketch: <br> <br>const int button = 8; // added button pin <br>const int led = 13; <br>const int led2 = 7; <br>void setup() <br>{ <br> Serial.begin(115200); <br> pinMode(led, OUTPUT); <br> pinMode(led2, OUTPUT); <br> pinMode(button, INPUT); <br>} <br> void loop() <br>{ <br> digitalWrite(led, HIGH); <br> digitalWrite(led2, HIGH); <br> delay(1000); <br> Serial.print(&quot; gyro &quot;); Serial.print(analogRead (A0)); <br> Serial.print(&quot; Xacc &quot;); Serial.print( analogRead (A1) ); <br> Serial.print(&quot; Yacc &quot;); Serial.print( analogRead (A2) ); <br> Serial.print(&quot; pota &quot;); Serial.print(analogRead (A3)); <br> Serial.print(&quot; potb &quot;); Serial.print( analogRead (A4) ); <br> Serial.print(&quot; potc &quot;); Serial.println( analogRead (A5) ); <br> ditalWrite(led, LOW); <br> digitalWrite(led2, LOW); <br> delay(1000); <br>} <br> <br>result: <br>both LEDs blink on and off at 1 second intervals and the captured serial input from the analog lines are: <br>(bot is lying horizontal) <br> gyro 486 Xacc 401 Yacc 303 pota 515 potb 532 potc 506 <br> gyro 485 Xacc 400 Yacc 303 pota 515 potb 532 potc 506 <br> gyro 482 Xacc 398 Yacc 301 pota 514 potb 532 potc 506 <br>(bot moved to vertical in about 5 secs) <br> gyro 489 Xacc 369 Yacc 319 pota 470 potb 485 potc 462 <br> gyro 437 Xacc 325 Yacc 301 pota 452 potb 467 potc 445 <br> gyro 397 Xacc 311 Yacc 296 pota 453 potb 468 potc 445 <br> gyro 402 Xacc 316 Yacc 300 pota 452 potb 467 potc 445 <br> gyro 423 Xacc 332 Yacc 318 pota 461 potb 477 potc 454 <br> gyro 410 Xacc 322 Yacc 309 pota 464 potb 479 potc 456 <br> gyro 399 Xacc 313 Yacc 299 pota 465 potb 481 potc 458 <br> gyro 391 Xacc 308 Yacc 293 pota 466 potb 481 potc 458 <br>
One other thing that's worth trying: you can change the PID controller expression to exclude the integral or proportional term while you debug the other. ie. comment out one of the terms in this expression:<br><br> speed = tilt_rads_estimate * TILT_FACT +<br> tilt_int_rads * TILT_INT_FACT +<br> gyro_rads_per_sec * D_TILT_FACT;<br><br>It won't balance but it'll show you how that term behaves.
If the motors are moving in opposite directions then you need to either swap the wires on one motor or flip the direction bit in the code. <br> <br>I don't think the current version of the code uses a calibration button but you can leave the USB cable connected and write a single letter g to the console. That will make it spit out diagnostics (although it won't balance with USB cable and diagnostics running). <br> <br>To calibrate, connect the USB cable and send a g to get the output flowing. Then, the bot will write out the key state values. Then you need to work back from the outputs. When you're not moving the bot, you want the gyro to be reading 0 after subtracting the gyro offset. You also want the X and Y acceleration to be normalized so that their sum square is 1. The error in the gyro offset is absolutely critical, you need it accurate to 0.01 or the error in gyro position will sum up quickly and overwhelm the signal. <br> <br>Looks like your gyro might have a different mV/rad/s value from mine, you'll need to enter that in at the top. I found the best way to set that was to run the calibration output and then: quickly rotate the bot by 45 degrees and then slowly rotate it back. If all your values are correct, then the gyro angle guess should end up back where it started. <br> <br>Since my code is pretty complex (and somewhat grungy), you might want to start from scratch with your own code, implementing a basic complementary filter to combine gyro and accelerometer and then a PID controller to balance the bot.
Hi, Can you explain please why the batteries are not plugged into Vin? And how do you get the motors to run in reverse if the battery it plugged in this way
Hi, the batteries are plugged into Vin, I think that's pretty clear on the diagram. Maybe you're wondering why the Vins aren't all connected? In fact they are all connected, it's just implicit in the diagram. Drawing all the lines to connect Vin would make it messy. <br> <br>I'm using an Ardumoto to control the motors, which uses a H-bridge internally. Effectively, it can connect the motors either way round; with Vin on one pin and 0v on the other thy spin one way; with Vin on the other pin and 0V on the fist they spin the other.
Thanks for the quick reply (sorry it's another post. The reply isn't working for me for some reason...)! I'll see if I can figure out the filter at the website, and I'll try to find a carpet. <br>I guess I'll just continue working on experimenting for the PID constants (maybe I'll try the methods on wikipedia). If it works, I'll upload a video. <br>Thanks for all the help!
Hi! I constructed your balancing robot and I am stuck on what seems to be one final step. The robot I made is relatively much simpler (no trimpots, no push button, no LED status), but everything necessary for balance is there. The problem I have is that the balance seems underdamped. I modified the code a little bit (which I can post somewhere else), but most notably the ISR and PID controller. <br>I changed the ISR to a loop (since the interrupt kicked in but the code within the ISR never began) and changed the constants for the PID (initially to slow the speed of the wheels, but now I'm trying to modify to stabilize it). <br>http://www.youtube.com/watch?v=zPcYQKwf4rQ <br>http://www.youtube.com/watch?v=lDwBbGUEXaw <br>Above are two videos of the robot. <br>Any suggestions on how to fix this (especially for calculating filters and PID controller constants) would be great. <br>Thanks!
Your bot is looking pretty close to balancing. I just experimented a lot. I think I used the filter designer at http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html to get the filter constants. I just experimented a lot to find some that worked. <br> <br>Adjusting the PID controller requires a lot of trial and error; there are a few different <br>&quot;sweet spots&quot; that give different behaviour. For example, increasing one of the parameters might make the bot respond well to a particular type of nudge but then it'll make it worse at standing still. <br> <br>One thing I notice is that your're trying to balance your bot on a smooth surface. I recommend starting with carpet because the carpet helps to dampen the bot. My bot doesn't balance well on a smooth surface either. <br> <br>If you find that it tends to drift in one direction more than the other then you'll need to adjust the balance point.
Ok. But what about d_tilt_pot? it is not used anywhere, why do we read its analog value? In the code there is the line: speed = 7 * sqrt(abs(speed)). Is 7 related somehow to the diameter of the wheel?
Any fix on the constant speed across the room issue? I think that could be solved with a line that would slowly increase the amount of correct if the initial amount does work. SO instead at going across the room, it would increase until it had enough to right it self
I already have an integral term in my controller but due to symmetry it doesn't work to prevent horizontal drift. Increasing it tend to make the bot oscillate back and forth but it still drifts across the floor as it does so. It's probably theoretically possible to derive the drift rate from the sensors but they're so noisy that it's very difficult. It'd be must easier to just add shaft encoders so that my bot can tell exactly how far it has travelled and how fast.
Hmm, that is an unfortunate downside to reasonably priced electronic components. Shaft encoders might do it, but Im not sure how that would solve the oscillation due to sensor noise. Now that got me thinking. What about another line that would dictate how much power the integral line would be allowed to add to correct offset? So the closer the bot is to up right the lower the limit, and as the angle increases the higher the limit would be set if it was needed. Less chance of over correcting. But if it were too low you'd might get a slow side to side sway.
Ah, but what if the bot is upright and moving, then the integral term would do nothing and we're back to square one! In short: control theory is hard and there are a lot of non-obvious consequences of any change. I've experimented quite a lot with all the PID parameters but without a rewrite I think the code is as good as it's going to get. (A rewrite would let me make the code more performant so it might shorten the control loop and result in better control.) <br> <br>Using the shaft encoders would help oscillation because I could reduce the integral term and rely instead more on the shaft encoders. Unfortunately, amalgamating multiple inputs like that requires more complex control algorithms that I'm not familiar with.
I apologize for my lack of knowledge on the subject. I've been just getting into controllers, and was looking into balance bots as a project. Been a bit tough, dropping out of calculous sure doesn't help matters, especially in terms of PID controllers....
Thanks for your reply) Now I'm trying to understand the code, but some parts of the program are unclear. Why GYRO_OFFSET = 3.982, and X_OFFSET = 8 ? And why do we need potentıometers? Have you used complementary filter or other one? Thank you in advance:)
The potentiometers allow adjustment of the PID controller without recompilation. I can adjust the code so that the potentiometers change any value that I'm interested in and then change the potentiometers gradually to experiment. It's much faster than recompiling the code every time. <br> <br>The other values are the calibration values for my particular sensors. You'll need to work those out for your own sensors too or experiment until you find the right values.
Hi! I'm going to build this robot, and I have a question: can I use triple axis accelerometer instead of dual axis? or can I use evaluation board ADXL203EB? I could not find ADXL203CE breakout board.
Using a 3-axis gyro would be fine but you'll need to have a good understanding of the design and the datasheet of the gyro you use in order to adapt the design. I don't want to put you off but this project is not an easy one for a beginner; you'll need a good understanding of the design and the theory behind the algorithms to get it to work. It's not just a matter of running my code, you'll need to calibrate it. Good luck!
Hey mate, i'm learning to play with the arduino hardware, and am going to attempt to remake your arduroller. Can I throw you questions everynow and then?
Sure, but, unless you've got a good handle on the engineering already, I wouldn't try the Arduroller as a first project. It's tough to get right and some of the parts don't seem to exist any more so you'll have to be comfortable adjusting the schematics and code for a different gyro.
I'm building myself up. Arduroller won't be my first, but it's what I will be working towards. I was going to ask you how you used the JST connectors on the prototype section of the board to power the ardumoto?
I wired them in series and then connected them to Vin so that it would power the Ardumoto and the Arduino via its 5v regulator.
I could not find ADXRS613 and ADXL203CE on Sparkfun, any replacement for that , may be I can purchase on eBay ? Thanks.
I haven't found a good drop-in replacement I'm afraid. If you're building my bot, make sure you don't go below 150 deg/s. 200 deg/s or 300 deg/s might actually work better (sometimes the bot moves more quickly than 150deg/s, leading to clipping). Remember to check the voltage of the gyro you get matches the microcontroller you're using.
Ways to make your bot work better:<br> <br> Low pass filter the accelerometer with a very low corner (comparable to the drift time of the gyro). Add that into your angle calculation, rather than directly adding it in. I don't think you need a Kalman filter. That is for noisy signals. (Yes the accelerometer is &quot;noisy&quot;, but not in the band of interest). Put optical encoders on the motors and feed this into the loop. This will stop &quot;running across the room&quot;. (The reason Segway doesn't need this is the rider controls this).<br> <br> Put weight up as high as you can get on the bot. That will increase the stability.
Looks like someone else has built a bot based on my chassis design: http://blog.makezine.com/archive/2011/09/pierce-nichols-at-the-ohs.html<br>
Wow, that is a good lookin' bot ;) The laser cut wood really makes it look super professional! I know this kind of thing is aimed towards beginners and people who want to build prototypes quickly, but I still had to chuckle at an alternate title for this Instructable: &quot;How to make the most expensive desktop Arduino balancer!&quot; :P I would build one of these in a heartbeat, but I am really curious about the total cost of this bot! Like I said though, this would be an extremely satisfying project for a beginner, so I'm not trying to play down the badassery of this little guy!
Thanks. That seems like a pretty apt description ;-)<br><br>It's definitely not a cheap bot if you go with all the parts I used. I'd guess that I spent about $300 on it plus I had to buy tools. There are some parts that aren't necessary (like the $50 Bluetooth modem) and there are certainly cheaper motors and batteries available (you could probably save $50 there). I didn't work too hard to reduce the cost because I was building it gradually over a couple of months and I've found in the past that it's too easy to spend 5 hours searching only to save $5.<br><br>I'd say it's a medium-difficulty project. The physical build isn't that hard (although cramming everything on the protoboard is a bit fiddly) but tuning it to stand up correctly took me a long time with a lot of trial-and-error.
Thanks for the suggestions propellerheadgeek. I'm always looking for new places to find parts.<br><br>Do you do custom laser cutting? What're your shipping times/rates to California like?
I produce kits, but yes, I custom laser cut as well - check out my instructables if you get a chance. Priority flat rate small box to California is $5 - the other sizes aren't bad either. 2-3 day shipping, guaranteed by the USPS.
Very nice balancing bot! I really like the overall design. I'm a laser cutter - let me know if I can help develop the chassis a bit further. Also, instead of the sparkfun motors, may I suggest using http://www.solarbotics.com/products/gm2/ <br><br>They are modifiable from 224:1 to 14:1 by removing a gear and are far more robust, plus... they mount ROCK SOLID with through hole mounting and the wheels that they use are nylon, inexpensive, and unbreakable. <br><br>Again, very nice bot!
Can't seem to get the video to embed but there's one on flickr: http://www.flickr.com/photos/fasaxc/5944650602/in/set-72157627058612467
Any chance of a video of the 'bot in action?

About This Instructable




More by fasaxc:Playable Giant Gameboy Costume Hardwood comb Crumpets 
Add instructable to: