loading

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-/

NOTE(December 2014): I have also done an Instructable using the same digital Sparkfun IMU in a self-balancing scooter. This instructable is most up to date and has the circuit diagram and latest code here:

http://www.instructables.com/id/Raleigh-Chopper-inspired-self-balancing-scooter/



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

Step 1: Whole assembly with hand controller

Picture of Whole assembly with hand controller
This Instructable assumes you know basics of how to load a program or "sketch" into an Arduino microcontroller and also know how to solder.

Tip: 
Even if you think you can see just fine, a pair of magnifying glasses or magnifying visor as sold in many hobby shops makes a huge difference when soldering very small parts and will last you your whole life probably.

The Shield has long pins that allow you to push it on top of the Arduino when completed. Take care as quite easy to bend some of them as you do it. It has a square grid of solder-holes on which you can mount your own components. I will mount my IMU, my LED indicator lights and the cables to the sabertooth motor controller and the hand controller securely to it also.

The shield is top left in this photograph. Arduino UNO is lower left. Hand controller, which we shall also make is lower right.

Step 2: General build layout of machine

Picture of General build layout of machine
This is just a guide as to how you might lay out the mechanicals of a machine like this using lead-acid sealed batteries and two rear-wheel drive units from a chain driven electric children's scooter.
See my previous Instructable of 2010 for example of how to arrange the mechanicals.

http://www.instructables.com/id/Easy-build-self-balancing-skateboardrobotsegway-/

Step 3: Main parts laid out

Picture of Main parts laid out
Arduino Uno
Arduino protoshield (or something very similar)
Cable with at least 6 wires inside (mine was 9 core in fact).
Battery holder for 6 x AA 1.5V batteries.
Two rocker switches that return to the middle position on a spring when you let go of them

A microswitch with metal lever that we will use as our deadman switch (when you let go of it all power to motors is cut).
Small on/off switch connecting the battery box to the Arduino.
Connector for the battery box.

Plastic project box which we will make our hand controller from.

Step 4: Making the shield

Picture of Making the shield
Close up of the shield.

The IMU is mounted on it vertically, more on this later (more wires in this early photo than I eventually needed).

We have 4 indicator LED's.

Multicore cable from hand controller comes in lower left.

2 core cable to Sabertooth motor power controller exits board middle right.

Shield is stacked on top of the Arduino.

Step 5: IMU right angled header pins

Picture of IMU right angled header pins
In previous photo the IMU was mounted vertically on the Shield. This was because I used right angled header pins to mount it, which conveniently come with the IMU.

Long ends go through edge of board with solder holes along it, short ends go down through holes in the protoshield.

Step 6: How we will wire up the IMU

Picture of How we will wire up the IMU
There are not many analog output IMU's left out there.

Here is the only one that seems to still be made.

IMU status (Updated 25th August 2013). Constantly changing situation......................
What you need for this software to work unaltered, is an analog IMU containing an IDG655 gyro and an ADXL335 accelerometer.



This is original one I specified when I wrote the instructable. However now 6 left and price has been quadrupled to $96.99 (thanks guys)
http://www.ebay.com/itm/181004141876?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

This one looks OK at approx. $17 but note “shipping and handling” is $100 (!) Thanks guys again.
http://www.ebay.com/itm/1PC-5DOF-IDG655-ADXL335-Accelerometer-Dual-axis-Gyro-Instrument-Module/360673380095?rt=nc&_trksid=p2047675.m1851&_trkparms=aid%3D222002%26algo%3DSIC.FIT%26ao%3D1%26asc%3D17214%26meid%3D818663122151966103%26pid%3D100005%26prg%3D8039%26rk%3D3%26rkt%3D5%26sd%3D181004141876%26

This one is OK but listed as sold out
http://www.dhgate.com/product/gy-66-idg655-adxl335-module-5dof-module-twin/156501775.html


Ones that do seem to currently be available at a reasonable price:

GY - 66 5 dof biaxial analog gyroscope sensor IDG655 ADXL335 module
$17.59 Does not ship to UK, does ship elsewhere.
http://www.ebay.com/itm/GY-66-5-dof-biaxial-analog-gyroscope-sensor-IDG655-ADXL335-module-/181115375225

GY-66 IDG655 ADXL335 Module 5DOF Module Twin Screw Analog Quantity Gyroscope Sensor Free Shipping
$14.28
http://www.aliexpress.com/store/product/GY-66-IDG655-ADXL335-Module-5DOF-Module-Twin-Screw-Analog-Quantity-Gyroscope-Sensor-Free-Shipping/406986_729113614.html

This one looks OK. Ships to UK, US etc.
$22.20
http://dx.com/p/gy-66-5dof-idg655-adxl335-double-shaft-analog-quantity-gyroscope-sensor-module-blue-232963

Here it is again at $24.71
http://www.goodluckbuy.com/gy-66-5dof-dual-axis-analog-gyroscope-sensor-module-idg655-adxl335.html

NOTE December 2013: Have just found the "Grove" series of analog sensors from Seedstudio. Details below. The scaling factors in software may need tweaking but at least they are still available to buy:
3 axis analog accelerometer
http://www.seeedstudio.com/wiki/Grove_-_3-Axis_Analog_Accelerometer
Buy here:
http://www.seeedstudio.com/depot/grove-3axis-analog-accelerometer-p-1086.html
and here:
http://www.dawnrobotics.co.uk/grove-3-axis-analog-accelerometer-adxl335/?gclid=CNDQ9fzmqLsCFSoewwod7gYA_w

Also they do an analog 3 axis accelerometer:
Buy here:
http://www.seeedstudio.com/depot/grove-single-axis-analog-gyro-p-1451.html
and here:
http://www.dawnrobotics.co.uk/grove-single-axis-analog-gyro/

Just found these as well (17th Dec 2013)
These also seem to have them in stock:
http://www.dawnrobotics.co.uk/grove-single-axis-analog-gyro/?gclid=COyekqahuLsCFRMRtAodlVMAQA

Here is one from Italy (March 2014 in stock):
http://www.robot-italy.com/it/gyro-breakout-board-lpy503al-dual-30-s.html



This one also might work, 10 left on ebay.
http://www.ebay.co.uk/itm/Single-axis-gyroscope-analog-gyro-module-ENC-03MB-module-For-Arduino-MWC-/180956189552?_trksid=p2054897.l4275

Here is an analog dual axis gyro (Feb 2014):
http://www.rhydolabz.com/index.php?main_page=product_info&products_id=1328
Note that it is surface mount so the soldering of wires to it will need magnifying glasses and a very steady hand.


You only need one gyro to balance. I use the second one for direction stability but that one is not essential (or buy 2 single axis gyros.

The accelerometer can be bought separately:

Example here:
http://www.ebay.co.uk/itm/ADXL335-3-axis-Analog-Output-Accelerometer-Module-angular-transducer-/281048570799?pt=LH_DefaultDomain_0&hash=item416fccdbaf







Check out how the original one I used was wired up to the Arduino via the protoshield:

Power to the VCC connection is 3.3V from Arduino 3.3V pin, NOT the 5V pin which will blow up the gyros, I know, I have done it before. Take care, these pins and GND are close together on the Arduino and respective protoshield pins, do not let solder bridges form between them! (A good case for the magnifying glasses I mentioned earlier).

GND goes to either GND pin on the protoshield.

Only 3 more connections need to be made:
X4.5 goes to Analog Pin 3 on the Arduino protoshield.
Y4.5 goes to analog pin 2
Z-acc goes to analog pin 1 

The rest of the IMU holes you do not have to worry about, not needed..................not too bad was it?


Notes on this IMU:
ACCELEROMETER (ADXL335) notes: 300mV (0.3V) per G i.e. at 90 degree angle
GYRO NOTES on the Chinese IMU we only have available in 2013 which uses the IDG655 gyro module: Gyro outputs x 4.5 on this Chinese IMU: 2.27mV per degree per sec up to 500deg per sec. 

Step 7: 3.3V power to the IMU (NOT 5V)

Picture of 3.3V power to the IMU (NOT 5V)
This is how I did it. So long as the wires go to the right pins you can do this any way you like.

I put the long ends of the right angled header pins through the IMU and soldered them all to the respective IMU holes.

From the ends of the long pins (now sticking out horizontally above the Protoshield) I ran small wires carefully to the Analog Pins 1, 2 and 3, you can see this better in the next photograph.

Two longer wires run to the 3.3V power supply pin and also to one of the GND pins.

The holes in the protoshield underneath the IMU are used just to hold the IMU upright and act as a mounting for it. I soldered two of them to hold the IMU rigidly at 90 degrees to the protoshield, i.e. vertically.

The holes on the protoshield just inboard of the black pin sockets are in continuity with them. Therefore you can put header pins in the sockets and solder your wires to them (as seen here with my IMU wires to analog inputs 1,2 and 3) or, you can solder your wires into the holes next to each pin (as seen with the 3.3V wire and GND wire in this photo).

Step 8: Rest of IMU wiring, just 3 wires

Picture of Rest of IMU wiring, just 3 wires
As described on previous page, I ran 3 short wires from airborne ends of the IMU long header pins (z-acc, X4.5 and Y4.5) to analog inputs 1, 2 and 3 respectively.

2 more wires go from VCC and GND to 3.3V and GND pins on the protoshield respectively.

Step 9: Mounting the IMU on the protoshield

Picture of Mounting the IMU on the protoshield
Another view just to make how I did this really really clear. Solder 2 pins on the IMU to the protoshield holes underneath just to mount it securely.

Step 10: LED wiring and the two serial wires to the sabertooth motor controller

Picture of LED wiring and the two serial wires to the sabertooth motor controller
Now we need to wire up some LED's as they are useful as indicators.

The wire next to the curves side of the LED goes to the +ve power (i.e. the Arduino Pin) and the flat side is the -ve and goes VIA  A RESISTOR, to a GND pin (ground) on the Arduino.

So, the +ve round side of the 4 LED's we see here are connected to Digital Pins 6,7,8 and 9 of the Protoshield. I soldered them into the holes just next to the respective black socket holes in the Protoshield.

The -ve side of each LED was pushed through a convenient hole in the protoshield and soldered into the hole.



In this picture we also see the 2 wires of the 2-core screened cable soldered to the holes for Pins 11 and GND.
This cable is the Serial communication cable carrying control data on motor speeds for each of the 2 motors to the Sabertooth motor power controller.

Step 11: LED wiring (2)

Picture of LED wiring (2)
Here is another view of the LED's and how they are soldered in, plus the 2 wires of the serial communications cable to the Sabertooth.

Flat side of each LED is facing to the right in this image.

Step 12: Resistors for the LEDs

Picture of Resistors for the LEDs
Each LED needs a resistor mounted in series with it, otherwise too much current would flow through it when the respective pin on the Arduino goes live. These should be about 100 Ohms each.

I ran mine from the projecting wire of the flat side of each LED (through the hole in the shield), on the underside of the shield, flat along the underside of the shield so they ran next to each other (no wires touching though).
I then joined all the ends of the 4 resistors together on right side of this image and ran a wire from them to the nearest GND connection on the Protoshield.

So, every time one of pins 6,7,8, or 9 goes live (+5V) current flows through the respective LED, through its respective resistor, to GND and so that LED will light up.

Keep the resistors fairly flat along the underside of the shield and you will find it does not then touch the Arduino when you mount the Shield on top of the Arduino later on.

Step 13: Making the handheld controller box

Picture of Making the handheld controller box
Here is a the hand controller, held in palm of your hand.

The deadman switch is on the end and you press it down with your index finger all the time. If you let go than as a safety feature, all power to the motors is cut (after half a second actually).

The rocker switch steers you left or right.

The rocker switch on the side is for fine-trim of the balance position. For example to go up a slope you might want the board (if it is a skateboard) a little "nose-up" before you start.

This is connected via a multicore screened cable to the Arduino.

When any switch contact is made, the respective pin on the Arduino is connected to GND on the Arduino.

Step 14: Hand controller internals

Picture of Hand controller internals
Here are the internals we want to fit into the hand controller.

Two rocker switches which have a spring that returns them to the mid-position when you are not pressing either end.

One microswitch which is to be used as the deadman switch.

Step 15: Cut holes in box for the switches

Picture of Cut holes in box for the switches
I use a Dremel with an abrasive cutting disc for everything like this.

Cut slots for your switches.


Step 16: Solder up wires to the respective switches - wiring diagram

Picture of Solder up wires to the respective switches - wiring diagram
Here is the wiring diagram.

Put a wire on each switch contact and write down the colour of each wire and what it does on a chart, along with number of the Arduino Pin the same wire at other end of the cable needs to go to.

See how all the GND wires can join together to go down one GND wire back to the GND of the Arduino

Step 17: Internals wired up

Picture of Internals wired up
Here are the hand controller internals wired up.

Switches are held in with hot glue gun glue. Careful where you put the glue else your rocker switches will not rock any more!

The microswitch (deadman) is held to box lid by 2 small 3mm bolts and nuts so you do not break it loose if pushing it too hard (with fear for example).

Step 18: Keeping hand controller cable securely fixed to Shield

Picture of Keeping hand controller cable securely fixed to Shield
See how I have used 2 small cable ties through spare mounting holes in the Protoshield to hold the multicore cable securely to it so you do not put any stress on the soldered pin connections for each of the little wires inside.

Things like this are important for reliability. Loose wires = chaos.

Step 19: Wire up the serial cable from Shield to the Sabertooth Motor Controller

Picture of Wire up the serial cable from Shield to the Sabertooth Motor Controller
We have one more cable left to go.

A 2 core screened cable from Pins 11 and GND (any GND on the protoshield) of the Protoshield/Arduino to the Sabertooth motor power controller.

These carry commands telling the Sabertooth how much power, and in what direction, to apply to each of the 2 motors. It uses a Serial communications protocol.

Step 20: Photo of how this cable is connected by just 2 terminals to the Sabertooth

Picture of Photo of how this cable is connected by just 2 terminals to the Sabertooth
Pin 11 on the Arduino is connected via this cable to the S1 screw terminal of the sabertooth.

Any GND pin on the Arduino/protoshield is connected via this cable to the 0V screw terminal of the Sabertooth.


In this image of the Sabertooth 2 x 25 Amp power controller, I have also shown the connections to the main 24V battery and also the connections to each of the motors.

Step 21: Keeping Serial cable tidy and securely fixed to Shield

Picture of Keeping Serial cable tidy and securely fixed to Shield
This is how I kept my serial cable neatly secured to the protoshield.

Two loops of insulated wire soldered into 2 spare holes in the protoshield about 1 inch apart hold the 2 core cable securely. Neater than a blob of glue gun glue, but that would also work. Careful with the soldering iron, if you hold it on for ages you might melt through everything and damage the cable itself.

Step 22: Setting the DIP switches on the sabertooth for Serial communication

Picture of Setting the DIP switches on the sabertooth for Serial communication
Consult the Sabertooth downloadable instructions but there is a set of DIP switches on the Sabertooth that need to be set to tell it what sort of communications it is receiving and what type of batteries are connected to it.

Step 23: Main power wires and motor wires to Sabertooth (for completeness)

Picture of Main power wires and motor wires to Sabertooth (for completeness)
For completeness here is how you connect the two motors to the Sabertooth motor power controller.

250 Watt to 400Watt motors are about right for this controller (remembering that if a motor stalls or is held jammed so it cannot turn, the current consumption greatly exceeds its "rated" value). This is why motor controllers often burn out on "Robot Wars" when robots are pushing against each other but hardly moving.

I have added a "Motor tester" sketch with the main code on page 27. Allows you to check your serial communications with the Sabertooth are all OK and working before worrying about the self-balancing part of things.

Step 24: Main power supply to the Sabertooth for motors

Picture of Main power supply to the Sabertooth for motors
Suggested simple way to connect the main two 12V batteries to the Sabertooth.

Step 25: Power supply to Arduino + Shield

Picture of Power supply to Arduino + Shield
To keep it all really simple I power my Arduino + IMU with a completely separate battery pack. AA size batteries are cheapest and last longest (compared to a 9V PP3 type for example). Therefore I use a simple 6 battery holder and a small on/off switch.

Step 26: Arduino CODE

Picture of Arduino CODE
Code is attached as a text file to the NEXT page.

Copy and paste it into an new open empty Arduino sketch, compile it and save it. Then load it into your Arduino.


Step 27: Code attached as text file.

This all was written using Arduino 22.

THIS CODE IS FOR USE WITH THE CHINESE ANALOG OUTPUT IMU MENTIONED ON THE TITLE PAGE.
If you are using an old Sparkfun 5dof analog IMU (no longer available) then you need to go to step 30 for code that works with this.

This is a bit old now and some commands do not work in the latest Arduino environment.

You may have to load Arduino 22 to your computer. If so, do it from here (scroll down the page for the historical downloads).

http://arduino.cc/en/main/software


NOTE also added now (Aug 2013) is a MOTOR TESTER sketch (as text file again) which allows you to connect just the deadman switch and the 2 wire serial cable to the Sabertooth.
When you press the deadman in, the code will spin the motors one way at different speeds, the back the other way at different speeds at 10 sec intervals.
It allows you to test the deadman switch and make sure you have the DIP switches on the Sabertooth correctly set up for serial communication (step 22) and that the Saber is working properly.

Step 28: Orientation of IMU and Shield on your machine

Picture of Orientation of IMU and Shield on your machine
Take note of the orientation of the IMU and the Shield relative to the plane of tilting of your board or Segway type machine.

Only mistakes here I cannot control are the way you wire up your motors.

Rule of thumb is that if you tilt board one way, both wheels should start turning in direction you have tilted it towards. i.e. if left end of board is down, then wheels should be moving board to left (to counteract this and bring board level again). It is easy to have one motor wired back to front for example in which case they do the right thing but spin opposite ways and so on.
Do initial tests holding board tightly at each end, with wheels ON the ground but be ready to lift board into the air and release deadman if it goes crazy.

- Tip machine one end on ground and do not move it about.
- Turn on Arduino.
- Turn on power to Sabertooth.
- Wait for 1 LED to light up.
- Press in deadman switch.
- Wait for all 4 LEDs to light up, it has now zeroed everything and is ready to go.
- Bring machine level SLOWLY. When level the self-balancing code will become active.
- For first few seconds the gain will be low and it will feel "mushy" in terms of ride quality.
- After a few seconds the gain automatically increases. This is the "soft-start" function.
- If you let go of the deadman switch all power will be cut within 0.5 seconds.
- Use the fine-adjust rocker switch to fine tune balance position if board is not quite level.

Step 29: Adjusting variables in the code

Picture of Adjusting variables in the code
Near top of the Arduino sketch is a box with all the key variables in that you might want to change.

You have P, I and D values of the classic PID controller.
The values I have chosen are by trial and error and suit my machine.

The overallgaintarget is the value the gain ramps up to in the first few seconds after you first bring it level.

Therefore for a taughter system you increase it (too much and machine will oscillate wildly). For a "mushier" ride quality then reduce it a little.

Step 30: Code for people using an old Sparkfun 5dof analog IMU (no longer available)

This is exactly the same code as used in this Instructable for the Chinese IMU that is just about still available (Step 26), but altered to take the old Sparkfun analog 5dof IMU that they no longer make, for people who may have one of these.
The gains have just been changed for the gyros as they have a different output to the ones in the Chinese IMU.

It is attached as a text document to be pasted into an empty Arduino sketch then compiled and saved.

The pin connections between IMU and Arduino are included in the sketch for you to see.
1-40 of 65Next »
jellis281 month ago

so why do you use an analog imu and not a digital. i have a digital 6dof

jellis282 months ago

would a 100watt e100 motor be suffucient

Kstuck11 months 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!

paulbing11 months 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!


paulbing11 months 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!


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

gilnaks1 year 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?

Whats the max speed?

XenonJohn (author) 1 year 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-...

Ciao John,

obiettivo raggiunto, ma ancora migliorabile.

Ecco il Vido:


Grazie di tutto,

a presto,

Gerry

Hias1 year ago

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

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)  gerrymazzotta1 year 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

chronoxxx1 year ago
hello john, could you add a potentiometer steering code please?
XenonJohn (author)  chronoxxx1 year 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.

Hello to all,

can anyone tell me if the IMU is oriented correctly?

Thank you, Regards

ORIENTATION IMU.JPG
XenonJohn (author) 1 year 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

eyrecamp1 year ago

Hello XenonJohn,

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

eyre.camp@hyne.com.au

XenonJohn (author)  eyrecamp1 year ago

Attached to Step 27

chronoxxx1 year 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?

zetowe1 year 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 zetowe1 year ago

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

hotcheezy1 year 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
smasaye1 year 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)  smasaye1 year 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!

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!

nikitojm1 year 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)  nikitojm1 year 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)  nikitojm1 year ago
My early machines used a separate (analog output) gyro and a separate (analog output) accelerometer.

You can do it that way.

John
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)  gerrymazzotta1 year 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?
1-40 of 65Next »