loading

This Instructable will show you how to build a ride-able Segway clone. Here are its features:

  • Easy to build with no welding, no complicated steering linkage and minimal soldering.
  • Uses a readily available $3 digital MPU6050 accelerometer/gyro IMU board.
  • Total parts cost is under $400 (including shipping). A real Segway is $5000!
  • No salvage, dumpster diving or Craigslist parts.
  • A detailed parts list and ALL purchasable sources are included.
  • Well documented with over 50 minutes of HD how-to video, pictures and a detailed plan.
  • Uses the very common Arduino UNO processor board.
  • All Arduino processor code is included. NO additional Arduino libraries need to be installed.

This is a great learning project. It involves:

  • wood working
  • metal working
  • plumbing techniques
  • wiring from schematics
  • micro controller (Arduino) C like coding
  • accelerometer/gyro basics


I would say that a motivated middle schooler (12+ year old) with a parental figure could tackle this project. If the motivation isn't in the technical learning and assembly, it will be in the riding fun!

----------------------------------------------------------------------------------------------------------------------------

UPDATE 12/24/2014: There is a separate Instructable here to strengthen the Segway Clone PVC to Wood junction.

Step 1: Introduction Video

This video shows some action shots of the Segway clone!

Step 2: How to Ride the Segway Clone

  • With the Segway clone leaning forward, it's front edge touching the ground, toggle the power switch on.
  • The LED will glow red. Wait about 8 seconds for the MPU6050 Accelerometer/gyro to calibrate.
  • Lift up the board so it is parallel to the ground.
  • Hold in the deadman switch. The LED will turn green.
  • Step on the board.
  • Lean forward to go forward and lean back to go backward.
  • While you are moving, you can press the steering rocker switch to go left or right.
  • You can press the tilt rocker switch to adjust the neutral balancing position of the board.

Step 3: How to Build the Segway Clone Video

This video is over 50 minutes long and includes detailed instructions on how to build this Segway clone:

Step 4: Electrical Schematics

This is the electrical wiring schematic. It was drawn in MS Visio and saved as a .PDF here.

Step 5: Parts List, Cost and Tools Needed

Parts List and Cost Breakdown
The parts cost is under $400.  The attached .PDF file below  includes the sources, cost and HTML links.

Step 6: Tools Needed

Tools Needed:
Wood saw, hack saw, drill, drill bits, hammer, screwdrivers, wrenches, wire strippers, soldering iron, files, metal punch

Optional tools:
table saw, drill press, Dremel tool, VOM (Voltage Ohm Meter), WD40 (for drilling)

Step 7: Plans and Dimensions

These are the mechanical plans.   I designed this in MS Visio and saved off the .PDF here.

Step 8: The Arduino Code


The Segway Clone Arduino code is below:

The Arduino code development took the longest amount of time to get right in this Instructable. It could still be improved. Any ideas would be appreciated. It was influenced by the following authors of self balancing device projects and MPU6050 development:

Jeff Rowberg: https://github.com/jrowberg/i2cdevlib
XenonJohn: https://www.instructables.com/id/Self-balancing-skateboardsegwy-project-Arduino-S/
ScitechWA: https://www.instructables.com/id/Self-Balancing-Scooter-Ver-20/
Geekmom: http://www.geekmomprojects.com/mpu-6050-dmp-data-from-i2cdevlib/
Julian Arnott: https://www.youtube.com/watch?v=q29MMfLRFYM
and Eric Wang

Installation:

  • Install the Arduino software (http://arduino.cc/en/Main/Software#.UxiP2BCmZU0)
  • Download the .zip file BELOW with all the code (note that Instructables MAY corrupt the name)
  • Unzip the file (this is a good freeware unzip program: http://www.7-zip.org/download.html)
  • Open the Arduino software
  • Connect a USB cable to the Arduino board
  • To ensure your Arduino is working, get your Arduino to "load" the "blink" program (file->examples->basics->blink)
  • Open the file hartway_digital.ino
  • Compile and "load" to the Arduino board

You can search on YouTube to learn about the Arduino. This guy does a good job explaining everything about Arduinos:
http://www.youtube.com/watch?v=fCxzA9_kg6s


notes:

1) Instructable user fgastald posted the following note. This library code change seemed to help him and some others with stability issues. Most people do not experience these issues but you may want to make the following changes if you have vibration in your final design:

"For those who are experiencing some MPU6050 issues (weird behavior.....motor that suddenly goes to 100%.....) i suggest this : Go to the library file MPU6050_6Axis_MotionApps20.h find the line 0x02, 0x16, 0x02, 0x00, 0x01 // D_0_22 inv_set_fifo_rate Modify the last number (0x01) to something higher, i'm using 0x02 right now and it works fine."

2) There is a bug in the code that will show up if you hit and release the deadman switch about 250 times. User rtreffkorn reported this and suggested the following solution. I have not tested it but it sounds reasonable.

"The fix is to change set_motor() from void to int.
In the normal case return 0. When the deadman button was released return 1;
Then in loop() do: "if (set_motor()) break;" "



The Segway Clone Arduino code is below:

Step 9: Step by Step Instructions Start Here

The following are step by step instructions of how I built this Segway clone.  You may decide to copy this exactly or just use this for inspiration in your own variation.

Step 10: Lawyer Stuff and Safety

  • This project includes cutting, drilling and soldering.  Please wear safety gear and be careful.
  • Riding on a 2 wheel device that is inherently unstable is dangerous.  You will fall off it and crash into things.  You are responsible for your own safety.   Wear protective gear. 
  • The real Segway device can be dangerous even though it has safety shutoffs and error detection.  This Segway clone has NO safety detection or elegant shutdown.  Ride at your own risk. 
  • This Segway corporation video clip shows some of the dangers riding the real Segway device may have.  I found it useful to watch before riding this Segway clone: http://www.segway.com/flash/video/safetyvideo.php
  • Putting your fingers inside a chain and gear drive while the motor is running will remove your fingers.
  • Lead Acid batteries should be recycled and not thrown in the trash.

Step 11: Cut and Prepare Wood Riding Platform

We'll start this by cutting our plywood base.  I used birch plywood.  Any 3/4" plywood piece that can finish to 29" by 17 1/4" will do.  I cut the piece on a table-saw.  If you do this, use eye protection and watch your hands.

You can use a hand saw as well.  Accuracy in cutting is not critical but if you applying plywood edge tape, it needs to be smooth.

Optional: Use a coffee can or something with around a 3" radius to mark curves on the corners.  See video.  A compass set to 3" will work as well.  Cut the corners with a jigsaw or a coping hand saw.

Optional: Sand and then apply iron on edge tape to the edges.

Optional: Sand top and bottom of board.

Step 12: Cut and Drill Brackets

NOTE: this step is not shown in the how to make video clip.  Sorry.  See plans and read this text.

Get the four 8" x 8" x 2" angle brackets.  Two of them will be outside brackets.  Two of them will be inside brackets.   See the .pdf file of the plans for a drawing of the brackets.

To make the 2 outside brackets, do this twice:
  • Use a hacksaw to cut off 1.5" from the end of a bracket arm.  Length should be 6.5" when done. Clean up with a flat file.
  • Use a hacksaw to cut off 2 1/4" off the end of the other bracket arm.  Length should be 5 3/4" when done. Clean up with a flat file.
  • Use a metal punch to make a mark centered between the end 2 holes of the 6.5" bracket arm. 
  • Drill this hole out with a 3/8" or .375" drill bit.   This will hold the wheel axle.  Use a drill lubricant when drilling metal.
  • Widen this drilled hole with a Dremel or round file to make it 0.40" and test that it will fit the wheel axle.
  • Punch and drill four 1/4" holes in the bottom of the 5 3/4" bracket arm.   See drawing for position.  It is not critical.
To make the 2 inside brackets, do this twice:
  • Use a hacksaw to cut off 1.5" from the end of a bracket arm.  Length should be 6.5" when done.  Clean up with a flat file.
  • Use a metal punch to make a mark centered between the end 2 holes of the 6.5" bracket arm.
  • Drill this hole out with a 3/8" or .375" drill bit.   This will hold the wheel axle.  Use a drill lubricant when drilling metal.
  • Widen this drilled hole with a Dremel or file to make it 0.40" and test that it will fit the wheel axle.
  • Punch and drill four 1/4" holes in the bottom of the 8" bracket arm.   See drawing for position.  It is not critical.

tips:
  • When drilling into metal, it's better to use a drill press if you have access to one.  It goes faster and the hole will be straighter.
  • When drilling into metal, it helps to use a lubricant between the metal and the drill bit.  The lubricant takes the heat away from the hole.   WD-40 is a great lubricant.   Don't run the drill bit too fast.  Stop and let the hole cool off occasionally.

Step 13: Mount Brackets Under Platform

Grab the 8x8x8 brackets, wheels, chain, 1/4-20 x 1-1/4 in. Zinc-Plated Hex Flange Bolts, nuts and washers.
  • Measure 4.5" in from an edge and mark a line.  This will be the outer line that the bracket will rest on.  See drawing.
  • Place brackets on board bottom as shown in drawing, pictures and video.
  • Mark 4 1/4" holes per bracket with a pencil.  See video.
  • Remove brackets and punch center of each hole lightly.  This is to center the drill bit.
  • Drill holes with a 1/4" drill bit.
  • Remove brake assemblies from the wheels if they are on still.  See picture above.
  • Attach brackets with wheels and chain to board with (16) 1/4-20 x 1-1/4 in. Zinc-Plated Hex Flange Bolts, nuts and washers.

Step 14: Mount Motors to Platform

The motor has a bracket attached to it with 4 pre-threaded metric screw holes.
  • Set motor up so chain is straight and motor gear is perpendicular to the wheel brackets.
  • Pull gently on motor away from the wheels and mark the 4 holes.
  • Note that you may want to use a short piece of pencil lead to mark the motor holes.
  • Repeat for the other motor.
  • Punch the 8 holes and drill with a 7/32" drill bit.
  • Insert a washer and an M6 1.0x30mm bolt into each hole and tighten it.

Step 15: Crimp on Battery Wires

Find an extension cord to cannibalize or use speaker wire for this step.

  • Cut 2 lengths per the drawing.
  • Mark the bumpy ridged side of all ends of the cords with a black Sharpie pen. This will indicate our negative side.
  • Separate the end of one side on each wire and strip it 1/4".
  • Crimp on a Battery Terminal connectors (16-14 AWG, .250 Series) to each wire.
  • Use 4 Battery Terminal connectors total.

Step 16: Connect Motor Wires

Find an extension cord to cannibalize or use speaker wire for this step.

  • Cut 2 lengths per the drawing.
  • Mark the bumpy ridged side of all ends of the cords. This will indicate our negative side.
  • Separate the end of one side on each wire and strip it 1/4".
  • optional: slide small pieces of heat shrink tubing to each extension cord wire.
  • Twist on the black motor wire to the bumpy ridged marked extension cord wire. Do the same with the red wire to the other extension cord wire.
  • Heat shrink tubing OR cover with electrical tape.

Step 17: Install Galvanized Floor Flange

----------------------------------------------------------------------------------------------------------------------------
UPDATE 12/24/2014: There is a separate Instructable here to strengthen the Segway Clone PVC to Wood junction. You may want to reference that to modify your design. A few of the parts will change.

----------------------------------------------------------------------------------------------------------------------------

The 1-1/2 in. Galvanized Floor Flange is used to connect the PVC handle bar assembly.

  • Mark the center line of the 29" long side of the board.
  • Center the Floor Flange in this line about 1/4" away from the edge of the board. see pics, drawing and video.
  • Mark all 5 holes.
  • Drill 4 1/4" holes for the screws.
  • Drill 1 1 1/8" hole (using a spade bit) for the wires to pass through this 1-1/2 in. Galvanized Floor Flange.
  • Install Four 1/4" 20 x 1-1/2 in. Flat Head Phillips Machine Screws with washers and nuts.

Step 18: Cut the PVC Pipe

Get your 10' section of 1 1/4" schedule 40 PVC pipe.
  • Measure 31.5" and cut.  This is the main vertical pipe.
  • Measure 10.25" and cut.  This is for the right horizontal hand hold pipe.
  • Measure 10.25" and cut.  This is for the left horizontal hand hold pipe.
  • Take all the parts and "dry-fit" assemble them per drawing and video.

Step 19: Cut PVC for Switches

Get the circular "deadman" switch and the 2 rocker type switches.  You should hold these switches on the dry fit to see where you want them.  The measurements I give here are for what I did.    Get switches to fit in this step.  We'll add the wires later.

Deadman circular switch
  • Mark a hole on one of the 10.25" PVC pieces 4" from the end.
  • Drill a hole in the center with a 3/8" drill bit.  Reverse the bit for a while to start the hole if need be.
  • File the hole or use a dremel tool to widen the hole to about 0.45" to allow switch to fit in the hole.  It should be snug and NOT use glue.

You may want to practice the following rocker switch hole cutting on scrap PVC first.  Also, watch the vid.

Steering Rocker switch
  • Mark a hole on one of the 10.25" PVC pieces 6" from the end.
  • around the center of the hole, mark a rectangle that is 1 1/16" by 9/16".
  • Using a small 1/16" drill bit, drill many holes INSIDE the rectangle EDGE.  Use the drill bit to "cut" through the PVC, connecting the holes you drilled to cut out the rectangle.  An alternative method is to use a Dremel tool for this with a cutter bit.
  • File the hole or use a Dremel tool to widen the hole to allow the switch to fit in the hole.  It should be snug and NOT use glue.
Steering Tilt switch
  • Mark a hole on one of the 31.5" PVC piece 4.5" from the end.
  • around the center of the hole, mark a rectangle that is 1 1/16" by 9/16".
  • Using a small 1/16" drill bit, drill many holes INSIDE the rectangle EDGE.  Use the drill bit to "cut" through the PVC, connecting the holes you drilled to cut out the rectangle.  An alternative method is to use a Dremel tool for this with a cutter bit.
  • File the hole or use a Dremel tool to widen the hole to allow the switch to fit in the hole.  It should be snug and NOT use glue.

Step 20: Harvest the Wire

If you are using Cat5 cable, you can "harvest" or remove the wire pairs like this.
  • Strip the end of the cable to remove the outer plastic insulation.
  • Put the 8 wires in a vice.
  • Go to the other end and pull on the insulation. 
  • Go back to the beginning of the cable near the vice and slowly pull the insulation down. 
  • It will come off a little at a time.  See video.
Better way from another Instructables user!:
Mar 19, 2014. 1:59 PM rmelchiori says:
There is an easier way to strip the outer jacket of cat5 cable. If you pull down on the thin nylon floss, it will cut the jacket and open it up like pulling a zipper.

Step 21: Prepare PVC Switch Wires

Measure out the switch wires.
  • Use electrical phone type wire that is about 6' long.  I used CAT5 Ethernet cable which has 4 twisted pairs of conductors.  
  • One pair is for the deadman switch.
  • To make the 3 conductor tilt and steer cables, separate out one pair into 2 individual wires:
  •  A fast way to do this is to put one end in a in a drill chuck,  attach the other end to a vice or have a buddy hold it.   Spin the drill to loosen the wires so you get 2 non-twisted individual wires.
  • Now, take one individual wire and add it to a twisted pair.  You will have 3 wires.  Put one end in a in a drill chuck,  attach the other end to a vice or have a buddy hold it.  Spin the drill to tighten the spin of the wires together.
  • Repeat for the other 3 wire cable.

Step 22: Optional: Epoxy PVC Reducer Into Floor Flange

This step is optional but recommended so the handle bars don't  twist while you are riding.
  • Take the epoxy tubes.  Squeeze out about 3/4" of each the resin and hardener on a piece of scrap paper.
  • Mix the 2 gels together until its a consistent dark grey color.
  • Apply the mixture to the white PVC threads of the PVC 1.5" to 1.25" reducing male adapter.
  • Screw this PVC 1.5" to 1.25" reducing male adapter into the Floor Flange on the board.  Hand tighten.
  • Wait 10 minutes for the epoxy to dry.

Step 23: Install Switches in PVC

Get the 2 rocker switches and deadman switch.
  • Solder the 2 wire cable to the deadman switch.
  • Solder a 3 wire cable to the steer rocker switch.
  • Solder a 3 wire cable to the tilt rocker switch.
  • Write down all the colors of the switches for reference later when you connect them to the Arduino.
  • Snake in the switch wires through the switch holes.  See picture and video.
  • Push in switch to friction fit.

Step 24: Glue PVC Parts Together

Get the PVC Cleaner and Glue.   An alternative to PVC glue is to use epoxy.  You are working around the snaked wires so lay it out on a table.

Do it in this order:
  • End caps
  • Handles to Tee. (watch the switch positions!)
  • Tee to main pipe.
  • Main pipe to Reducer PVC (floor flange)  For this last step. Make sure the Segway board is lying flat on the table.  Quickly step back and look at the handle bar assembly to make sure you twist them parallel to the table while the glue has not dried.
How to Glue PVC:
  • Use the PVC cleaner wand (purple) to wipe cleaner on both parts to be bonded.
  • Apply glue (clear color) to both sides. 
  • Push pieces together and twist to spread the glue.  The working time for the PVC glue is about 10 seconds.  Make sure the switch is where you want it!

Step 25: Mount Electronics Box to Platform

Use the 1/2" #4 wood screws:
  • Line up the box as shown in the picture.
  • Mark the holes with a punch (or screw) by tapping with a hammer.
  • Drill holes with a 1/16" drill bit.
  • Using a hand held screwdriver, attach box with #4 1/2" screws.

Step 26: Install Batteries

  • Mark Battery lines at 3/4" in from long edge of board.
  • Mark battery line 1" in from short end of board. 
  • Trace rectangle around each battery.
  • Mark 4 holes outside battery rectangle for zip ties to go through.  See pictures and video.
  • Drill a hole for each battery power wire to go through.
  • Make sure the batteries will fit but dont lock the zip ties now!

Step 27: Install the Bi-Color LED


Grab the bi-color LED and the 300ohm resistor.  Watch the video.
  • Trim the LED center conductor.
  • Trim and solder on the resistor to the LED center conductor.
  • Solder an 8" long piece of 3 conductor wire cable to the LED assembly.
  • Insulate all wires with electrical tape.
  • Drill a 3/32" hole in the project box.
  • Insert the LED into the hole.
  • Hot glue or epoxy it in.

Step 28: Install the Charging Connector and Power Switch

Get the 3pin charging connector and circular rocker power switch.  see video.
  • Drill a 5/8" hole with a spade bit in the end of the project box.
  • Insert the 3 pin charge connector and put on lock nut.
  • Drill a 13/16" hole with a spade bit centered in the top of the project box for the power switch.
  • Press fit switch in.

Optional:  Add a hole for USB access to the Arduino.  You can see white electrical tape covering mine in the pic above.
  • Place the Arduino with shield in the box aligned with the side away from the connector.
  • Mark the USB connector position on the inside of the box.
  • Transfer the center of the marks to the outside of the box.
  • Use a large drill bit to make a hole for the USB. 
  • Try to connect a USB cable to the Arduino. 
  • Trim to fit using a Dremel tool or file.

Step 29: Drill Project Box Holes and Pass Through Wires.

I didn't shoot video of this step so look at this picture.  
Get your Arduino and your Dimension Engineering Motor Driver boards.
  • Place both boards in box for test fit.   Mark edges of board to ease hole placement.
  • Mark and drill 1/4" holes for power wires on side closest to batteries.  Be sure not to hit the rubber wheels below!
  • Use a Dremel tool or files to widen holes.  An alternative is to use a bigger drill bit so wires will fit through more easily.
  • Drill a 1/4" hole 2.5" from these power wires hole.  This hole is for the control wires.
  • Push through all available wires now.   Make sure that the boards still fit in with wires in place.

Step 30: Tack Down Wires and Connect Battery Wires

Get the 1/4" wire tacks and a short piece of extension cord.
  • Flip over the segway on a few 2x4's or a small bucket so you can work on the bottom.
  • Tack down wires that are loose by hammering in the small tacks.
  • Snake the previously crimped battery cables through the battery holes.
  • Measure and tack the battery cables to arrive under the Project box.  Strip ends.
  • Make a small (8") piece of extension cord cable to pass through hole into project enclosure.  Strip all ends.
  • Twist together the batteries in "series" per the schematic under the Project box location.
  • Twist in the connector cable per schematic.
  • Add in short 8" cable per schematic.
  • Secure with 3 wire nuts or just solder and electrical tape.

Step 31: Get Wires Ready


With all the wires sticking up from the project box:
  • Solder a short extension cord wire to the power switch as shown in the schematic and pictures.
  • Put electrical tape over the power switch to avoid any shorting.
  • Place the motor controller and Arduino boards in the enclosure temporarily.  
  • Find a good final length for the wires and cut them. 
  • Strip the wire ends.
  • Using a soldering iron, "tin" all the wires
  • Optional: Attach small terminals to the control wires. 
  • You can use the straight terminals that came with the MPU6050. 
  • Break them apart. 
  • Use a hemostat or cardboard to hold them while soldering.

IMPORTANT NOTE:
This is from the Dimension Engineering web .pdf for the Saber controller :
"Warning! Be very careful to wire and plug in the battery and connector correctly.
Connecting the battery backwards will destroy the Sabertooth and will void the warranty."

Step 32: Install Batteries and Quick Meter Check

Get the batteries and zip-ties.
  • Put the batteries on the board.
  • Thread the zip ties through the holes and around the batteries.
  • Pull tight on the zip ties so the batteries are secure.
  • Trim off the ends of the zip ties with wore cutters.
IMPORTANT NOTE:
This is from the Dimension Engineering web .pdf for the Saber controller :
"Warning! Be very careful to wire and plug in the battery and connector correctly.
Connecting the battery backwards will destroy the Sabertooth and will void the warranty."

Step 33: Install Electronics

Get the motor driver board, the Arduino and the Arduino shield.

  • Place each board into the box as shown in the picture.
  • Secure each board with screws through the plastic and into the wood.
  • Connect the battery wires.
  • Connect the power wires to the motor controller as shown in the schematic.
  • BE SURE THE BATTERY WIRE POLARITY IS CORRECT. If the + and - are swapped, you will burn out the expensive motor driver board.
  • Install the Arduino shield board
  • Connect the control wires to the Arduino shield as shown in the schematic. ALL WIRES MUST BE TWISTED AND KEPT VERY SHORT!!
  • Solder on the MPU6050 GY521 accelerometer/gyro board right angle pins that came with the board.
  • Insert the accelerometer/gyro right angle pins as shown in picture. Make sure that the component side faces the back of the board.
  • Wire up the pull up resistors, Vcc, GND, and I2C lines as shown in the schematic. Use twisted pair wiring for the I2C wires and keep them very short. ALL WIRES MUST BE TWISTED AND KEPT VERY SHORT!!
  • Connect the wires from the saber to the Arduino.

    Use twisted pair wiring and keep them very short. ALL WIRES MUST BE TWISTED AND KEPT VERY SHORT!!

  • Check Saber dip switches match the picture for 9600 baud. This is to match the serial communication rate set in the Arduino code for communication between the Arduino and the Saber. This is the Saber 2x12 Data sheet for your reference: http://www.dimensionengineering.com/products/sabertooth2x12

Step 34: Test!

At this point, you should be ready to test out your Segway Clone!

  • I would recommend setting the board up on a bucket so the wheels CAN'T touch the ground.
  • Turn on the power switch. Wait 8 seconds.
  • Hold the deadman switch down and move the board forward and backwards.
  • You should see the wheels spin in each direction.
  • If you see the red Error LED on the Saber flashing and the motors start to shake, you have low battery voltage. You either need to charge your batteries OR replace them because they cant hold a full charge anymore.


When this works:

  • Try out the board on the ground.
  • If forward and backward tilt are reversed, flip the pins in the Arduino code.
  • Try out the steering and tilt.
  • Pop out and flip the steering and tilt switches if they are reversed.
  • If you see the red Error LED on the Saber flashing and the motors start to shake, you have low battery voltage. You either need to charge your batteries OR replace them because they cant hold a full charge anymore.

CONGRATS!

Step 35: Optional: Debug

Before you start to debug, check the following:

    • All wiring is as short as possibleas shown in this Instructable. Long wires will get noise on them from the motors and the serial communication will fail. ALL WIRES MUST BE TWISTED AND KEPT VERY SHORT!!
    • The resistors shown in the schematic have been added.
    • The MPU6050 Accel/Gyro is installed and oriented as shown in the Instructable.
    • The tilt switch is for minor comfort adjustments. Don't use it for the tuning. Just try tilting the board back and forth while the board is balanced on a bucket or stool.
    • Make sure to wait at least 5 seconds after power up for the MPU6050 to internally calibrate.
    • Make sure your batteries are fresh. Each battery should measure at least 12V when not under load. If not, replace your batteries.

    This is optional for debug

    Arduino Serial Monitor

    Open the Arduino Serial Monitor. Set it for 115,200 baud

    The code has this line in it:

    Serial.begin(115200); // initialize I2C and serial monitor to 115,200 baud

    To enable printing to the serial monitor, set this to a 1:

    #define DEBUG_ENABLE_PRINTING 0 //normal

    If you are up on a bucket, to avoid holding the deadman switch, set this to a 1:

    #define DEBUG_FORCE_DEADMAN_SWITCH 0 //normal

    To just look at the serial monitor and not have the motors running, set this to a 1:

    #define DEBUG_DISABLE_MOTORS 0 //normal

    recompile.

    The serial monitor screen should output something like this:

    Initializing I2C devices...
    Testing device connections...
    MPU6050 connection successfulI
    initializing DMP...
    Enabling DMP...
    Enabling interrupt detection (Arduino external interrupt 0)...
    DMP ready! Waiting for first interrupt...

    NOTE:

    If you turn on DEBUG_ENABLE_PRINTING and see a message that says: "1024 mpuIntStatus: 19FIFO overflow!", don't worry about it. It is caused by the fact that printing out messages is a relatively slow task for the Arduino processor. While this printing is occurring, the control loop which is trying to pull accell/gyro data from the MPU6050 cant keep up. Eventually, the FIFO holding this data in the MPU6050 has too much data or overflows. The FIFO will recover. When you are done with debug, disable DEBUG_ENABLE_PRINTING flag.

    Oscilloscope:

    if you want to observe the "loop time" of the Arduino code, you can use an oscilloscope to do this. It should be around 10Hz or 10 times per second.

    • Hook a scope probe to Arduino pin 3. Connect the ground as well.
    • Un-comment this lines in the code: // digitalWrite(oscopePin, HIGH);
    • recompile.

    To adjust the base tilt angle in the code:

    If the board powers up and wants to sit at a strange angle, you can use the tilt switch to tweak it OR, you can make a code change to permanently tweak it:

    Look for this line in the code and modify the 80 number to whatever you want:

    // Sensor tilt number below is Determined experimentally. Bigger is more tilted forward. It needs to change if you adjust ANGLE_GAIN. x_accdeg = (float)((SG_filter_result - (80 + balancetrim)) * (1.0));

    Step 36: Optional: Chain Tensioning Block

    If your chain is coming off or it's loosened up, you can add chain tensioning blocks as shown in the above pics.
    • Cut out a pice of 2" x 4" plywood.
    • Drill a 1/4" hole 1 1/8" from one end.
    • Drill a 13/16" hole 1 3/8" from the other end.
    • Press fit a 2 1/4" piece of 1/2" PVC into the larger hole.
    • Secure the other hole with a 1/4" nut, washer and bolt to each bracket as shown in the picture.

    Step 37: Final Notes:


    Low Cost Goal:
    My main goal in this project was to make it low cost and easy to build. A number of design decisions would have been different if the goal was long term reliability, range, power etc.

    Batteries:
    The 12V sealed lead acid batteries used in this project were ONLY chosen because they are very low cost. They are really made for starting gas motors. They are not the best choice for a long life, deep discharge, rechargeable battery. They are prone to failure if they are discharged below 20% capacity. They must be charged after use to keep them from failing. I went through 2 sets of batteries before I learned this.
    Some reading on batteries:
    http://batteryuniversity.com/learn/article/can_the_lead_acid_battery_compete_in_modern_times
    Deep discharge batteries will work better but cost more.
    http://auto.howstuffworks.com/question219.htm

    Weak Point:
    I have found that one weak point of the design is at the interface between the PVC and the board. If you push too hard on the PVC handle bars let's say in a crash, the PVC at that fulcrum may crack. A design improvement would be to use a threaded metal pipe coming up from the board. The top threaded metal pipe would join the PVC at the handlebars. The PVC would have the switches in it.

    Motor Controller:
    The Dimension Engineering Saber motor controller was one of the most expensive parts of this project. I tried two cheaper ebay motor controllers using PWM driven by the Arduino. They both failed to work well and so we needed to use the Saber part. It would be great to find a lower cost alternative to the Saber which is very well designed.

    Future Enhancements (as of 3/2014):
    Here are some future enhancement ideas I would like to see made to this Segway clone:

    1. Voltage monitor circuit. This would be a pair of resistors set up as a voltage divider. They would bring the 24V range down to a 5V range and be monitored by an ADC input on the Arduino. If the voltage dropped below a preset threshold for a certain period of time, the LED would flash at a 2Hz rate to let you know to recharge the battery.
    2. More work to smooth the control algorithm. This Segway clone control is just OK. I think there could be more refinement to the gain adjustment and steering.
    3. Battery research to replace the $32 lead acid batteries with cheap LIPO or LiFePO4.
    4. Find cheap encoders and add them to the wheels.

    ----------------------------------------------------------------------------------------------------------------------------
    UPDATE 12/24/2014: There is a separate Instructable here to strengthen the Segway Clone PVC to Wood junction.

    Step 38: Conclusion

    I hope you enjoyed this Instructable.  This Segway clone could not have been done without the work of others in the Instructable community. 

    If you make one of these Segway clones, please add a picture or video clip to the comments!

    I will end this Instructable with a final safety warning:
    • Riding on a 2 wheel device that is inherently unstable is dangerous.  You will fall off it and crash into things.  You are responsible for your own safety.   Wear protective gear.
    • The real Segway device can be dangerous even though it has safety shutoffs and error detection.  This Segway clone has NO safety detection or elegant shutdown.  Ride at your own risk.
    • This Segway corporation video clip shows some of the dangers riding the real Segway may have.  I found it useful to watch before riding this Segway clone: http://www.segway.com/flash/video/safetyvideo.php
    <p>Good morning Ira,<br>I would first like to thank you for sharing your project with me and I believe in many other people.<br>For the operation I used your code in which I also inserted the power monitor of Fabio Gastaldi. Of its software at the beginning I had tried and modified the steer with the potentiometer but then I went back because your buttons gave me more <br>confidence.<br>I also modified the row in the file MPU6050 as suggested by Fabio and I have made remarkable progress.<br>Now my Seg works really well but I have a little one problem and I would ask for.<br>It seems to me that after several start / stop the control angle changes.<br>I try to explain it better.<br>While at the beginning i just tilt very little to get moving, after several operations this angle changes considerably and I am forced to tilt a lot. <br>In that case I have to turn it OFF and ON again to be able to reactivate.<br>It seems to me that the balancing buttons do not produce affect about the movement.<br>Do you have an explanation for this problem?<br>Thank you again<br><br>Claudio</p>
    <p>Hi Claudio,</p><p>What a cool looking build. </p><p>I haven't had the issue you are observing with the starting tilt angle changing over time. Could it be that there is some kind of intermittent short with the tilt wire? That might explain the built up tilt offset as you ride.</p><p>Please post a youtube video of your machine running for us when you have a chance.</p>
    <p>Hi Ira,</p><p>finally i was able to make things working with the new setup. I had strange values from MPU and motor that often goes 100%.</p><p>In the new setup i have 500W motors and a sabertooth 2x32. (see images)</p><p>I modified the settings from 0x01 to 0x02 (as in my previous setup with 250w motors)</p><p>I added a STEP DOWN from 24v to 12v circuit to power the Arduino, instead of using 5v from sabertooth.</p><p>I twisted cables as you wrote several time :)</p><p>Now it works! I just need to make it more responsive, which parameters do you think i should touch at the beginning?</p><p>Attached some pictures</p><p>Thanks again for the great help</p><p>regards</p><p>Fabio</p>
    <p>That's great news. Twisting the wires is important. Big motors give off a lot of electromagnetic energy which couples into the low voltage signal wires and corrupts the I2C communications. Twisting cancels out this noise.</p><p>I don't believe that the &quot;modified the settings from 0x01 to 0x02&quot; mod does anything. it would be interesting to try backing that out again as an experiment to see if you notice a difference.</p><p>To modify the gain, change this at the top of the code. I would start with ACCEL_GAIN:</p><p>//Variables for GYRO_GAIN and ACCEL_GAIN</p><p>#define ACCEL_GAIN 18.0 //</p><p>#define GYRO_GAIN 5.0 //</p><p>Post a youtube video of the machine in motion if you can.</p>
    It was an amazing experience making this scooter .. My Scooter is finally working and taking all the load easily .. Happy About it
    <p>It looks great! How about sharing a working Youtube video for us?</p>
    <p>Sir,</p><p>As You Suggested I have uploaded the video of my progress for my version of this Project.</p><p>The Problem I am Facing is that the scooter is not able to take its own weight.</p><p>The details of the project are shown precisely in the video I have uploaded :D</p><p><a href="https://www.youtube.com/watch?v=izXGBri9mLI&t=70s" rel="nofollow">https://www.youtube.com/watch?v=izXGBri9mLI&amp;t=70s</a></p>
    Hi Devesh,<br>Nice build and video. You are very close. My first question is what is the voltage on your batteries? Both should be at least 12V when the switch is off. If not, they need to be recharged or replaced if they wont hold a charge anymore. THese lead acid 12v batteries can be permanently damaged if they are over discharged.<br>Is the led flashing on the saber when you have the segway on the ground?
    <p>Hello Sir,</p><p>I have checked the batteries when the switch is off it shows 12V always and yes the RED LED (ERROR) and the S2 LED (BLUE) of the sabertooth also flashes when the scooter is on the ground.</p><p>Also will the gear ratio matter in the build ? </p>
    <p>The red flashing LED means over current error. Sometimes the Saber will vibrate the motors to let you know you have this condition.</p><p>The power requirement of the motors are fixed. If you drop the voltage, you will increase the current needed to run them. That will cause the over current error.</p><p>Either your battery is too low or your wires are too thin. Check both carefully under load this time. Or, your wires are too thin for the load. Make sure they are the size of electrical extension cords as used in the Instructable. If they are thin wires, there will be a voltage drop.</p><p>Yes the gearing matters. 1:1 is not good but I dont think it would cause the severe problem you have. Not sure. You should try to match the gearing of the Razor scooter gears and chain used in this Instructable.</p>
    Thank You for your help sir , my scooter is finally working .. ?
    Okay Sir , <br>I will Change the wires and check .. <br>any specifications of the wires <br>also I dont Need to change anything in the code right ?
    Sir ,<br>anxiously and eagerly waiting for your reply .
    <p>The wires should be the size of an extension cord wire. If possible, get 2 car batteries and try that as an experiment. It's still possible that your batteries are weak or are not rated at 7A each.</p><p>Once you get close, you may want to increase the gain settings at the top of the code. Your video shows that the Saber is cutting out due to an overcurrent error so that is not the issue yet.</p>
    Hello i hart<br>I tried all the possible solution but still I didn't solve my problem of starting torque. so can i increase my torque from the program and which line and what value should i change in the program ? Please help me.
    <p>What solutions did you try? New batteries?</p><p>You can try to adjust the gain settings. Play with these values in the code. Start with the ACCEL_GAIN:</p><p>//Variables for GYRO_GAIN and ACCEL_GAIN</p><p>#define ACCEL_GAIN 18.0 //</p><p>#define GYRO_GAIN 5.0 //</p>
    <p>Thanks ihart i got solution by changing the value in the code.</p><p> mpu.setXGyroOffset(10);</p><p> mpu.setYGyroOffset(7);</p><p> mpu.setZGyroOffset(14);</p><p>mpu.setZAccelOffset(400) </p><p>It works very well!!!!!!</p>
    <p>Very happy to hear that! </p><p>I dont understand why those offsets fixed your slow moving motor issues. Do you?</p><p>Post a video of someone riding it for the community please.</p>
    We have changed the battery to 6 cell lithium polymer battery and somehow it worked.We don't know the reason behind it, do you any idea sir about how the lithium polymer battery worked instead of the 12volts and 7ampher dry cell battery.Also i will soon upload the video.
    <p>sir, have prepared the segway as per the components that you have used in your vehicle.Mine are the same but only the motor is of 350watt and i have used the sabertooth 2x25 motro driver.The battery is of 7amp and i have checked the voltage and is 12.But still i am facing the problem.The vehicle is not responding properly at initial stage when the rider tries to stand on the vehicle.I am attaching the link of the video which shows the problem which i am facing.So please help me out.</p><p><a href="https://youtu.be/SK5x178aoSc" rel="nofollow">https://youtu.be/SK5x178aoSc</a></p>
    <p>Trying new batteries is a great idea. 25AH or more is fine. The batteries amp rating is the max current it can supply. The power required by your wheels is fixed. 350W *2 = 700W V=24V P=IV I=P/V I=700/24 = 29A</p><p>So, in reality, the max current the motors could draw is 29A. You will not need this much current to balance the segway with a person on it. </p>
    <p>Interesting. It looks like it is basically working without a load.</p><p>One thing you definitely need to change is your I2C and S1 serial wiring. They must be twisted with a ground wire or you will get corruption as the motor load increases. This is due to EM radiation.</p><p>The batteries need to be in excellent condition to drive the 350W motors. THey should be charged and preferably new. I remember that my segway behaved like yours when the batteries were bad.</p><p>Does the red LED flash on the saber board when you cant ride it? If so, this means you are having overcurrent issues and the saber is shutting down.</p>
    <p>Sir,</p><p>What is the maximum weight this can hold and how much can a single motor that you used be able to lift?</p>
    <p>he sir i am using 32x2 sabertooth driver and 250w motor and i have connected exactly how u described in schematic but when i connect battery one which is connect to m1a m1b starts rotating on its own i seams there is some different dip switch configuration for 32x2 board pls can u tell me the solrution ASAP </p>
    <p>Hey, </p><p>I had a similar problem in the early stage of the making of this project. The problem got solved by placing the MPU6050 fixed on proper position and also twisting the wires used for connection. </p><p>You can try these and check</p>
    <p>did u use same 32x2 sabertooth driver.?? because i have tried placing the board in every possible way but it is not working </p>
    <p>i have even tried twisting wires i saw your video on youtube i did same on breadboard what actually happening is that when i power in that circuit and even though the deadman switch is open one motor rotates at full speed changing is direction of rotation on its own </p>
    Hey , <br>Did You try fixing the bug in code as well as shown in step no.8/38 under notes .. The First Code fix which sir has given .. <br><br>also I have used 2x25A sabertooth that shouldn't matter much as it depends on the battery readings and types of motors you are using
    <p>yes i have tried it as well and 2x32 is different from 2x25 because 2x25 can only work in serial mode while 2x32 can work in 4 different mode and what i came to know from datasheet of 2x32 is that it is pre configured to 9600baud rate and u have to just set dip switch to get it work in serial mode but that also is not working </p>
    <p>hey there is mistake yes 2x25A board can work in all above modes hey can u just upload the photo of ur dip switch configuration </p>
    <p>Hello IHurt,</p><p>I made a segway as per your steps but, i faced a problem. When i give a power, motor start shaking and sometimes it start to run on full speed. When i put segway on the ground it self balanced but not work when person stand on the segway it does not go forward or backward but without person segway balance it self. I also found that my one battery discharge and one not because i used different batteries may be this problem occurred due to using different batteries. Give me your suggestions as early as possible.</p>
    It sounds like a battery issue if it won't work under load. The batteries need to both be over 12V when you start out. They should be 7A minimum each as shown in the Instructable. The batteries do fail if they are too depleted and not charged in time.
    <p>Hello Ira,</p><p>Last week, I sent a message, but pictures were not added.</p><p>So, you ask me to make a video.</p><p>Here is the link to read it (I do hope this time it will be ok)</p><p>So save your time, I treid to make it clear as possible.</p><p>Best regards,</p><p>Jean-Claude from France</p><p><iframe allowfullscreen="" frameborder="0" height="281" src="//www.youtube.com/embed/dhEFSYjlB3Q" width="500"></iframe></p>
    <p>Hi Ira,</p><p>Still on the infernal machine...</p><p>Back to my video :</p><p>1 - Well seen, around 47 seconds, you noticed two wires on S1 at the Saber. It&rsquo;is a very short lenght of wire which is use to grip the oscilloscope probe.</p><p>2 &ndash; I confirm that there is a direct link beteween S1 at the Saber and Pin 13 at hte Arduino. This wire is twisted with ground connection</p><p>3 &ndash; you tell me to modify arduino code in order to test the Sabertooth. I am unable to do this job. So, I have dowloaded a test progamm witch take in acount exactely the same hardware. I shall tell you the result of the test.</p><p>4 - I have read one more time the instructable, and I have discovered one thing I have not done properly.</p><p>I have not added one individual wire to both twisted pair. I consider if you mention to do so, it must be useful.</p><p>5 - One more question : Has the metalic cabinet to be grounded on the same common point ?</p><p>@+</p><p>Jean-Claude</p><p>PS : I tried to add pictures to this message, but it seems that it doesn't work. When I upload the file, the picture appears at the bottom of the message, but it is a tiny square</p>
    <p>One other thing comes to mind since this is an intermittent problem. </p><ul><br><li>Make sure your batteries are fresh. Each battery should measure at least 12V when not under load. If not, replace your batteries.</ul>
    <p>Let me know how the saber &quot;test program&quot; test goes.</p><p>The metallic cabinet does not have to be grounded. </p><p>I can see one picture which looks larger when I click on it.</p><p>Debugging is tough. I do it a lot. It will feel great when you solve the problem!</p>
    <p>Sorry for the reply delay Jean -Claude. Just returned from vacation. </p><p>The video looks good. at around 47seconds in, It looks like there are 2 wires connected to S1 at the Saber. Why is that? It should be only 1 wire.</p><p>On the green wire from S1 to Arduino board, this should go to pin 13. It's hard to tell in the photo but it looks strange. </p><p>All the wires from the steering and tilt switches should be twisted with grounds. If not, it can couple noise to the Arduino. You can see my son doing this with a drill in the Instructable video.</p><p>I still think you have I2C noise getting into the system or a wiring issue. If you have ruled all these above problems out and really think the Saber is a problem, try: </p><p>modifying the Arduino code to just drive the saber wheels with a delay. No I2C accel readings at all. For example, Mot0 clockwise for 2 seconds at a slow speed then stop for 1 second then CCW for 2 seconds and repeat. Try the same for Mot1. This will prove out the Saber. </p><p>Let me know how it goes.</p>
    <p>MPU6050 connection successful</p><p>Initializing DMP...</p><p>Enabling DMP...</p><p>Enabling interrupt detection (Arduino external interrupt 0)...</p><p>DMP ready! Waiting for first interrupt...</p><p> fifoCount: 1024 mpuIntStatus: 19FIFO overflow!</p>
    <p>@SafetyfirstS Did you happen to find solution for this problem or found out what was causing this issue?</p>
    <p>I am making this as my final year project. But sabertooth motor driver is not available. Can you suggest any other motor driver for this project? And what all changes have to be done in programming with the new motor driver?</p>
    <p>Hi guys!</p><p>I'm currently making my own Segway clone as a college project but I've run into difficulties with the MPU6050. When the deadman button is pressed the motors go 100% in one direction and the gyro seems to have no effect on them. </p><p>Everything else works perfectly (LED, Steering, Deadman button)</p><p>Any assistance would be greatly appreciated. </p>
    Hi Niall,<br>I assume that you have the segway up on a bucket when you push the deadman switch. Does the segway respond at all when you tip the board or just slam to 100% no matter what you do? <br><br>Is the MPU 6050 oriented as shown in the picture and up on the top of the board in a box?<br><br>Are you sure the I2C communication is good? Pullups, twisted wires? Noise can easily couple in and you will get bad Accell gyro readings. The debug section shows how to use the serial monitor to see the actual Accell gyro readings from the MPU6050. It's cool and you should try it.<br><br>Re-read the instructable and check the schematics carefully for the I2C connections and the S1 connections.<br>
    <p>The motors slam to 100% no matter what orientation the gyro is at. I'll check the wiring again for noise and such, but nothing seems to be making any difference to it. </p><p>I'll try the debug. Thanks for replying!</p>
    <p>I've tried the fix mentioned above, changing the number from 0x01 to something higher, but that still has no effect. </p>
    <p>great instructable! Is there any way I can build this with just a castor wheel attached to the front, without the Segway balancing? If there is could you explain the how I would do it, and what extra parts I would need. Thank you! :) </p>
    <p>Yes, the Arduino code could be modified to ignore the Accel Gyro and just follow the steering switch. What are you using this for?</p>
    <p>Hi!</p><p>I have built the clone as per your direction.</p><p>Kindly let me know how you set the dimension for the segway measurements.</p><p>Whether you use equations or something else.</p><p>Kindly let me know.</p>
    <p>The dimensions for the segway were found experimentally. For example, I measured the size of my foot and the box needed to determine the size of the platform plywood. No advanced mathematical calculations or formulas were used for that. Does that answer your question?</p>
    <p>Thank you ihart !</p><p>But if you know about any mathematical calculation or formula for segway dimensions kindly let me know.</p><p>Thanx</p>
    <p>Hello Ira,</p><p>A few months ago I posted some questions of course about the construction<br>of the segway clone.</p><p>At the time, there were several dysfunctions. Then, I modified the wiring,<br>and I changed the gyro card, so things<br>got a bit better.</p><p>For personal reasons, I put the construction a bit off, and I'm recovering<br>now.</p><p>There is something weird about the Sabertooth card. That's what happens:</p><p>I turn on the power (24V)</p><p>I wait for 8 seconds</p><p>I do not press the deadman switch</p><p>If I connect a voltmeter to the M2A / M2B output of the Sabertooth board, I<br>measure 0 V with a voltmeter in DC <br>position and +/- 3.75 in the AC position. So, the motor rotate very<br>slowly. Here is the picture of the signal.</p><p></p><p>f I do the same on the M1A / M1B output, I measure 0V both mode (DC and<br>AC). Here is the picture of the oscilloscope on this channel</p><p><br></p><p>In addition, here is a picture of the signal that comes out on pin 13 of<br>the Arduino card (still without pressure on the dead man switch)</p><p></p><p>If I press the deadman switch, the operation is eratic with apparently an<br>IC2 bus break.</p><p>Of course, all your advice has been followed (wires twisted by pair +<br>connection as short as possible + pull resistors + battery fully charge + DIP<br>configured as indicated in the instructable).</p><p></p><p>To be sure to be completely free from possible<br>parasites, I tried to power the arduino card with a 9-volt battery, but that<br>does not change anything</p><p>Here are some questions:</p><p>Since the fact that motors do not turn, I consider that<br>parasites cannot interfere on the system &ndash; Yes or no ?</p><p>Why are the signals on the two outputs different?</p><p>Is it normal to have a signal on pin 13 of the Arduino card without<br>pressing the deadman switch ? To me, it would be seem more logic to get no<br>signal at all.</p><p>What kind of signal should be read on the pin 13 either without pressure or<br>pressure on deadman switch ?</p><p>Is my signal seen by the oscilloscope on pin 13 correct ?</p><p>An Arduino card is very cheap and easily available. So, I<br>could try to connect a new one. On the other side, a Sabertooth car is<br>expensive. How could I be sure that my sabertooth card is fully<br>fonctionnal ?</p><p>Many thanks for your help.</p><p>Best regards </p><p>Jean-Claude (France)</p>

    About This Instructable

    487,058views

    1,937favorites

    License:

    Bio: I'm an Electrical Engineer with "engineer disease." I need to always be making, fixing or learning about something.
    More by ihart:Update: Segway Clone - Stronger Design Modification Wood Bike Rack for 5 Bikes, Fast and Low Cost Build Rideable Segway Clone - Low Cost and Easy Build 
    Add instructable to: