Instructables

Self-balancing skateboard/segw*y project Arduino Shield

FeaturedContest Winner
Picture of Self-balancing skateboard/segw*y project Arduino Shield

General purpose Arduino shield for self-balancing machines.

Why did I make it?
I previously made an Instructable in 2010 on how to build a self-balancing skateboard.
http://www.instructables.com/id/Easy-build-self-balancing-skateboardrobotsegway-/

There are >500 comments on this and many express confusion setting up the balance sensors, software and electronics. On top of that, the analog output inertial measurement units that were commonly available stopped being made.

Here, I have taken a low price obscure analog IMU that IS currently still made in China, that IS available on ebay, and used an Arduino prototyping "shield" to mount ALL the parts, including a cable to a basic hand-controller (for steering and fine-tuning the balance point) and a cable with just 2 wires that you connect to a 2 x 25Amp "Sabertooth" motor power controller.
I have tried to make it as easy and in particular, non-confusing as possible to build.
NOTE December 2013: Even these are getting rare now but I have just found the "Grove" series of analog sensors from Seedstudio and added contact details to page 6.

In essence a complete re-vamp of the control system, making it simpler to build at the same time.


NOTE (March 2014): I have finally made something similar to this that actually works with a modern DIGITAL IMU from Sparkfun, the 6dof sensor, code No: SEN-10121. It has its own new Instructable here:
http://www.instructables.com/id/Arduino-Self-Balance-Controller-using-DIGITAL-IMU-/

Shameless part:

JUNE 2014: I am entering the Hackaday Competition with Nick Thatcher and another friend.
The entry is the Medicycle, yes it will have one wheel and yes it will be really cool. Best project yet hopefully. If you want to follow us, and we would very much like you to, here is the link:

http://hackaday.io/project/1156-Medicycle---Urban-...

continuing ...........It works with my self-balancing skateboards but by experimenting with the P, I, and D values listed at the start of the program (Arduino sketch) you should be able to use it to build a SegwayTM clone or similar project.



I have included the basics of how to connect this to the Sabertooth motor power controller, which is an off the shelf commercial robot power controller, how to power the Sabertooth and how to connect the motors to it. For a really detailed explanation of the mechanical side of the build, take a look at my original Instructable of 2010, linked at the top of this introduction page.

One gyro is used for balancing (complementary filter with an accelerometer). Another gyro measures rate of rotation laterally (e.g. when steering).
This provides another useful feature for free; when running in a straight line, if it detects rotation faster than 10 degrees per second laterally, it will change power to the motors to resist this effect. For example the motors often have different friction so when you slow to a stop, one stops before the other and you spin off. This feature stops that happening, and means the wheels can be mounted quite close together.
See this video http://www.youtube.com/watch?v=FEaTxahyQxc and you will see this happening at 0.51 mins, the spare gyro is used to reduce this effect.

NOTE: Added 15/03/14. For those who may manage to have one of the old, no longer available, Sparkfun 5dof analog IMU's, I have just attached the same code as written in this Instructable for the Chinese IMU, to step 30 but with the gains changed for the gyro to suit the old 5dof analog Sparkfun IMU.




Main parts list

www.maplin.com part number GBP US$

N39KR RockerSwitch 2.39 3.62
N39KR RockerSwitch 2.39 3.62
GW72P Microswitch with lever 2.49 3.77
FH04E Sub-Min Toggle switch 2.79 4.23
Project Box 3.79 5.74

XR27E 9 way multicore cable 5.14 7.79
2 core screened cable 0.99 1.50
N30KU Arduino Uno 24.99 37.86
N35KU Arduino protoshield 14.99 22.71
5DOF analog IMU 17.81 26.99
NOTE: List of sellers of this updated August 25th 2013 (See Step 6 for the list)
4 x LED’s 2.56 3.88
_________________________________________________________
80.33 121.71

Video clip



Video of latest self-balancing skateboard in action using this IMU and code



 
Remove these adsRemove these ads by Signing Up
1-40 of 63Next »
Kstuck1 month ago

Another great instructable!

Thanks for all of your efforts!

You have saved me countless hours of trial and error on my project because you took the time to post.

Can't wait to see you and Mr. Thatcher's latest creation in action!

paulbing1 month ago

Hello John,

I'm attempting to build a copy of your Pneu-Skate attempt at pneumatic tyred smaller skateboard https://sites.google.com/site/onewheeledselfbalancing/Home/pneu-skate for my 8th grade report,

and was wondering what your dimensions are, length, width and thickness of board.

Thanks!


paulbing1 month ago

Hello John,

I'm attempting to build a copy of your Pneu-Skate attempt at pneumatic tyred smaller skateboard https://sites.google.com/site/onewheeledselfbalancing/Home/pneu-skate for my 8th grade report,

and was wondering what your dimensions are, length, width and thickness of board.

Thanks!


gerrymazzotta4 months ago

Ciao,

Ho letto cose molto buone su questo driver del motore, penso che sia meglio di Sabertooth.

http://www.pololu.com/product/2393

Xenon si chiedono che cosa ne pensate ...

Cordiali saluti,

Gerardo

gilnaks4 months ago

Can I do it with this http://www.adafruit.com/products/81 motor controller? If not, what else can you recommend besides the sabertooth?

Kirkthepyro4 months ago

Whats the max speed?

XenonJohn (author) 5 months ago

Here is an analog output 3 axis gyro still available in Italy if it helps anyone:

http://www.robot-italy.com/it/gyro-breakout-board-...

gerrymazzotta6 months ago

Ciao John,

obiettivo raggiunto, ma ancora migliorabile.

Ecco il Vido:


Grazie di tutto,

a presto,

Gerry

Hias6 months ago

hi can i also use MPU 6050 GY-521 ??

gerrymazzotta6 months ago

Hello John,

I'm using an IMU Analog Combo Board - 5 degrees of freedom IDG500/ADXL335 SEN-11072 -----> https://www.sparkfun.com/products/retired/11072.Ti wonder if I should change the values of the code.

Thank you,

friendliness,

Gerry

XenonJohn (author)  gerrymazzotta6 months ago

Yes, the gyros have a different voltage outputs. I have just added code to this Instructable that lets you use one of the old Sparkfun analog 5dof IMU's (step 39).

If using the Chinese IMU listed at start of the Instructable use the original code (step 26 I think).

I am removing all code from the original self-balancing skateboard Instructable from 20010 as too much code is confusing everybody.

John

chronoxxx6 months ago
hello john, could you add a potentiometer steering code please?
XenonJohn (author)  chronoxxx6 months ago

Can do, so long as you already have it working with a rocker switch!

Keep things really simple until you get it to self-balance. Then you will be 95% done and can afford to add extra complexity at that time.

gerrymazzotta6 months ago

Hello to all,

can anyone tell me if the IMU is oriented correctly?

Thank you, Regards

ORIENTATION IMU.JPG
XenonJohn (author) 7 months ago

Hi everyone,

Big development: I have finally managed to get all this to work with the Sparkfun DIGITAL 6dof IMU Code No: SEN-10121.

It has taken 2 years but there we are.

Uses code from all over the web chopped and changed and merged with my existing code. Use the very clever Kalman balance filter algorithm too.

See the new Instructable here:

http://www.instructables.com/id/Arduino-Self-Balan...

John

eyrecamp7 months ago

Hello XenonJohn,

can i please get a copy of the code for this project

eyre.camp@hyne.com.au

XenonJohn (author)  eyrecamp7 months ago

Attached to Step 27

chronoxxx7 months ago

Hello everyone,

Hello XenonJohn,

Nice work, and thank you for the inspiration! I build a segway like self balancing machine and i used your code with the 5 dof IMU. The problem im facing now is when the board is level and the tipstart becomes active, the balance angle gradually drifts, and the board leans more and more forward.

i tried change

angle = (float) ((1-aa) * (angle + gyroangledt)) + (aa * x_accdeg);
to this:
angle = (float) ((1-aa) * (angle + gyroangledt)) - (aa * x_accdeg);

but with no success.

Do you have any idea how i can fix this?

zetowe7 months ago

Could is use this IMU? http://dx.com/p/gy-85-6dof-9dof-imu-sensor-module-for-arduino-148436#.Uv_HKfldVww I am planning to make a one-wheeled slim 12v vehicle like a ''onewheel'' http://www.youtube.com/watch?v=ns7RFZPTfpc

zetowe zetowe7 months ago

The website (dx.com) is reliable, i purchased several products there; never had a problem.

hotcheezy7 months ago
Hi John, I saw this video http://youtu.be/0wm2V9U5TG4 a skate board similar to yours but has only one wheel. Is it possible to modify your code to work with one wheel?

Peter
smasaye9 months ago
instead of using 2 single axis gyro,is it possible to expected the same result from a dual axis gyro,

http://www.rhydolabz.com/index.php?main_page=product_info&products_id=1328

the pins are same,
just instead of 4.5 rate output its 4,
will the code change?
XenonJohn (author)  smasaye7 months ago

The code would change but not by much. In fact it might work with code unchanged.

One problem with these unmounted components is soldering the wires to the sides of the gyro. It comes with no wires sticking out at all, just metal tabs you solder to and they are very small.

Sparkfun used to make a breakout board for these surface mount sensors, not sure if they do anymore. I used one on an old project which had an accelerometer in a similar package.

Well spotted. Always helps everyone when a new source of analog gyros is discovered!

m0skit0d3lt48 months ago

I bought a GY-521 MPU-6050. I'm wondering if I can use this, I thought I read about it on this instructable, but couldn't find it again. Since it is an I2C type chip. Please help? Thank you!

nikitojm12 months ago
Hello John, thank you very much for all your information. It's fantastic!
I have a question. I don't find analogic IMU, and the question is: What's the difference if I use one gyro IDG 500 separate with an accelero ADXL 335 that an IMU with the same component inside?
thank you
XenonJohn (author)  nikitojm9 months ago
Hi,

Notice that I have added some more analog IMU suppliers I have found.
Seedstudio still do an analog accelerometer and gyro, Have added details to page 6.
XenonJohn (author)  nikitojm11 months ago
My early machines used a separate (analog output) gyro and a separate (analog output) accelerometer.

You can do it that way.

John
gerrymazzotta9 months ago
Hello John,
I finished assembling my self balancing platform and I have to face the most difficult part for me is that the Arduino programming. I would like to modify the code so you can steer left / right with a potentiometer (5 or 10 Kohm) for proportional control.
I understand how to modify the variables P, D, but I do not know if you can adjust the torque and the maximum speed of the motors (2x280W 24V).
All your advice is appreciated,
thanks,
regards,
Gerry
XenonJohn (author)  gerrymazzotta9 months ago
Seriously now,
Keep it as simple as possible until you get the thing to self balance. Once that is done then worry about the finer points of control.
I can easily give you code to add in potentiometers but I would stick with simple switches until it is balancing OK.
Therevis plenty enough to go wrong as it is. Start simple then addin each improvement incrementally, testing each one works as you go.

John
Ok, I do as you say,
thanks so much,
regards,
Gerry.
kengaron1 year ago
Congrats John on a nice instructable. Just a quick question, based off of the picture when you were wiring up the IMU, I saw that A0 was used for something. Could you explain what that was for, couldn't find it in the tutorial. On a side note, almost finish welding my frame together. I'm trying this out with 12 inch tires, how well does this unit tackle inclines?

Ken
XenonJohn (author)  kengaron1 year ago
I soldered a wire to every single output of the IMU before I mounted it on the prototyping shield. From experience it is best to do this at the start than try to add wires later on when lots of obstructions in the way.
I then worked out which ones were relevant for what I was trying to do and trimmed off the ones that I did not need later on.
In the Instructable I only list the ones that are required therefore.
Hello,
congratulations on your tutorial, and thanks for the valuable advice you give.
Sincerely, Gerry.
XenonJohn (author) 1 year ago
Greywarden has just sent me a message that he has managed to get his board to work fully. Always nice to know it can be built from the instructable. Problem was loose wiring.
John
pm2001071 year ago
HI,

congratulations for this tutorial. This is by far the most complete one I found. I want to use this to make an arduino Segway. what advise would you give me (electronics and SW)? I would also like to power the arduino and shied from the 12V battery instead of doing it from the AA Batteries. Possible for you?
XenonJohn (author)  pm2001071 year ago
I did in the past use a DC-DC voltage converter, look at Tracopower products for example. This works up to 48V and converts it down to 9V DC.

Just once I turned it on and the accelerometer failed in the IMU. It was an older Duemilanove Arduino and not sure if some momentary power surge caused the problem. After that I always power the Arduino with a nice smooth ripple Dc battery as the IMU needs a nice smooth regulated supply.

Not sure if I am being paranoid but there are enough odd things that can g wrong that take ages to diagnose and this makes one less to worry about.

So, yes you can do it if you want to.

There are some micro segways out on the web built from two rear wheel drive sets from electric childrens scooters eg Razor range so you can do it this way or go for a bigger drivetrain. Look at the Sci-tech instructables for inspiration.

John
XenonJohn (author) 1 year ago
OK, I found the problem.
In the Instructable I said connect pins 11 and 12 to the Sabertooth. This was wrong and not what I actually did in the end.

GND on the Arduino/Shield goes to 0V on the Sabertooth and Pin 11 goes to S1 on the Sabertooth. Pin 12 not connected to anything at all.

This will explain why you had to GND the sabertooth to get anything to happen but then it still behaved erratically.

I have updated the Instructable just now. It was a mistake I originally made and corrected when I built mine but forgot to correct when I wrote it all up. Sorry for inconvenience caused.
Alright, I fixed that problem. The most likely problem was that the arduino and sabertooth weren't on common grounds. This was fixed pretty easily by placing a wire between my arduino's - battery terminal and the sabertooth's ground. I tested it with your serial testing sketch posted on the other ible, and it works great. But now I am having trouble getting it to balance. The IMU Tester code tells me to replace the 338 with 350, which I have done, but I can't balance it correctly. No matter what variables I change or how I change them, the balancing code starts too soon (the board is still tilted) often I don't even move the board when it decides to try and balance. I'm just getting confused at this point X) any help to offer for balancing adjustments?
XenonJohn (author)  Greywarden21 year ago
Are turning it on tilted with one end on ground, not moving it at all, then waiting 10 seconds before you bring it level?
Just making sure.......
XenonJohn (author)  Greywarden21 year ago
Send me an email address via the messaging system and we can correspond on this. First step would be to video it and put it on Youtube as a private video (only those you send the link to can view it). I can tell a lot by just watching what happens.

Best wishes

John
1-40 of 63Next »