Self Balancing Segway Instructabot





1.  Arduino:  I used an Uno
2.  7.2v battery
3.  Set of motors:  Parralax's 7.2v motor set
4.  Analog accelerometer
5.  Sabertooth 5X2 motor controller
6.  base board
7.  3/4" threaded rod and nuts for balance
8.  Zip ties
9.  Screws


1.  Drill
2.  3/4" and 1/4" drill bits

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Instructabot Platform

I used a piece of wood 6" x 12" x 0.5"

Step 2: Electronics

Now for the electronics...  

The brain of the robot is an Arduino UNO which reads the accelerometer and gives commands to the motor controller which in turn powers the motors.  The Arduino takes 10 readings per second from the accelerometer and proportionally changes the motor speed and direction.  The Arduino code has gone through many changes and tests, but you still may have to change some of the values to be compatible with your robot.  To run the robot, hook up all the wires in the correct fashion and upload the code below to the Arduino.  It should start working right there and then.

//Self Balancing Instructabot 2013

int x, r, l, s, f, xa, xb, xc;

//Digital pin 13 is serial transmit pin to sabertooth
#define SABER_TX_PIN  13
//Not used but still initialised, Digital pin 12 is serial receive from Sabertooth
#define SABER_RX_PIN  12
//set baudrate to match sabertooth dip settings
#define SABER_BAUDRATE  9600
SoftwareSerial SaberSerial = SoftwareSerial (SABER_RX_PIN, SABER_TX_PIN );

void initSabertooth (void)  {
  //communicate with sabertooth
SaberSerial.begin( SABER_BAUDRATE );

void setup()                    // run once, when the sketch starts

void set_motor()   {
  x = analogRead(0);       // read analog input pin 0

//x range is about 270-400 and flat is about 330
//smooth x by averaging 3 readings of x
xa = x;
delay (20);
x = analogRead(0);     
xb = x;
delay (20);
x = analogRead(0);      
xc = x;
x= (xa +xb + xc)/3;


//s=slope with less being more aggressive
s = 1.8  ;
//f=fudge factor
f = 5;

//stable x around 330
if ((x > 325) && (x < 335)) {
r = 62;
l = 194;
//drive forward at a steady speed if leaning forward a little 310 > x < 330
if ((x > 310) && (x < 326)) {
r = 45;
l = 167;
//if falling forward more increase speed linearly for 279 > x < 311
if ((x > 279) && (x < 311)) {
//higher values make it faster
r = s * x - 278 + f;
l = s * x - 148 + f;
//if full forward x < 280
if ((x > 250) && (x < 280)) {
r = 6;
l = 133;
// drive backward at a steady speed if leaning back a little 334 > x > 349
if ((x > 334) && (x < 349)) {
r = 78;
l = 208;
//if falling backwords more increase speed linearly for 348 < x < 390
if ((x > 348) && (x < 391)) {
//lower values make it faster
r = s * x - 270 + f;
l = s * x - 140 + f;
//if full backwords 390 < x
if ((x > 390) && (x < 410)) {
r = 122;
l = 250;

//send motor outputs to sabertooth


void loop ()  {
float level = 0;

int u;

} // end loop

Step 3: Making the Instructabot

So now it's time for the artistic part of this make.

1.  Cardboard 
2.  Glue
3.  Robot print

1.  Scissors 

Step 4:

What did you make?
I made a self-balancing, segway-like robot.  The robot works by taking readings from the accelerometer in the x-direction, converting them to digital, then putting them into a formula which turns the motors a specific speed to get it to right itself.   

How did you make it?
I have wanted for some time to make a full size ride-on segway but decided to start out with a smaller version to get some ideas for a full-scale version.  To make it, I used a drill, soldering iron, computer for programming the Arduino, accelerometer, motor controller, screwdriver, and a lot of ingenuity.

Where did you make it?
I made the entire robot at home.  

What did you learn?
Before this project, I hadn't done a lot of stuff with accelerometers so this project gave me a great oppurtunity to learn about them.  Also, sending serial to the motor controller took some thinking and tinkering with the computer program which was challenging.  I was most proud of getting it to balance. The biggest surprise was how hard it was to get the code just right.  

Make-to-Learn Youth Contest

Participated in the
Make-to-Learn Youth Contest

Jury Rig It! Contest

Participated in the
Jury Rig It! Contest

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    83 Discussions


    1 year ago

    very helpful! sir i want to know details about the wheels. please help me since i am very much interested in this as my project


    2 years ago

    could this hold the weight of a person that weights 100-110 pounds


    3 years ago

    In the video it says "with a leash". I thought after trying to balance itself for 10-15 seconds it goes 1-2 metres forward, then it comes backwards. Am I wrong?How does it do it in the video?

    Thank you by the way.


    3 years ago

    Hi. Could you show me which part of the code makes the robot go forward( for a certain distance) then go backward (for a certain distance as shown in the video) please? Thank you.

    3 replies

    Reply 3 years ago

    The code given makes the robot try to stand up straight. When it falls forward it tries to right itself and moves forward in the process.


    Reply 3 years ago

    In the video it says "with a leash". I thought after trying to balance itself for 10-15 seconds it goes 1-2 metres forward, then it comes backwards. Am I wrong?How does it do it in the video?


    6 years ago on Introduction

    Hi again, Can you tell me the max + and - angle from the vertical you based your code on? I'm still having difficulty in smoothing out the motion. Thanks

    5 replies

    Reply 3 years ago

    Hi there! Can you help me with my masters degree project connected with Segway problem? I want to use neyral networks and fuzzy logic in it. I only have an arduino and a driver for 2 motors based on L298D chip


    Reply 3 years ago

    hello Librav nice robot you have here can you please send me the code and the design for your project to


    Reply 5 years ago on Introduction

    Your bot looks great. The max my accelerometer measured while on the segway was 400 and the minimum was 270 with 330 about flat

    it was awesome but the arduino uno is showing errorketch_may27a:21: error: expected unqualified-id before '\x616c'

    sketch_may27a.ino: In function 'void initSabertooth()':

    sketch_may27a:26: error: 'SaberSerial' was not declared in this scope

    sketch_may27a.ino: In function 'void setup()':

    sketch_may27a:29: error: redefinition of 'void setup()'

    sketch_may27a:1: error: 'void setup()' previously defined here

    sketch_may27a.ino: In function 'void set_motor()':

    sketch_may27a:102: error: 'SaberSerial' was not declared in this scope

    sketch_may27a.ino: In function 'void loop()':

    sketch_may27a:107: error: redefinition of 'void loop()'

    sketch_may27a:6: error: 'void loop()' previously defined here

    expected unqualified-id before '\x616c'

    so can you help me for solving it

    aesome . but i have got a problem that a have not got the sabertooth motor controller anywhere so can i use l298 p


    4 years ago on Introduction

    Awesome. I'm doing segway and trying optimal trajectory problem. I was wondering for your RF control what kind of receiver you used. Or anyone use a specific type of receiver?


    4 years ago on Step 2

    HELLO i have one question i tried to use your program and i couldn´t do it sorry i´m new in this topic :'( but i would like to do that amaizing robot =D can you help me :( please I´ll be very glad with you for the rest of my life =D


    4 years ago on Introduction

    Where is schema of the accellerometer and arduino??