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 45CODE (Just balances nothing else!)

CODE (Just balances nothing else!)

Open this sketch (attached as a text file to paste into an arduino sketch and save)

NOTE:

Updated Feb 25th 2012.
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.




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.


Now you have tested your IMU, tested your motors (and so have a working deadman switch) and are confident from video and photos that IMU is mounted correctly AND that motors are not wired up back-to-front, then you are ready to try to get it to balance.

This sketch, attached as a text file, just balances the board - nothing else. Steering disabled so if you have no steering controls connected it doesnt matter at this stage.

The tip-start is working.

The deadman switch has to be working.

The overallgain has been fixed in the code so the gain potentiometer does not have to be attached.

Power it up (tilted), wait a few seconds for gyro to zero itself, press deadman button and hold it in, then bring it slowly level, hopefully when more or less level it should start to balance or at least try to.

« Previous StepDownload PDFView All StepsNext Step »
3 comments
May 23, 2012. 9:32 AMgrunff says:
Hi XenonJohn,

I built a robot using this setup a while back, but never managed to get it to work satisfactorily. I've now picked the project back up to see if I can get it working.

The problem I'm having is caused by the Level drifting very quickly, so the board never finds its level. It tries to level, but by the time it gets there, the Level variable is way off horizontal, so it can't balance.

Any idea what can cause this drift? It happens over a few seconds, and within 30 seconds or so instead of being 0 deg it's 400 deg.
May 25, 2012. 8:33 AMgrunff says:
Thanks for your help John, I appreciate it.

I'd actually got past this point, but I'm still having trouble getting it to balance. It starts off well, then oscillates wildly out of control. I suspect the values in your sketch are not working well on this small frame (~500g).

I'm experimenting with overallgain, and also with the scaling variables in the balance_torque calculation (4.5 and 0.5), but I still haven't managed to make it balance.

Any further insights would be much appreciated.
May 27, 2012. 2:00 PMgrunff says:
Thanks very much for that John. I will spend this evening trying to tune it :-)

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