As an avid maker of "things that Seg" this one is inspired by the 1970's Raleigh Chopper bicycle.
I was recently involved in the Hackaday competition with the MediCycle: MediCycle This was a big one wheeled electric motorbike styled machine. Impressive looking maybe but quite difficult to ride and if you fell off it really hurt:
I have also built all sorts of other self-balancers after starting in 2008 with a skateboard design: self-balancers site
Having learned the lessons, for this machine the objectives became clear:
- Lightweight, fun, more like a bicycle in construction.
- It is strictly not a unicycle but is a di-wheel or di-cycle.
NOTE: I have other instructables describing self-balancers that would be easier to build than this one. This one does require some tools, fabrication skill and a welded frame. The self-balancing electronics described here could be used in other projects with slight modification, such as a Segway, and are up to date using an easily obtained digital IMU.
Extra features 01/01/2015:
- Twist grip speed control on left handlebar.
- Uses a gyro to resist sudden spins when going straight, for example if one wheel hits stone.
- Brake levers each side are actually to steer left or right.
- Overspeed "lean back" automatically stops you going too fast and falling off the front if motor power >70%.
- If you pull both steering levers simultaneously, they act as a handbrake and machine will lean back and slow down.
NOTE: 27/05/2015An error in the wiring diagram has been corrected. "Deadman" switch is wired to digital pin 4.
NOTE 23/6/2015:One person building this found that the IMU "locked up" and stopped talking to the Arduino. He solved it by making sure he used the SAME GND PIN on the Arduino for both the IMU GND wire and also the 0V wire from the Sabertooth. There are several GND pins on an Arduino Mega and they are connected to each other on the board, however he found it was more reliable if you use the same one for all your GND connections to the Arduino.
Main parts list, not everything, but the main key parts:
- Sparkfun 6dof digital inertial measurement unit (IMU). (Part No. SEN10121). Most of my previous projects used analog output IMU's which were useful as you read the voltages from the gyro and accelerometer sensors using the analog ports of an Arduino. For this project I am reading the tilt angles using the FreeSix IMU code of Varaseno. $39.95
- Arduino Mega 1280 (same price online as an Uno, but has hard wired serial ports which are useful). As low as $16
- Dimension engineering Sabertooth 2 x 25 Amp motor power controller. Not the cheapest but has self-protection features which reduce risk of it burning out, so can be used in all your other similar projects. $124.99
- LED battery voltage indicator. Incredibly cheap on ebay. Example: $1.65 inc. shipping! LED voltage indicator
- Serial LCD display module. Example: 4 x 20 Serial LCD display NOTE: Some cheaper ones on ebay don't always work. Get one from a supplier that also sells Arduino's. Not essential to have this but useful for status updates as you ride the machine. Approx $29.95
- MY1016Z3-24V brushed gearmotor x 2. Has 6:1 reduction gear built in and sprocket for a chain already fitted. Designed for electric bikes. Comes with sprocket that fits 410 standard bike chain. $76.49 x 2
- 410 standard bike chain. NOTE: In the photos I am using belt drive but to be honest if doing it again I would stick with chains.
- Two big sprockets to fit to wheels. Needs to have between 4 to 6 times as many teeth as on the motor sprocket. Make sure they are for 410 bike chain. Get cheaper solid steel ones possibly, as easier to drill the 6 holes that will allow it to be fitted to the disc brake mounts of the wheel hubs.
- Mountain bike front wheel hub (with 6 threaded holes for mounting a brake disc) x 2.
- BMX bike rim x 2, fitted to the above hubs for me by a bike shop. The reason I did not use a BMX wheel and hub off the shelf with disc brake mounts is because apparently very uncool to have a BMX bike with disc brakes so disc-brake BMX wheels are not made. Need tubes and tires too.
- Same bike shop fitted a spacer tube between inner and outer bearings of each hub. This means they can be compressed sideways by a bolt later on without huge side-loads being placed on the bearing internal rollers.
- Rally car emergency power-off switch. For safety (stops small children turning it on when you are not with it), can handle 100 Amps, and looks a bit like the Raleigh Chopper gear-shift from a distance.
- Battery holder for 6 AA batteries. To power the Arduino separately from the motors. I prefer to do it this way so Arduino gets stable ripple free voltage no matter what punishment you are giving to the main battery.
- 24V battery. I used a "Headway" kit of 8 LiFePO4 cells. You could also use 2 x 12V 7Ah (or above) lead-acid batteries to save money which would be fine but would not run for as long. I mounted mine in a box in a holder which allows the pack to be easily removed and inserted in another project so may save money in the long run. $273 from China.
- "Ape hanger" handlebars for a chopper style bicycle. Real Raleigh Chopper ones are stupidly expensive so I used generic copy. $30
- Long saddle. Again a real Raleigh Chopper one would be very expensive even in poor condition. However in the US there are loads of companies making low priced "banana seats" which look nice, are long, and I think are made for retro styled Schwinn bikes. Mine came with a rear chromed "sissy bar." $30 with chrome bar.
- I mounted my motors and wheels on two thick alloy plates. You could weld up a frame to do the same job but make sure you measure everything lots of times.
- 40mm spacers (also sold as "stand-offs"). 8mm thread one end and 8mm socket the other end. These were important to get the geometry of everything correct. Correct name is: "M8 Stainless Threaded Stand off Pillar Bolt Extender Extension Fitting" About $9 each but worth it. Example from UK ebay
- Box section steel. 1 inch for seat mount etc and some 40mm wide so it exactly fits between the two plates that have been bolted together using the 40mm stand-offs.
- Big fuse say 75 Amp and holder for it.
- Twist-grip 5K Ohm potentiometer. In reality there is only one make of these, used as throttles for electric scooters, made by Magura. Example US link: Magura US example Link to a UK seller: UK example seller$60
They also sell a matching regular handlebar grip for the other side that matches.
- Children's electric scooter brake lever x 2. Search and you can find them very cheaply. Approx $5. They have an electric switch in them which means we can use two of them to steer left and right. Example link: E scooter brake lever
Step 1: Why Inspired by a Raleigh Chopper?
Raleigh built a copy of chopper-like Schwinn Sting-Ray, launched it in 1966 in the US, but it was not a success. They sent their chief designer, Alan Oakley, to the US to look into the youth market. On the flight home he drew the basic design on the back of an envelope. At around this time drag racing was becoming popular in the UK after some US cars had come over for exhibitions. The 1972 Raleigh Chopper was a hit and is now a cult classic bike. It had the wide large rear tire with the small front and these had red lines on the sidewalls. The "ape-hanger" handlebars, long saddle and plenty of chrome completed the look. The final touch was the chunky gear-shifter dangerously placed in front of the seat, connected to a 3 speed gearbox. It had some stability problems, two people could fit onto the Mk1 saddle at the same time, it was heavy and hard to ride long distances. However to a 12 year old it was just the height of 70's cool.
I am basing the latest self-balancer loosely on the Chopper for several reasons.
- The previous machine (MediCycle) for the Hackaday competition was big, heavy and like a one-wheeled motorbike, designed for maximum visual impact. It needed to be treated with respect and if you fell off you would be likely to get hurt, as I know from personal experience.
- This new machine is to be built with lightness in mind, more like an electric pedal bike in design.
- It needs a long saddle so you can position yourself back and forth along it so that you have your weight at the correct balance point to make it work. Clearly a Chopper-style saddle would be very convenient for this compared to a regular bike or unicycle saddle.
- The "ape hanger" handlebars also conveniently can be mounted so they stick forwards in front of the wheel to get the weight distribution of the rider correct, while using the least metal tubing to do it.
- It gives me an excuse to put some chrome at the back of the seat and on the handlebars for a bit of "bling."
Other experimental features being tested out:
- Toothed belt drive to avoid any slackness in chain when moving from forwards to backwards. It works fine but to be honest I might just use chain drive if doing it again, they would probably have been fine.
- Aircraft grade alloy mounting plates for the entire drive mechanism each side.
- DiWheel design (2 wheels one next to the other) BUT not like a Segway, the legs of the rider will go OUTSIDE the wheels. This should make it relatively easy to learn to ride, stable even when stationary, capable of turning on the spot.
- Could even be seen as a radically different "take" on the concept of a disability scooter.
- Lowish seat height so feet can easily be put onto the ground if any malfunction.
Step 2: Cut Shaped Hole in Alloy Plate to Take Motor.
I used two rectangular alloy plates and cut holes in them to allow the gearmotors to bolt "through" them as shown. By using washers you can move the motor in and out a bit by using them as spacers.
I also fitted toothed belt sprockets to my motor but to be honest I would just use chains and the existing chain sprockets that come on the motors.
Step 3: 40mm Stand-offs Used to Bolt Two Plates Together.
The two plates have to be bolted together later on in a slightly unusual orientation. They also have to be spaced about 40mm apart. Easiest way to do this neatly and accurately was to use 4 stand-offs which were 40mm long.
These had an 8mm thread one end sticking out and an 8mm female thread the other end to take an 8mm (M8) bolt.
Step 4: Another View of Motor Mounted to Alloy Plate.
I would use chains not toothed belts and place the axle bolt so the chain is just slightly loose. If too loose you will need an idler wheel, but, if you get it right, you may get away without one.
NOTE: A roller skate wheel makes a good idler wheel if you do end up having to use one.
Step 5: Alloy Plates Bolted Together Offset From Each Other With Axle Holes Aligned
The holes that will take the long bolts that comprise the wheel axles have to be lined up else wheels will not be level with each other!
Measure up where the holes need to be very very carefully. See notes in the image. I put a very long bolt between my axle holes to line them up, then drilled the holes for my stand-offs accordingly.
If you made your machine wider, you would not need the motors to "overlap" each other like this. I did it as I wanted wheels to only be about 8 inches apart, with my legs on the outside of them.
Step 6: Mountain Bike Hub
This is the side of the hub that does not have the bolt holes for the disc brake. These holes are for the spokes when it is assembled.
See the bearing uppermost, with a tube visible inside between it and the bearing on the other side.
Step 7: Other Side of Wheel Hub.
This is the other side of the hub. There are 6 threaded holes to take a brake disc. Instead of a disc we will attach our large chain sprocket (with 6 holes drilled to match and arranged so they are in exact centre of the sprocket).
Step 8: Big Sprockets Bolted On.
Here my large (and very heavy as it turned out) toothed belt sprockets are bolted to the hubs with a ring of 6 bolts. I would do the same thing but with a regular bike chain sprocket and stick to chain drive.
Step 9: View of Plates Bolted Together and Wheels Assembled.
Two views of whole drive train assembled.
Step 10: Let's Weld a Frame
Frame can be however you want it.
To keep weight down I used as little metal as I could. Battery box needs metal frame around it to protect your expensive battery if you crash. Notice how the "banana seat" rear end is not held just by the "sissy bars" that came with it (see later images) but actually fully supported by a proper welded frame.
The "Chopper" handlebars are ideal as they can be angled forwards so when you sit on the machine your weight is "forward" enough to be completely over the axle line. Tack-weld the handlebars on until you get the angle right before you weld it up properly.
Step 11: Frame Side View
Side view of frame bolted to the alloy-plate drivetrain assembly we made earlier.
Lower box section of frame is a horizontal section 40mm wide so it exactly jams in between the tops of the two alloy plates (which are also 40mm spaced due to the 40mm stand-offs we used). 4 long bolts then go through tops of alloy plates through this lower box-section to bolt the welded frame to the top of the drivetrain assembly.
Step 12: Seat Fitted.
Seat is on, mounted at front and a bolt hole each side at the rear.
The weight of the rider is not taken by the sissy bars at the rear, the frame underneath the seat takes all the weight, the sissy bars are for decoration mainly.
Battery is in a box at the rear which drops down into a welded enclosure for it that protects it.
Step 13: Headway LiFePO4 Kit
These are available on ebay from Hong Kong / China.
A 24V pack will consist of 8 cells. They assemble like Lego using the orange plastic interlocking end-sections that come with them. Metal strips bolt across the terminals so they are wired in series. There is a small wire from each junction that runs to a battery cell balancing unit or "BMS." There is often no wiring diagram for this in the kit so you end up surfing the web.
Step 14: Battery Pack Being Assembled.
This shows pack being assembled.
You can just use two 12V lead-acid batteries, say 7 Amp-h or more, to save money, or until you know your machine works before committing to a more expensive battery option.
Step 15: Wiring the Batteries
Here is wiring diagram for my particular BMS.
Some vendors may include a different BMS so you cannot assume this diagram automatically applies to your pack.
Step 16: Wiring of BMS
Here is what the end (front/back) of my particular BMS looks like where the wires have to be soldered to it.
Step 17: Packaging the Cells.
Here you see the cells assembled with metal strips joining them and the little red wires go to the BMS which balances the cells.
Step 18: View of BMS
The flat black thing is the BMS. Packaging it neatly in a plastic box with high density foam around it, that was used as packaging for the cells when they were shipped to me.
Step 19: All Protected
Trying to protect my batteries against all future impacts!
Step 20: Saddle On, Balance Controller Fitted.
I used a flat plastic box to hold the Arduino, the inertial measurement unit and the sabertooth motor power controller.
On the top of it you can see two 12V computer small cooling fans wired in series to the 24V feed to the Sabertooth so they blow cold air down over the cooling fins of the Sabertooth.
Under the seat you can see a blue box that holds 6 x AA batteries to power the Arduino. This one shown is a good quality one from a robot shop that has a lid that cannot easily be knocked off accidentally.
Step 21: Power Switches and Fans
Here you see the big rally car master power switch which is operated by a big red removable key. This connects the +ve from the 24V battery pack to the +ve power input terminal of the Sabertooth.
The small switch connects the +ve of the small AA battery box to the Arduino. This means you can test out the Arduino with the main power to motors off, and also ensures the Arduino always gets stable ripple free power no matter what punishment you are giving to the main 24V battery via the motors.
Step 22: Wiring Up the IMU, Arduino, Sabertooth and Switches.
Regarding the IMU we are using:
It is Code number SEN-10121 with Sparkfun. They describe it as: IMU Digital Combo Board - 6 Degrees of Freedom ITG3200/ADXL345 It has 3 gyros and 3 accelerometers inside. It communicates with the Arduino using the I2C protocol. Older IMU's produced a varying voltage output as they were moved, this one puts out the same information in a digital form.
Note for enthusiasts for this sort of thing: Pull-up resistors are not required as they are already present on the little red circuit board the IMU sensors are mounted on. If you don't know what this means it does not matter at all, it just refers to various on-line debates about hooking up this kind of sensor to an Arduino.
IMPORTANT NOTE 23/6/2015:
One person building this found that the IMU "locked up" and stopped talking to the Arduino. He solved it by making sure he used the SAME GND PIN on the Arduino for both the IMU GND wire and also the 0V wire from the Sabertooth. There are several GND pins on an Arduino Mega and they are connected to each other on the board, however he found it was more reliable if you use the same one for all your GND connections to the Arduino.
Data from the IMU is read by the Arduino Mega 1280. I use a Mega 1280 because they are a lot cheaper online than the 2560, and about the same price as an Uno. They have several hard wired serial outputs which means I can conveniently use one of these to send motor control data to the Sabertooth 2 x 25 Amp power controller, and another to send data to the serial-LCD screen.
The Deadman switch (connected to digital Pin 4) and steering buttons (actually brake levers from children's e-scooters, connected to digital pins 2 and 5) when pressed will connect their respective Mega pins to ground. The deadman is for safety, if you let go of it all power to the motors will stop after half a second.
Digital Pin 12 is connected to an LED. This LED stays lit on startup and goes out after a few seconds when the machine is ready to be brought "level" at which point it will start to balance itself.
The potentiometer in the diagram is actually on the left handlebar and is a Magura 5K potentiometer "twist-grip" throttle handle designed for electric vehicles. Turning it makes the machine lean forwards a little, and so it starts to roll forwards. Let it spring back and machine will lean backwards a little and slow down. It makes a very effective method of controlling speed (as well as simply leaning like you would on a Segway).
I have used brake levers (which contain a normally-off electric switch) from children's electric scooters as the switches that allow you to turn left or right. If you surf ebay you can get them very cheaply. They point downwards on my machine and are lifted by my thumbs.
The deadman switch has to be good quality. Dirty or intermittent contacts will not do! My favourite are microswitches that have a metal lever attached. I trim down the lever a little. These switches "snap" between open and closed states so you are less likely to get an intermittently closed contact as you would with some cheaper button switches.
Step 23: Wiring Up the 4 X 20 Serial LCD Display
Here is how you wire up this display.
Step 24: View of Orientation of Arduino Mega and Sabertooth
Sabertooth is mounted at rear end of the electronics box (left side in this photo).
Step 25: Wiring of the IMU
The Sparkfun IMU is mounted in this orientation. Front of machine is on left side of picture (opposite to previous picture).
The wires from my IMU are very fine and are soldered directly to their respective pins on the arduino on the underside of the arduino where the pins sockets are soldered in. This is because I cannot risk data loss or hangup of communication between the IMU and the Arduino due to dodgy push-fit connections, you would fall off instantly.
Step 26: CODE: Setting Up the FreeSix IMU Library on Your Computer
Download the folder "FreeSixIMU" from this website and put whole folder into your Arduino libraries folder so then the libraries listed above can be accessed by the Arduino.
Instructions on how to download this folder and put it into your Arduino libraries folder can be found here on this website (scroll down the page about half way):
This Arduino library was written by Fabio Varesano who sadly died not long ago. It reads the digital data from the IMU and processes the gyro and accelerometer information using a filter called a "Kalman filter" to work out what angle your machine is tilting at relative to the (always vertical downwards) pull of gravity.
My bit of the Arduino code (attached later) uses something called a PID controller which processes the IMU balance sensor information 100 times per second to adjust the speed of each motor many times per second to stop the machine falling over.
Step 27: FreeSix IMU Library Installed
Here is the FreeSix IMU library installed.
Jan 2015: I have attached a .pdf file showing some extra information on how the FreeSix library should be set up on your PC.
Step 28: Footrest
A piece of 40mm wide box section steel is bolted between the two alloy plates at their lowermost end (nearest the ground) sticking forwards. To this is welded a Y shaped arrangement of smaller box section carefully measured so you end up with a footrest each side that just clears the front of the tire on each side then sticks out sideways. Try to make it as neat as you can. The vertical tabs stop inner edges of your shoes rubbing the outer edges of the tyres.
Measure lots of times and cut/weld once !
Step 29: Another View of the Footrest Arrangement.
Step 30: Big Alloy Spacer.
A big high tensile smooth bolt goes through the wheel bearings from the outside and bolts the wheel to the alloy plate each side. There needs to be a spacer between inner wheel bearing and the alloy plate, to leave room for the tire to turn without rubbing the alloy plate, and also to leave room for the sprocket and chain (belt drive shown here) to function.
An alloy spacer of just the correct width so the chains/belt drives line up with the motors was made for each side on a hobby lathe. It needs to be narrow where it buts up to the inner bearing and nice and wide where it buts up to the alloy plate - this wide part spreads the loads and stops the axle bolt tilting upwards when your weight is placed on top of the machine.
Step 31: Big Alloy Spacer Fitted
Here the spacer is pushed into place and we are ready to bolt the whole lot to the side of one of the alloy plates. You can kind of see why it is the shape it is.
Step 32: Sabertooth Dipswitch Setup
The Sabertooth can receive commands from the attached Arduino in several formats. We have set up our Arduino to communicate with it via one of the Arduino Mega serial output pins.
The Sabertooth is configured to receive data in this format by setting a series of tiny switches using a toothpick or similar.
Set them as in this picture.
Step 33: Cooling Fans and LED Battery Voltage Indicator.
I bought 2 of the smallest 12V computer cooling fans I could find. I then wired them in series between the two central power contacts of the Sabertooth, where the power leads from the battery also are wired in.
When you turn on power to the sabertooth (via the big red key), the same power is applied to the fans and they start to spin and blow air down over the sabertooth cooling fins.
Also (optionally) wired up in exactly the same way is the LED voltage display module. I mounted this in front of the big red key and it shows the voltage across my big 24V battery when under load, giving an idea of battery life remaining.
Step 34: Detail of the Various Control Mountings.
Here you can see how I have mounted my controls.
Deadman: Right index finger.
Turn right: right "brake" lever operated by right thumb lifting it upwards.
Forwards / Slow down: Left twistgrip handle.
Turn Left: Lift left hand "brake" lever with left thumb.
This works OK.
Step 35: NOTE: Wiring Power Leads to Sabertooth
Power leads to Sabertooth have to be wired the right way around (the centre two big screw terminals).
If the +ve and -ve are reversed it will damage it permanently.
Also make sure there are no strands of wire shorting out between terminals either.
It is possible you may wire up one or both motors back to front. When you do initial testing, turn on arduino, then turn on Sabertooth, hold down deadman, wait until LED goes out, slowly bring machine level (still holding down deadman).
"Angle" will be displayed and it will count down or up to zero, then "balanced" will be displayed on the LCD display once it gets to zero, and machine will go "live."
If you initially do this with NO CHAINS fitted, then as you lean machine forwards, motor sprockets should both turn the same way, and they should turn in a way that - if chains were on - would make machine roll forwards.
Tipping machine backwards should make machine roll backwards.
If one or both motor wired up back to front, swap the + and - motor wires over on the relevant motor.
DO NOT swap over the centre two power in wires from the battery (just to make it clear, you will blow up the Sabertooth if you do that).
Step 36: Image of Finished Displays
Step 37: Finished Machine (1)
The black plastic panels behind the spokes are new-old-stock parts for BMX bikes in the 1980's. The idea is that if one is fitted each side of the wheel spokes, they make your wheel look "solid." They occasionally come up on ebay.
They look quite good mounted inboard of the spokes I think, so the spokes are visible but not the drive mechanism.
Step 38: Finished Machine (2)
Step 39: The CODE for Your Arduino Mega
Here is the code attached as a text file, not as an Arduino sketch as Instructables has trouble with sketches.
There are two versions, a basic one and a more advanced one.
Get the "Basic" version working first, then go on to the next one which has extra features in it such as direction stabiliser, handbrake function, overspeed "leanback" to stop you reaching 100% power then falling off the front (see below for explanation of all of these).
Open the text file, copy and paste it into a blank new Arduino sketch page, compile it (set for a Mega board) then save the sketch on your computer.
Don't forget to download the FreeSix IMU library before trying to get this to run on your Arduino Mega.
NOTE: 01/01/15I have also just attached a second "Advanced" version of the code where this feature is now enabled for you to try.
Extra features in this more advanced version of the code:
Direction stabiliser: There is a "direction stabiliser" section in the code steering section.
What does this mean? It means if your machine is drifting SLOWLY left or right - "yaw," it will continue to do this. If however, one wheel hits a stone for example and machine swings sharply i.e. a FAST turn around to one side, this software will detect that and try to resist the sudden unintentional turn. It means you are less likely to get spun around and fall off sideways if one wheel hits something. It worked well in the skateboard projects, was relatively simple and did not rely on "yaw" estimates, magnetic compass readings (magnetometer) or anything like that.
When you activate one of the steering levers, this feature is temporarily disabled of course so it still steers when you want it to! When you depress a steering lever, the machine turns. The rate of turn slowly builds up over a second or two, so the longer you hold the lever the faster it will start to turn. With practise this allows you to do anything from very gentle turns blipping the turn lever, to fast pirouettes on the spot if holding the lever down (see video on opening page). The angular rate of turning is measured by a gyro and set to a maximum in the code so it does not get faster and faster indefinitely. In future versions of this code I may make it speed sensitive, i.e. you turn more slowly when going fast so you do not suddenly spin off sideways.
Handbrake function:Also if you pull both steering levers in this version, the machine will lean back 5 degrees and slow down. Therefore this works as kind of handbrake.
Overspeed correction (leanback): It also will do this if the power to the motors exceeds 70%. This stops machine going too fast and you falling off the front. Self-balancers must never be allowed to reach 100% power else there is nothing in reserve to accelerate the chassis beneath you so you can then slow down. At 100% power it would slowly start to fall over forwards (but while going at max speed so expect it to hurt). By automatically leaning back (to slow down) at 70% power, it should persuade you to slow down as you can feel it trying to resist your urge to go faster.