DIY E-Bike

by crazykiwi in Outside > Bikes

4823 Views, 44 Favorites, 0 Comments

DIY E-Bike

IMG_20210920_185131.jpg
IMG_20210217_175318.jpg
IMG_20200730_122917.jpg

Today I would like to share how I built an electric bike. I use it every day to go to the university. In total, it costed half the price of the cheapest commercial electric bikes we can found in my country and I have all the options I wanted for my bike. This is the most complex project I’ve ever made, it took me more than one year to complete it and I learned a lot of things in mechanics, electronics, soldering, mathematics and programming by doing this project.

This project aims to construct an ebike. It must be powerful, endurant and legal. I wanted to be able to unlock the bike with an RFID card and to charge me ebike with the LiPo charger I already own. I also wanted to control the motor with the pedals as well as with a button on the handlebar. On the top of that, I had quite a low budget for an e-bike : 600$. I do not only reused some components from old electronics to keep the price low, but I also built my battery and control board.

Supplies

  • Bike
  • Motor
  • ESC (Electronic Speed Controller)
  • Li-ion batteries
  • Arduino Nano
  • Relay
  • RFID reader
  • 12V LEDs
  • Nickel strips and copper wires
  • Step down converters
  • Pedal sensor
  • Resistors, capacitors, diodes, transistors, buzzer (see step 4)


Arduino code : https://pastebin.com/vEwyMhg1

Mechanics

IMG_20210920_185342.jpg
IMG_20210920_185426.jpg

First of all you need to find a bike. After several weeks I found a bike adapted to my size with disc brakes (I absolutely wanted to have disk brakes, as the average speed will be quite high and the bike will be heavy). After some mechanical adjustments the bike was functional and ready for this project. (I forgot to take a picture of the bike before putting the motor, sorry...)

I decided to buy a motor that was integrated to the wheel, as it was easy to install and not too expensive. I installed the motor on the bike, disassembled the pedals to fit a pedal sensor in it’s place and cat four pieces of aluminum to reinforce the back fork (the force applied by the motor could bend the fork). We can see those pieces on the first photo (they are covered with carbon tape because it's nicer).

Placing the pedal sensor can be a bit difficult, it took me a long time. I won't go into details here because a lot of videos on YouTube explain how to install this sensor much better than me. We can see the installed sensor on the second photo.

Deciding Where to Put the Electronics

IMG_20210920_185907.jpg
IMG_20200721_183935.jpg
IMG_20200727_195829.jpg

I wanted all electronics to be in the same plastic box as the battery. I bought an empty battery case online and started thinking how everything will fit inside. The battery will be composed of 18560 lithium-ion cells, so I can choose how I will arrange them in the housing (the connections will be explained in step 3 and 5). I also needed to find the place for the ESC (the brushless motor controller) and the control board (see step 4).

Connections

IMG_20210920_185948.jpg
IMG_20200902_193243.jpg

The battery case I bought online only has 5 connectors. That was a problem, since I needed to connect more components :

  • The motor (3 wires)
  • The hall effect sensors (3 wires)
  • A 5V power line (2 wires)
  • The lamps (2 wires)
  • The throttle button (1 wire)
  • The pedal sensor (1 wire)
  • The battery charging connectors (a lot of wires)

I decided to keep the five existing connectors of the case for the motor and the 5V power line. All others wires are on a single 7-wires connector (the white connector on the first photo). The others connectors are used to charge the battery, as we will see in the fifth step.

Here is a document with the electronic circuits of the e-bike :

Downloads

The Main Circuit

IMG_20200730_122827.jpg
IMG_20200730_122917.jpg
Screenshot from 2021-09-21 03-40-02.png
IMG_20200730_122930.jpg

The main circuit board was the most complicated thing to do in this build. The circuit must be able to lock and unlock the bike, control the throttle output from the motor, control the speed of the bike (to be legal on the road), power the lights, prevent an over-discharge of the battery and turn off the bike at the end of a ride.

The main component of this circuit is an Arduino Nano. Most of the components here come from old electronic projects or old electrical devices. I even used a triac from an old kitchen robot as I didn’t had a mosfet laying around to control the lights.


Here is a more detailed explanation of how the circuit works :

(see the PDF of step 3 for the exact layout of the circuit)

(click on the first picture to see to which area of the electronic circuit the numbers below refer)

  1. Power input : There are two power inputs. To start the bike, the user must press the power button which powers the card through the first input. The Arduino waits for the user to present the RFID card before activating the main relay (see point 6) which powers the card through the second input. The user can then release the button. The card is only powered by the second input during the ride. The diodes prevent electrical current from flowing back into the unpowered input of the circuit. The resistors form a voltage divider bridge which allows the Arduino to read the supply voltage (this allows the Arduino to cut the power if the voltage is too low).
  2. This part contains two step-down converters. The input voltage (between 30 and 42V) is first lowered to 12V by the first module. This voltage is used to power the lamps of the bike. The second module lowers the 12V to 5V, which is the operating voltage of the rest of the circuit.
  3. We find here a buzzer, a capacitor and a triac. The buzzer makes a noise when unlocking the bike and makes an alarm when the voltage is too low. The capacitor smooths the 5V voltage at the output of the step-down converter. The triac controls the power supply (and thus the lighting) of the lamps (it would have been better to use a mosfet here but I did not have one at hand)
  4. The Arduino Nano takes a lot of space in this part of the circuit, but there are also some connectors, for example for the RFID reader, for the relay and for the gas button. The relay is controlled with a transistor because the Arduino can't deliver enough current to activate it.
  5. The last part of the circuit contains many resistors, forming an R-2R circuit. This is the throttle output, which comes out of the Arduino in binary on four digital outputs and is transformed into an analog signal by these resistors. This analog signal passes through an operational amplifier to avoid a voltage drop. This signal can then directly be interpreted by the ESC (Electronic Speed Controller).

The Battery

IMG_20200906_182153.jpg
IMG_20201126_215211.jpg
IMG_20210920_190546.jpg
IMG_20210920_190142.jpg
IMG_20210920_190229.jpg
IMG_20210920_191847.jpg

Caution: creating your own battery can be dangerous if you don't know what you're doing. Only reproduce if you are sure of what you are doing!

I built my own battery for a few reasons: I wanted it to be in the same box as the rest of the electronics (so it had to have a particular shape), I didn't want it to be too expensive, I wanted to be able to charge it with my LiPo charger, and (most importantly) I wanted to learn how to create my own battery.

This is a 36V (10S) lithium battery with a capacity of about 10Ah. I used 18650 cells from Sanyo. This configuration allows me to have about 40 km of autonomy (which is not bad knowing that the place where I live is not flat)

My battery is composed of 30 Li-ion cells (18650) connected in series and in parallel (according to a 10S3P scheme). In reality, they are rather two 5S3P batteries that can be put in series thanks to a small connector (see picture). This configuration allows to have a 10S battery during the discharge but two 5S batteries during the charge. The LiPo charger I already had does not allow to charge batteries over 6S but I can still use it with the "two 5S batteries" configuration: mission accomplished.

I didn't use a BMS (Battery Managment System) in this project, since it is directly integrated in the charger. So it's my LiPo charger that is in charge of balancing the cells and charging them properly. For the discharge, the Arduino is in charge of cutting the current if the voltage is too low (if the battery is too discharged) and a fuse allows to cut the circuit in case of short-circuit or too high current. So I didn't use a BMS, but all safety functions are still handeled by other components.

All cells were connected with a spot welder and nickel strips, in groups of three in parallel, and then these groups were connected in series. I then soldered the balance and discharge wires to the nickel strips. I finally insulated the contacts with insulating tape (I know this is not the best way to proceed).

The two yellow connectors (XT60) at the back allow direct access to both parts of the battery for charging. We also find the two balancing connectors at the back, they are necessary for the balancing of the cells during the charge.

I designed and 3D printed a cover to protect the connectors from the rain.

The Lights

IMG_20210920_185239.jpg
IMG_20210817_164751.jpg
IMG_20210920_185315.jpg

I wanted the bike lights to be connected directly to the bike battery, so they would automatically turn on and I wouldn't need to charge anything other than the bike battery.

Lights are mandatory on electric bikes in the country where I live. It's also a very important safety feature, so I put some on my bike.

I used old LED strips (I gave them a second life, they were on my bookcase :) ) that I welded together and glued with epoxy on a plastic plate. Since they were RGB LEDs, I was able to connect the wires so that I had a white light on the front and a red light on the back. These lights are connected to the battery with electrical cables (which are also salvage), remember the 12V lamp connectors on the circuit in step 4?

But since everything never goes as planned, the lights started to come off their support. So I designed and 3D printed new supports for the LED strips. They perfectly fit the shape of the bike tubes and they have a plexiglass window to protect the LEDs from rain and dust.

Debugging

IMG_20200701_155320.jpg
IMG_20200722_220301.jpg

I could have called this section programming, but we always spend more time debugging than programming.

In my case, the debugging took about 6 months before I realized that the problem, which was also completely random, was not in my code but in the PCB: a copper chip was connecting two tracks that should not be connected.

Anyway, the code for the Arduino Nano of my e-bike is now working (finally!) and it is available here under free license. I won't explain it in detail, it's not very long and I tried to put enough comments explaining how it works.

It allows the Arduino to lock and unlock the bike with an RFID card, control the battery status, control the throttle input and calculate the signal to send to the motor controller. It also controls the bike lights and the buzzer.

Enjoy the Ride !

IMG_20210920_185220.jpg

After several months of work, my electric bike is finally fully functional! I use it every day to go to the university and it works pretty well.