3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Easy build self balancing electric skateboard

Step 46Full balancing code

Full balancing code
This is the full version of the code for use with a rocker switch to steer and another to fine tune the balance point, i.e. the one that goes with this instructable. Attached as a text file to copy and paste into a new arduino sketch compile and save.
NOTE: It works with Arduino V22. They have now released a newer version (V1.0) with a new softserial library with slightly different softserial commands so it might not work with very latest version of Arduino.

NOTE 3: As Sparkfun are discontinuing the 5DOF IMU, I have rewritten the code here to work with a 6DOF "Razor" IMU also from Sparkfun, in response to requests. This has analog voltage outputs and should not be confused with their 6DOF digital version. I have not had time to upgrade the other attached program examples yet but this one compiles, though I have not tested it.


The overallgain is set in the code (to 0.5) so you don't need the potentiometer connected to make this work.

There is a value currently set to 338 in the code that needs adjusting by trial and error until your board balances perfectly level when the tipstart has kicked in. This is clearly indicated in the code.

HOW TO DO THIS:
Open this sketch.
As when we tweaked the IMU tester: alter the value of 338 in this line of code (if you need to) in for the value you wrote down for accsum when running IMU tester and holding your board level: x_accdeg = (float)((accsum - 338) * 0.862);

Recompile the balance code with this new value in and you are now ready to try it out.



On next page I have similar code but modified so you can experiment with using a 10K potentiometer for steering and another to fine tune the balance point.



« Previous StepDownload PDFView All StepsNext Step »
2 comments
Mar 29, 2012. 10:56 PMpumo says:
Does this code work with old IMU also ?
and is there link for right 6dof IMU, I found one but its also retired.
or should this work http://www.ebay.com/itm/190478609162?ssPageName=STRK:null:IT&_trksid=p3984.m1542.l2649?
Mar 30, 2012. 7:55 AMpumo says:
Thanks for your help and info, I did order that 5dof version from ebay if it wont work I just have to find 6dof analog.
Or if no luck with that I just wait your 6dof digital version code...


br
Pumo
Oct 23, 2011. 2:54 PMkarotSunoe says:
Hello John..

I used this code for my try.
I got the tilt started point.. But the skate can't balance properly.It's look like week and the deck slowly drop.
The skateboard just go away slowly (the skateboard can't stay)..But when I push the deck, the motor still work to get the balanced.
So, what part of the code that can I adjust?
Thank you...

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
127
Followers
10
Author:XenonJohn