loading

This Instructable is intended to share my hobbyist project: a Self-Balancing Personal Transportation (SBPT), also known as "Homemade Segway". It is an interesting project requiring a minimal knowledge in electronics and some handcraft skills. All the components can be bought in internet and the mechanical parts assembly can be done in your home workshop.

The SBPT consists in a platform to stand on vertically with 2 side electrical motors powered by batteries. The controller algorithm ensure the balanced position to not fall forward or backward. The 2-wheeler motion is controlled by the rider with the tilt and the handle for the direction. Therefore additional electronical components like a controller, motor drive and acceleration/gyroscope sensor are required. The mechanical framework is made with material like wood because it is lightweight, electrically isolated and very easy to work for prototyping purpose. The description reflects the current status and will be updated with the coming optimizations and enhancement according to the readers’ comments. The way the hardware configuration and the software purpose are documented is to give you a reference which one you can modify to meet your needs. Finally, it is your homemade project!

Adrian Kundert

Step 1: Application’s Target Definition

The goal here is to state what we want to achieve with the SBPT. This will lead what and how the vehicle has to be build up. In my case, I wanted the following features:

- Enough powerful and rugged to ride outdoors even on gravel path

- At least 1 hour operation range

- Total cost less than 500€

- Wireless communication at debugging to get all motion freedom

- Data logging on a SD card for troubleshooting over a long period

Step 2: System Design

The schematic above shows the wiring of the main components as well the worm gear motor. The Arduino controller can be the Uno, Nano or the ATmega328 as single IC. The batteries are connected serial to get 24V which supplies the dual H Bridge for motors. This one is only powered as long the rider holds the ready button. In emergency case, the rider just release the push button to get unpowered the motors. The Arduino controller uses the serial communication in the “Packetized” mode at 38400 baud with the H-Bridge and the wireless module XBee. The tilt and steer are measured by an acceleration/gyroscope InvenSense MPU-6050 sensor in a “GY-521” on 2 separated breakout board and communicate with the Arduino by I2C. The tilt sensor (address 0x68) which is the most important is programmed to sense at every 20 ms and gives an interrupt to the Arduino. The second sensor (address 0x69) is pulled by the Arduino. Finally, the rider loaded limit switch is aimed to detect when the rider stands on the SBPT in order to activate the balancing algorithm.

Step 3: Framework Construction

The wheels and gearboxed-motors are hold by screws into 3 pieces of wood assembled in a U form box. The handle is a wood stick hold by a bolt in the front wood piece. Very important is that the weight distribution SBPT is balanced when held vertically, which is the riding position. For this verification, the heavy parts like the batteries must be considered, otherwise it will be more difficult for the balancing algorithm.

In my case, the batteries are placed rear in the wood box to compensate the motor weight which in centered. At the remaining space between the batteries and the front of the wood box is placed the electronics components.

On handle is taped the “rider ready” push button. Sorry about the very prototype status with a lot of tape and Vise Grip usage.

Step 4: Electrical Wiring

The wiring in the wood box is done according to the system schematic. The Arduino pinout table gives you the wire connection to the sensors, h-bridge and switches.

The tilt sensor is mounted flat horizontally to get the x axe angle. However, the steer sensor is mounted vertically to get the left/right steer angle with the y axis.

Step 5: Testing and Tuning

Don’t forget: the motors can be powerful! Ensure the trial is done in a wide and safe area to not cause damage or injuries. It is recommended to wear protection pads and a helmet.

Important is to proceed step by step. Begin by programming the Arduino (download the source code), then verify the communication with the sensors and afterward with the H-Bridge. The Arduino Terminal can be used for debugging and to verify the working status. For example, the PID gains must be tuned because it depends of the motor mechanical and electrical proprietries.

The gains can be tuned with this typical method:

1. Kp is mainly for the balancing. Increase Kp till the balancing become instable, Ki and Kp remain 0. Reduce Kp a bit to get stable again.

2. Ki is for the acceleration/deceleration by the tilt. Increase Ki to get the right acceleration to avoid falling when tilting forward, Kp remain 0. The balancing should be now is stable.

3. Kd is used to compensate the integration and get again a stable the balancing.

In Terminal, you can get the differents commands by the command "?".

________________________________________________________________________________________

? - Help for the commands

p,i,d [value] - Set/Get PID gain, value between 0 to 255

r [value] - Force the motor speed, value between -127 to 127

v - Software version

________________________________________________________________________________________

With the command "p", you get the Kp. With the command "p 10", you set the Kp to 10.

Once the Arduino controller is powered, the sensors are initialized and finally the waiting state is reached. Pressing the push button will signal to the controller the SBPT has to be prepared by getting the vertical position by activating the motors forward or backward dependant the initial position. From this point, this button has to be held otherwise the motors are unpowered and the controller goes back in the waiting state. Once the vertical reached, the controller is waiting the signal from the “Rider Loaded” limit switch, normally pressed by the foot when get on the platform. When this happen, the balancing algorithm is launched and will activate the motors forward or backward to stay in a vertical position. Leaning forward will create a motion forward, and vice versa. Keep leaning will increase the motion speed. Leaning in the opposite side of the motion will decrease the speed. About the direction left or right, just move the handle in the desired direction.

Step 6: Demo

Here you can watch a short video as a demo to see the dynamical behaviour of my SBPT. This should be the funniest step of all!

<p>Hello Adrian. I want to assemble a Segway according to your drawing. Please help. Can't deal with the connection of the relay and connecting the gyro to the arduino. Send me please circuit diagram your device for email. tolikhoroshev@mail.ru</p>
<p>Can you share where to order the motors and wheels?</p><p>Thanks,<br>Mike</p>
Hello Adrian plzz mail me connection diagram for the relay module u have installed at Tushar.soni38@gmail.com regards tushar
<p>You use state-space control? ie state-feedback? Or is it PID.</p>
it is a simple PID.
<p>Dear readers</p><p>Here an update after a few month of trial and testing.</p><p>- The mechanics, motors and power electronics work like a charm.</p><p>- The balancing algorithm is limited when the motor reach is<br>maximum speed. Pretty simple to understand: if you lean forward or backward,<br>the speed has to be increased to compensated, but if the motor is already a<br>max, it is not possible anymore, so you fall! I was aware of that and without<br>knowing the motor speed, it is always a guest if I can still lean or not.<br>Therefore, I added a buzzer (or a vibration motor) in the handle activated by the ARDUINO when the motor speed is<br>over 90%.</p><p>- It happened a few time that my ARDUINO NANO had to be reprogrammed<br>because it lost his program!. This happens when the motors regenerate current<br>while driving down a hill.</p><p>I would say thank you for all shared comments.</p>
<p>Hello Akund, a progress question. My example has been done and running great for a week or so. It died today, and I after exhausting other possibilities, I am wondering if there is an issue with the MPU6050 devices. Currently, as I think you do as well, I operate the arduino at 5v, as 5v is required for high speed 16mHz operation. But the MPU6050 is a 3.3v device. I took a chance and ran it without a fancy level shifter at 5v, and it has up to this point operated fine. Just wondering out loud if that's how yours operates, and if it's given any trouble.</p>
<p>hi Bill</p><p>Nice project!</p><p>Nope, I never had problem with the MPU-6050 / GY-521 break-out boards. This board has his own suppy regulator, it muss be supply with 5V. Just the logic signals (SCL and SDA could be shifted to 3.3v. The arduino input is 3.3v compatible.</p><p>regards</p><p>Adrian</p>
<p>Oh, just one more thing. You can see my temporary grey cable...it wires to (3) 10k 10-turn pots glued together, I adjusted the code to read on startup via analog inputs, the pot settings, these are translated to my PID settings. Allows a simple adjustment in the field using your fingernail even, a quick reset and you're off with fresh PID settings to test. When done, I'll tuck the cable down inside.</p>
<p>Notes on the pics I added....I installed 12v strip leds on the underside and front. Shines the surrounding area really well operating at night. I didn't want to hold a button down all the time, so added the emergency red cord, it's tied to the operator, and wired to disconnect battery power in the event of an &quot;unplanned departure&quot;. Because the motor controller is capable of running on forever with its last speed command if the arduino craps out for some reason. I also added a line of code to include the &quot;rider loaded&quot; switch along with the button press switch (bypassed here) so that if you step off, it shuts down via computer. Works great. Added a dc meter I had lying around, it monitors the 2 lithium polymer series 12v 13AH packs I built for the project, there's a switch to shut it off, as it requires its own 9v battery source. Installed a 12v switching power supply and AC cord in the underside to charge, wired through a DPDT switch wired to parallel the 2 12v batteries for charging. So down position is charging, middle is off, up is ready. I used an old Hoveround for the motors and chassis, they work great. I machined some adapters to mate the small Hoveround hubs to a 4-bolt pattern standard US-style trailer hub, after machining off the unnecessary steel to minimize the weight. Used 2 spare trailer tires I had lying around. This thing is fast! Way too fast to allow it up to full speed, unless you like the risk of faceplanting on the asphalt when something goes wrong, like a pothole or a computer crash. Very happy overall with the project, highly recommended for those with the skillset. </p>
<p>Logging some of my build notes here for others' benefit. One: don't forget the address pins on the MPU6050 devices. Figured that out the hard way. Second, and not sure the answer yet, the PID settings are tricky. Currently I am using 1,28,6 for the PID constants. I revised the code to incorporate (3) 10-turn pots for PID settings. I think it best to be able to revise things on the fly, while out in the street or parking lot without hassling with other devices. Bench testing indicates my PID settings are on the money. A little tweaking once test running for real, should be good to go.</p>
<p>Another interesting note. The code spits out plot data, you can open the serial plotter(instead of the serial monitor in the Arduino IDE) and it plots what appears to be PID gain and some other variables. Interesting to watch.</p>
<p>For the PID settings, I think I would add some active control, whether by mechanical pots or an lcd and joystick, to allow on the fly adjusting. I mean once the code is loaded, that's all that needs adjusting right?</p>
<p>Yes, some tuning control are very<br>useful. </p><p>To simplify the amount of component and the wiring, I have<br>implemented commands with the Arduino Terminal for the PID tuning. In the step<br>5 is described how to tune the Kp, Ki and Kd separately.</p>
<p> I did see that, thanks so much. I guess with the Xbee, over serial. Was studying the code last eve. A couple things I might suggest for others....the motor driver I think, could be swapped to (2) $8 PWM double h-bridges, with little change to the code. Unless there's something I am missing. Also the Xbee is rather pricey, around $38 or so, while a bluetooth Bee is like $5 or so. I would probably change to that.</p>
I'm in a group that has building an almost identical project and the $8 PWM will not last too long. The motors are basically electric wheelchair motors and use a lot of current. I have my doubts about the suggested motor driver but we will use them with fan cooling.
<p>1. BTS7960-43A Motor Driver is what I will be testing. It's good for 43 amps and seems to get good reviews. Though I see there are various suppliers, some poorly made and fail early.</p>
<p>At the beginning, I wanted to use the Arduino PWM and drive an external H Bridge. So I bought on eBay a &quot;60A Dual Motor Driver Drive Module H Bridge&quot; with the BTS7960. I had doubt when a saw the size of the screws for the wires. Yeah, it began burning at the very first switching on. </p><p>Another con was the highest PWM frequency limited to 8 KHz, which is still audible.</p>
<p>You'll quickly learn that you can't buy cheap electronics when it really matters. Otherwise - great job!</p>
<p>Is there any alternative for the motor controller? Sabertooth isn't available at stores where I live.</p><p>Waiting for your response.</p><p>Thanks</p>
<p>hello.. I want to do this project.. :D but there's no seller in my country which sell sabertooth dual motor driver.. and i want to replace that with BTS7690 motor driver.. do u think it will work or not? please help me.. :)</p><p>waiting for your answer.. :)</p>
<p>no. Please read the comment I have done about BTS7960 to BillK27, 22 days ago.</p>
<p>Ok, I tried the IBT-2 motor drivers we spoke of. They are fine but noisy at standard Arduino PWM frequencies. Adjusted the PWM to 10kHz, and the driver smoked in seconds. Ugh. Ordered the Sabertooth. :-)</p>
<p>hello sir , great job on that clone segway :) is possible to have a decent schematics? im sory but im still a amateur.</p>
<p>Something of concern, but maybe you have it handled. What about rolling over uneven surfaces? The steering gyro will feed back incorrect tilt since it only sees overall tilt. How is this effect seen in real life operation? Most builders seem to opt for potentiometer steering for that reason. Maybe it's not an issue overall.</p>
<p>Your remark is very good. The concept here (like for the real Segway), is that the rider stays vertically whatever the position of the PT. This mean when the left wheel is higher than the right wheel, the rider has to lean the stick to the left (get vertical) to not turn right. For me this behaviour is more &quot;natural&quot;, then the poti steering.</p>
So I think you are saying, this works more naturally with the tilt sensor, and possibly even the real Segway uses this concept?
<p>Hello, I'm Edward's Braziu, thanks for posting this detailed well and it is possible to do, do.</p><p>But you have the link to purchase the engine and batteries etc?</p><p>Thanks and a hug</p>
<p>Also you mention using Xbee for tweaking settings, updating code, but I don't see any drivers or mention of Xbee in the code?</p>
<p>It is the xbee default configuration. You take 2 Xbee modules (1 connected to Arduino, the other your PC). They talk together to bridge the serial communication.</p>
Could ESP8266 modules be used, then the tweaking vould be done on a phone
<p>it should. See https://www.instructables.com/id/Using-the-ESP8266-module/</p><p>I had already the XBee module, that s the reason of my choice.</p>
<p>Any idea where to get those motors? I can find the specs and the site of the manufacturer but am not having any luck finding a place where they actually _sell_ them.</p>
<p>Are you able to stop and have it balance in place while standing on it?</p>
<p>yes. almost standing. it moves slightly back and forth. The perfect standing is not possible for any self-balancing system.</p>
<p>Great device. Love the video.<br>Is there a full parts list? How is the wireless sensor used?<br>Can you provide more detail of how the broom handle is attached and connected to the tilt switch to achieve steering/</p><p>Please.......</p>
<p>there's no wireless sensor. Wireless is the serial communication instead via the Arduino USB interface. </p><p>I have added in the step 4t he mounting schematic of the steer sensor to the stick.<a href="https://www.instructables.com/files/orig/F7X/1DX7/IJUCJQM2/F7X1DX7IJUCJQM2.pdf">https://www.instructables.com/files/orig/F7X/1DX7/I...</a></p><p>The tilt sensor is pinned in the bread board.</p>
<p>Looks like I can build it with the info provided. I downloaded the code, it assembles fine. Question is, is the device reliable enough, from one use to another that the PID constants don't need tweaking? I see some others are unsure of their devices once constructed, they're always playing with the settings.</p>
<p>If it is one thing that cannot by</p><p>&quot;copied&quot;, it is the PID gains. It depends fully on the motor<br>electrical proprieties and the mechanic like the weight distribution. But don't<br>worry, the gains can be tuned with the common method.</p><p>1. Kp is mainly for the balancing. Increase Kp till balancing<br>become instable, Ki and Kp remain 0. Reduce<br>Kp a bit to get stable again.</p><p>2. Ki is<br>for the acceleration/deceleration by the tilt. Increase Ki to get the right<br>acceleration to avoid falling when tilting forward, Kp remain 0. The balancing<br>should be now is stable.</p><p>3. Kd is used to compensate the<br>integration and get again a stable the balancing.</p><p>That roughly summarized. The<br>tuning can be tricky if you don&rsquo;t understand the dependencies.</p>
<p>Hello akund, i made one in a little time ago, but i have problems with my self-balance. chash all the time. i think your project more simple. my ask is, what happens when the battery is discharging ?</p>
<p>Both batteries provide my 24VDC. The 5VDC electronics (Arduino and auxiliary) are supply by a converter 24V to 5V. The Sabertooth H-bridge works in 6-28VDC range.</p><p>The batteries voltage is more than 26V when full charged. Then the voltage drops slowly during operation till reaching 23VDC. At this point the voltage drops massively when demanding current, enougth to causing failure operation in the H-bridge. So the electronic is still working, but H-bridge do not respond anymore. Time to recharge!</p>
<p>Ok akund. In my case, my batteries is 12VDC, i put in serie to get 24VDC and 7A. But i think the current is low for motors and the noise crash the arduino. I will try change my batteries to have a good time to enjoy and don't crash. currently, i don't use my sef-balance because this problem. Thanks akund. I return with the results.</p>
<p>Are you able to stop and have it balance in place while standing on it?</p>
Hello! I love this project! what are the specs on the motors you used, or a link if you have one, Thanks!
<p>Hi</p><p>I have added the worm gear motor specs in the step 2 or here is the link</p><p><a href="https://www.instructables.com/files/orig/FJQ/8VFU/IJG00CP0/FJQ8VFUIJG00CP0.pdf" rel="nofollow">https://www.instructables.com/files/orig/FJQ/8VFU/I...</a></p><p>regards</p>
<p>Hi, great project!</p><p>The PDF you attached for the motors seems a generic one, describing an entire family of products.</p><p>From the picture I cannot read the model / type on the label. Could you please take a better picture or post the model number? thank you</p>
<p style="margin-left: 20.0px;">Type: PMGST 80/65-R, Nr 08016912</p><p style="margin-left: 20.0px;">24V DC/13.3A, 250W</p><p style="margin-left: 20.0px;">4900 rotation/min, gear box 28:1, IP43 / Class F</p><p style="margin-left: 20.0px;">Product number: 038.6055 06/2008</p>
<p>thank you!</p>
<p>Very nicely done.</p><p>You say one of your bigger problems was dealing with backlash; I presume you've sorted this out in the software? Is this going to give me problems if I end up with a slightly different gear train from the one you've used?</p>
<p>For an ideal balacing object, the motor should be direclty binded to the wheels to avoid backlash. I think it is more possible with chain than a gearbox. The backlash creates back and forward instability caused by the &quot;gap&quot;. This could eventally considered by the balancing algorithm. But in my case, this problem could by passed because the passenger's weight stabilize and he works together with the balacing algorithm. So the backlash is compensated by the passenger assistance. </p>

About This Instructable

58,420views

689favorites

License:

More by akund:Self-Balancing PT (homemade Segway) 
Add instructable to: