Easy build self balancing electric skateboard

Easy build self balancing electric skateboard

What is it?
Twin wheeled skateboard that works like a Segway.  Electric skateboard exist already with motors on the rear wheels. The plan here however is to build something like a Segway but in the form of a skateboard. It knows which way is "up" via a combination of  gyroscope and an accelerometer sensors, using what is known as a complementary (not complimentary) filter which reads and combines data from both 100 times per second.

What's new on this Instructable?
July 26th 2011: Step 49 now describes a better way to power the Arduino using a very efficient voltage regulator
July 26th 2011: Step 50 describes alternative build with pneumatic tyres.
Jan 2012: As well as old sketches attached to pages 43 - 47 which work in Arduino V22, I have rewritten each sketch and attached it to work with latest Arduino environment V1.0. also with some bugs fixed regarding accelerometer orientation

How does it stay level?
It controls the wheel motors so the wheels always stay under your centre of balance, like balancing a broomstick on your fingertip. This in engineering terms is called a "PID" control system and is used for all sorts of things. For example think of the 300+ feet high Apollo rockets used in the moon landings..........
Q: How come they didn't they just fall over when they took off? They took off incredibly slowly for the first few seconds, tailfins would have no effect, much slower than the Shuttle launches.                Watch this video and see what I mean.......................
It takes a full 10 seconds just to get to 100m and clear the launch tower: http://www.youtube.com/watch?v=F0Yd-GxJ_QM
A: They had engines mounted on gimbals (swivelling joints) hydraulically controlled by a PID control system (lots of analog electronics too). Hence the mystery phrase "we've hit gimbal lock" which keeps cropping up during the film, Apollo 13.

Background:
In 2008 I saw a YouTube video by Ben Smithers of his one-wheeled self balancing skateboard whizzing around a car park in Norwich UK. http://www.robosys.co.uk/       Video: http://www.youtube.com/watch?v=HGbbag9dklU
It turns out he was a Lotus cars controls system engineer - which makes sense.
Also see Trevor Blackwell's site: http://www.tlb.org/eunicycle.html
Meanwhile I wanted to teach myself microcontroller programming and, totally underestimating the task, thought this would be a great fun way to do this. I built several machines some with one wheel and some with two. Advantage of two wheelers is that they turn more easily and can turn and balance even when stationary - which is fun.

Why an Instructable?
Having learned lessons the hard way I thought it would be worth redesigning the project around an Arduino microcontroller, then seeing how low-cost and easy-build I could possibly make it. Clearly something like this is not for the complete Arduino beginner, nor is it that "easy" however this is about as easy as a self-balancing machine is realistically ever going to get.

Skills:
Projects like this lend themselves to being built as a team. Some examples below were built as college projects. There are
i) some electronics (not making circuit boards, just wiring and soldering) to master,
ii) some mechanical fabrication; this version is designed to require no welding, just nuts bolts and some woodwork. Wheel/sprockets/axles/bearings come as a unit (electric scooter rear wheel assemblies).
iii) some programming; the programs (Arduino sketches) you need, including those to help debugging, are attached to the last few pages of this instructable.

How much does it cost?
There are a number of self-balancing robots out there. I realised when costing them up that the cost of a self balancing robot would only be a little lower than that of a ride on machine, therefore I went for the ride-on machine! Robot motor/gearbox combinations are pretty expensive.
For me the cost was about $300 equivalent PLUS whatever batteries you choose to use. I recommend starting with lead-acid batteries then make improvements later once you have a working machine. Lithium batteries etc are expensive!

Why do it?
i) For the challenge of doing something original. Most things have been invented, indeed self-balancing machines have been invented. Segway skateboards have been invented in principle BUT there is huge room for improvement.
ii) Making something that is practical and intuitive to ride is quite a challenge in terms of both electronics/software and fabrication/packaging. Cannot all be done on a computer. Eventually you have to actually build something then incrementally improve it. Despite the myth of "Eureka" moments, the truth is that this is how most innovations come about, by slow incremental development and hard work. Edison did not invent the lightbulb. He developed the first practical lightbulb.
iii) To educate yourself. You will learn a huge amount.
iv) These things are really good fun to ride! I have taken this to 2 UK Maker Faires now and both times people are wanting to have a go. The last time the BBC cameramen who also had an exhibit politely waited until the end of the show, then they too asked to try it out.

This instructable:
There are a large number of pages in this. This is deliberate, if you are serious about building one then you need every single step documented with no gaps.

Additional information:
I have documented all my machines both good and bad on another website here:
http://sites.google.com/site/onewheeledselfbalancing/
I have a page of links to dozens of other self-balancing projects from around the world here:
http://sites.google.com/site/onewheeledselfbalancing/Home/links-to-other-self-balancing-projects

Can I do this as a beginnner?
The fabrication in this has been deliberately kept really simple.
The soldering between sensors and arduino board needs to be good quality!
If you are new to Arduino I would recommend buying an Arduino starter kit. These usually come with a number of ancillary sensors etc and a set of about 12 tutorials. Work through them all (about 2 days of work) and read a beginners book to Arduino. You will then be ready to have a go at something like this.

Has anyone else built one of these?
Oh yes! Ages currently range from 12yrs to 81yrs.
This Instructable is over a year old now, so yes indeed, people have. Here are a few I know of:
1)   Skateboard:    http://www.youtube.com/watch?v=kSW7YXLCjqk
2)   Skateboard:    http://www.youtube.com/watch?v=u-uUidBZEnM
3)   The Velociryder:  http://www.youtube.com/watch?v=xvfUIxusPZw&feature=player_embedded
4)   Great board video - Buffalo State College senior project: http://www.youtube.com/watch?v=FEaTxahyQxc
5)   Another board based on this Instructable:  http://www.youtube.com/watch?v=vhbH_AmIKZA&feature=related
6)   A board based on old FIRST robotics parts + code from this instructable (FIRST robotics was started by Dean Kamen who also invented the Segway, to encourage youth to get interested in engineering):   http://www.youtube.com/watch?v=Vh9LpNQ_S0k&feature=related
7)   Carbon fiber racing car seat with 2 wheels also based on this instructable - the SciChair: 
http://www.youtube.com/watch?v=HtivH7INpZ4
http://www.youtube.com/watch?v=1hG24CTgBL4&feature=related
8)   Carey's self-balancing platform, good video:   http://www.youtube.com/watch?v=ngMJcxeB7og
9) Really cool video (on clifftop path by the sea): Skate auto-balancé
Took 3 years. Used similar parts list except for accelerometers which are from a Wii-Nunchuck. 350W motors.  Batteries: two 3Ah LiPo and one 5Ah LiPo. http://www.youtube.com/watch?v=MsYoNA3s7O0
10) The KSLURP board from Malaysia: http://www.youtube.com/watch?v=x3O2NkjJOlg


NOTE:
You build these at your own risk. If tilted they WILL accelerate to correct the tilt. If you are not on the board, this means it can fly across a room. This is why you have to have some form of emergency hand switch that cuts the power if you let go of it. If it develops a fault it does not have multiple redundant systems like a real segway, most likely you will fall off! The code is not guaranteed against any bugs.
If you don't believe me here is a video of Clint Rutkas developing his machine, also featuring some holes it punched in the walls of his apartment!    http://vimeo.com/2013773

Have fun. Treat it as an adventure. Once you get it to balance there are many ways to improve it.

John



 

 
Remove these adsRemove these ads by Signing Up
 

Step 1Parts

Parts
Here are the parts laid out on floor
« Previous StepDownload PDFView All StepsNext Step »
316 comments
1-40 of 316next »
Feb 1, 2012. 3:23 PMgerrymazzotta says:
Hello, I'm very surprised by what you managed to do, congratulations. Inspired by your project I would also like to realize in my school in Italy, however, starting from a lower level until you get to 'self-balancing. The problem that I know basicstamp parallax. I have a problem in programming arduino 2009 to perform simple movements with this yojstik http://www.robotstore.it/product/293/Shield-Mini-Joystick-resistivo.html.
The two motors (left and right) should say:
- Both forward (acceleration ramp%)
- Both backward (with ramp acceleration%)
- Turn right (starboard engine spins up)
- Turn left (turn left engine plane)
- Do you reverse right or left (respectively, the engines run against each other).
I use two 180w 12V motors
Sabertooth
Arduino 2009
yojstik assembled on Arduino as links.
I suppose you are super busy but I'd be very grateful if I persuades a tip on the Arduino programming and electrical connections.
PS: I build the vehicle has two front wheels and rear swivel type robots.

Sorry so much for English .... I'm Italian!

Hello and see you soon!
Jan 28, 2012. 5:24 AMTigrisLi says:
Could you give the names of all the parts please?
Thanks!
Jan 16, 2012. 5:06 PMdariokristo says:
Hello everyone,
For people who are interested in making a remote controlled two wheeler, check this out:
http://www.youtube.com/watch?v=Yjsp1-DrsHI&feature=plcp&context=C3c668efUDOEgsToPDskIjtX14x24OF2K3_r7mJgcn
Jan 4, 2012. 6:13 AMlooking4ideas says:
Howdy! ,
I have just recently tackled this project to use daily taking me to and from class. However i was wondering if this system is stable enough for daily use or just time to time to show off to your friends.. I will be using 2x 300W motors instead of 250.

You can fallow my project at www.aggiespaceprogram.com

Gig'em
Jan 8, 2012. 1:15 AMCurtis 109 says:
Hi, I was very impressed with the self balancing skateboard and I thaught I am going to build one but as a segway, I used the same parts just put the wheels further appart and fit a handlebar. So far so good the IMU test worked out good it leveled at 340 which is close to Johns recommendation of 338, the motor test is perfect.
with the balance test I seem to have problems, I lean it forward count to 5 then activate the deadman switch and slowly bring it level and just as it gets level the tiltstart kicks in but it doesn't selfbalance at level the motors stop if I tilt it slightly forward the motors move forward if I tilt it back the motors reverse and the more I tilt it the faster it will go, of course let the deadman switch go everything stops.
What am I missing out on? I,m not a programmer nor have I an oscilloscope.
Any help would be much appreciated.
Jan 8, 2012. 3:52 AMdariokristo says:
Change this line of code: x_accdeg = (float)((accsum - (338 + balancetrim))*0.862); //approx 1.16 steps per degree so divide by 1.16 i.e. multiply by 0.862 with,
x_accdeg = (float)((accsum - (340 + balancetrim)) * (-0.862)); //approx 1.16 steps per degree so divide by 1.16 i.e. multiply by 0.862. We actually use -0.862 as accel is wrong way around relative to gyro.

It should work.
Jan 9, 2012. 1:58 AMCurtis 109 says:
Thank you heaps dariokristo, it is balancing now all I have to do is to adjust the take off speed as present it is taking off too quick when I only give it a slight tilt.
Jan 9, 2012. 4:54 AMdariokristo says:
Again, try changing this:
angle = (float) ((1-aa) * (angle + gyroangledt)) + (aa * x_accdeg);
with this:
angle = (float) ((1-aa) * (angle + gyroangledt)) - (aa * x_accdeg);

Cheers
Jan 11, 2012. 12:17 PMtracer11lb says:
Hi,

I know its been awhile since the last comment but I was just wondering if I can use a motor with built in motor controller? thanks
Jan 11, 2012. 12:43 PMtracer11lb says:
sorry here is the link of the motor I want to use

http://www.teknic.com/products/servo_motor.php
Oct 3, 2011. 8:40 AMmgrachev says:
Hello! I don't have an oscilloscope, how can I measure the cycle_time? Thanks. I'm trying to use your code on an Arduino with Lego and some servos, but I have to tweak the Motor output signals. Thanks for the help! Awesome instructable btw
Dec 6, 2011. 8:04 PMBeerBellyJoe says:
Looks like Universal Pictures likes The THING you built!

Check out the scooter the boy is riding!
http://movies.yahoo.com/feature/lorax.html?showVideo=1#theatrical
Nov 8, 2011. 12:41 AMdhteam says:
once again thanks for your insight in regards to my question before about running from a power supply as well as the usb cable in the tuning stages my self balancing scooter has come a fair way since then but ive hit a small problem and was wondering if u had any suggestions to help me out ???

here is a link to my board running : http://www.youtube.com/watch?v=s9WJ29vczaU

the problem im experiencing is the shuddering in the entire board when changing from forward to reverse or reverse to forward , im pretty stuck im thinking its a program fault , maybe when changing directions i need to add a delay or a way to ramp power up, any guidance would be much appreciated
Nov 15, 2011. 6:44 PMdhteam says:
i helped reduce this problem significantly by having overall gain relative to angle of the board, still not great but better result.
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...
Nov 6, 2011. 1:13 PMbschulth says:
Has anyone updated this program to work with the UNmodified Wii nunchuck? I am about 2 weeks of stuff away from attempting it myself, but I'm still working on some other fabricating. I'd like to be able to control the steering by using the accelerometers in the nunchuck but the other (excellently written) instructable is set up to export the accel readout as a varible voltage to feed to another microporcessor instead of directly into the code to the motor controller. Didn't want to reinvent the wheel if it wasn't needed.

BTW, Thanks to all for all the support so far. It's funny that the more DIY stuff I do the more I feel the support comes from so many others. I a very big way, none of us do anything entirely on their own :)
Nov 6, 2011. 6:06 AMh3x_your_nightmare says:
i think you can use a relay instead of that switch :D good luck
Oct 29, 2011. 11:01 AMdurakes says:
I have been playing around with your instructions, great job! I got to the point of testing the motors but when I load the motor testing code into the Arduino IDE I get a landry list of Java errors. Not being a programmer I seen to be dead in the water

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at processing.app.Sketch.setCurrentCode(Sketch.java:1106)
at processing.app.Sketch.load(Sketch.java:218)
at processing.app.Sketch.(Sketch.java:140)...

Any Advice? Thanks
Sep 14, 2011. 11:33 AMjmunsami says:
Thanks for an amazing tutorial once again john. I really want a pressure sensor driven one... so i guess ill have to wait!

So anyway... I was thinking about what motors to use. I want to use one of these motors, but im unsure which one, and if the sabertooth will be enough to handle it.
http://www.ampflow.com/ampflow_motors.htm

Ive also found this battery which can handle the juice.

http://teamassociated.com/reedy/parts/details/626/

thanks :D
-Jaysen
Oct 29, 2011. 9:36 AManiles jr says:
can i use this sabertooth


http://www.dimensionengineering.com/Sabertooth2x60.htm

thank you
Oct 22, 2011. 10:50 AManiles jr says:
wat motor would be better the on u used or this http://www.ampflow.com/ampflow_motors.htm?
Oct 20, 2011. 3:33 PMdornseif says:
I have been able to purchase all other items for this build except these. Cant seem to find an online source for good brackets. I am in South Carolina, any idea where I can obtain them on internet?
Sep 23, 2011. 5:11 PManiles jr says:
and wat motor would be better the on u used or this http://www.ampflow.com/ampflow_motors.htm?
Sep 23, 2011. 5:09 PManiles jr says:
how long can u ride ur untills it dies
Sep 16, 2011. 12:13 AMdhteam says:
hey thanks "XenonJohn" for this tutorial it has been a big help i have used this and a few others and a lot of researching and incorporated them all together my code seams to be working alright and a balancing bot feels not to far away ,my question is in regards to powering the board by a second source as well as the usb cable , i was wondering what happens if u dont? and if the change is noticable? i have been using only my usb cable when debugging and testing software .

Sep 4, 2011. 3:27 AMfuture-tinker says:
Cool, but I have a couple of inquiries;
Firstly could I use this( http://diydrones.com/profiles/blogs/arduimu-now-available ), because I have a couple floating around the place.
And secondly could you make it as an assist for a pedal (with brakes) bike like this ( http://www.n55.dk/MANUALS/SPACEFRAMEVEHICLES/spaceframevehicles.html ) (with the back wheel taken of)?
Sep 14, 2011. 12:37 PMfuture-tinker says:
Cool thanks,
Aug 9, 2011. 9:23 PManiles jr says:
thank you for answeing all of my qustions but i have a few more

im building a segway and instead of putting left-right on a SWICTH iwant to lean the handel over to the left to turn left and the father father i push it to the left or right the tighter the turns. would this mean i would have to put the gyro some were in the steering bar? and how much would i have to change in the code?

thanks
1-40 of 316next »

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!
109
Followers
10
Author:XenonJohn