Close
0%
0%

Smart BLDC controller for eBikes with BLE

A smart, hackable BLDC controller for electric bicycles with bluetooth, Android app and a web service using an Atmega328

Similar projects worth following
BLDC controllers are quite interesting pieces of hardware and quite obviously the future is electric. Now not every hacker can afford a Tesla but a bicycle is very affordable and electric bicycles are a lot of fun.

BLDC controllers for bicycles are pretty cheap and the low cost versions start at roughly 35€. However, the second time when a controller ceased operation while I was in the middle of nowhere, I decided it was time to dig into the inner workings of these little gadgets and create my own.

The project consists of:
* an open hardware BLDC controller based on an Atmega 328
* which can power up to 1000W
* has bluetooth
* and connectors for hall sensors, brakes, pedal assist and throttle

Plus
* an Android app with hacker diagnostics
* a cloud service to share the data

Last not least ebikes are environment friendly and good for your health.

Key specs of the controller:

  • 250W-1000W power output
  • 36V/48V operation
  • Texas Instruments switching DC/DC converter / buck regulator
  • output for light
  • bluetooth configuration
  • connectors for throttle, pedal sensor, speed sensor and brake interrupt
  • regenerative braking
  • switchable power assist levels

Specs for the Android App

  • settings for max speed, wheel diameter, motor type etc
  • display speed, amps, battery voltage, power consumption
  • diagnostics - check hall sensors, brake sensor etc.
  • gps track logging with electrical data
  • easy upload of trip data to website

Website for viewing / sharing trips. An example trip with electrical data is here.

Specs for yourself and the environement

  • bicycle usage improves health
  • the environment is happy: a small car uses 5l fuel per 100km (=56 miles per gallon). A liter of fuel contains about 10KWh of energy. An electric bicycle uses about 0.5KWh per 100km. Thus about an espresso cup of fuel or 5600 miles per gallon.

EBikes are fun, good for your health and good for the environment! You should join the revolution...

open-bldc-bytefactory.eu.pdf

Adobe Portable Document Format - 144.66 kB - 06/14/2017 at 13:38

Preview

  • A handful of prototypes

    marcus09/11/2017 at 08:39 0 comments

    Making prototypes

    So far I have made a handful of prototypes for friends & family:

    Doing them by hand is quite a lengthy process. The general workflow is

    • applying solder paste to the PCB and placing the SMD components
    • reflow soldering in oven
    • first power up test slowly going from 0V-60V while checking that there are no shorts and all power converters are working correctly
    • flashing the firmware and bootloader
    • configuring the bluetooth LE
    • soldering the THT components 
    • cutting the aluminium heat sink, drilling 6 holes and cutting the M3 threads
    • applying the kapton tape and mounting the MOSFETs
    • drilling a hole in the panel for the grommet
    • mounting the whole board on a bike and doing a test ride

    All in all it takes me well over three hours to make one controller by hand.

    Currently I am looking into producing a batch with seeedstudio. The goal is to achieve a very competitive price tag of ~90$. This is about half the cost of what you currently have to pay for a cycle analyst and a controller while being a lot more powerful and lot less cabes.

    Stay tuned for more updates....

  • So how far can you go? The 240km challenge.

    marcus09/10/2017 at 22:48 0 comments

    The question

    The most asked question is always: "How far can you go with the battery?".
    And the answer is: "It depends!".


    The challenge

    The highest point that the Tour de France has ever passed is the Col de la Bonette at 2802 m (9192 ft). 

    The distance from Nice/France is 120 km thus back and forth is 240 km (150 miles). The challenge is to go up and back in one day with only one battery pack.

    The tour

    The start is in the early morning hours at the famous Promenade des Anglais in Nice.


    Under clear blue skies it goes along the Var river towards the mountains. In the morning there is always a bit of head wind due to typical offshore winds close to the sea.

    It is a very interesting landscape along the route which changes multiple times. A section in the middle is covered with red limestone.

    89 km after the start the real ascent begins.

    The peak in the background is the Col de la Bonette. Still 14km to go and 1000m of altitude to gain. It looked damn far away - and it was!

    Last stop to refill the water supply


    The difficult part starts roughly at 2500m - the thin air begins to effect the legs, every meter forward becomes a major effort. There is 40% less oxygen available than on sea level taking away your forces...


    In the picture below is the "Camps des fourches", an old military village - and a veeery welcome stop to take some pictures.

    And finally the summit - mission accomplished! 

    Well almost, but the way back is all downhill ;)


    Let's do some calculations

    The battery on my bike is a medium sized battery with 48V and 11.6Ah giving roughly 550Wh of energy. Let's assume an average efficiency of the motor of 70% that gives us 385Wh of mechanical energy.

    Let's assume the average speed is 24km/h (15mph) then we would need 10 hours for the trip.

    The calculator on kreuzotter.de says we need 112W for 24km/h in the flat, thus in 10 hours we need 1.12 KWh for covering the distance.

    For getting up to the top we need E = mgh -> 100kg * 9.81 * 2800m = 2746800Ws = 763Wh. Together this is a need of ~1.9KWh of energy, therefore the battery has supplied about 20% of the energy.

    Conclusion: obviously eBikes keep you fit!

    The maps

    Ascent

    http://cyclehikemap.eu/mymaps/view.php?id=73
    http://cyclehikemap.eu/mymaps/view.php?id=72
    http://cyclehikemap.eu/mymaps/view.php?id=71

    Retour

    http://cyclehikemap.eu/mymaps/view.php?id=70

    Food

    5 bananas
    2 baguettes with mountain cheese, ham, tomatoes and olive oil
    plenty of water

    Fun

    Priceless!

  • Unobtainium - findchips.com

    marcus07/24/2017 at 13:59 5 comments

    I have been a bit slow on updating the logs. Unfortunately there is a reason out of my control: the ATMEGA328PB has become unobtainium und thus making another prototype has become impossible.

    All this despite the fantastic findchips.com. Findchips is agreat service for managing your BOMs and finding the right places to source them.

    Nevertheless, they are nowhere to find anymore, not even on obscure websites and much less so official distributors.

    If anybody has a good channel to Microchips - who are also sponsors of the hackaday prize - maybe you can ask them to look in some drawer for some left over ICs.... I'd be more than grateful to get a handful of them!

    Meanwhile I have been polishing the enclosure with some laser cut panels. Below is a picture of the local fab lab SOFAB:

    And this is what the result looks like:

  • Doping test - PASS || KERS - PASS

    marcus07/24/2017 at 13:52 0 comments

    Doping Test

    Given enough Watts, all mountains become shallow. As I live on the french riviera, the obvious place to test an ebike ist the Col de la Madonne. It is pretty famous among road cyclists because it was the favourite test drive for Lance Armstrong.

    And guys, it is beautiful. Say about Lance what you want, be he knew the good places.

    This is what it looks like:


    All the way up you have a stunning view over the mediterranean and very little road traffic. The glamour of Monaco is at your feet, the blue of the sky melts into the blue of the sea...

    The picture below is taken at the top of the pass, a selfie taken the old fashioned way with a timer. I think I need to train this a bit more.


    KERS - Kinetic Energy Recovery System

    Below is the log of the trip from Nice to Italy via the Col de la Madonne. In true geek fashion the controller is logging all the data. Display in the chart is:

    • blue: speed in km/h
    • gray: altitude profile in m
    • red: ampere of the motor @ 48V
    • green: Kinetic Energy Recovery System = recharge the battery


    The green part is actually the cool part, the controller can does regenerative braking, in Formula 1 better known as KERS.

    Thus doing the long descent is the ultimate stress test for the controller. PASS!

  • eBike basics

    marcus06/12/2017 at 09:18 0 comments

    There are plenty of instructables on youtube videos out there about how to convert a bicycle into an eBike. I wont repeat this here but just cover the basics.

    What you need

    • motor (($50-$500)
    • battery (($100-$1000)
    • controller ($40-$200)
    • throttle, pedal sensor, speed sensor, brake lever with sensor

    Motor

    The easiest conversion is done with a hub motor. They come in two varieties: as direct drive motor which is gearless and as geared motors. Here is a picture of a geared hub motor:

    You can use a 36V motor also on 48V and even higher. It is not the volts that destroy a motor but the amps. Technically a motor is nothing but a copper wire. When too many amps are pushed through for too long then the insulation of the wires will melt causing short circuits and subsequently havoc. Also the magnets will loose their force once being heated over the curie temperature.

    Battery

    There are plenty out there and the more capacity you want the more expensive it will be. To calculate how much battery you need there is a calculator here. As a rule of thumb 100W of assistance will give you already a nice boost. Thus with a battery of 500Wh you can have five hours of 100W of assist. That's good for cruising on the flat at 25km/h or 16mph. However when going uphill fast you may need 1000W and your battery will last only 30 minutes.

    In general if you continue to use the bicycle as such and use the motor only as assist then a small battery can bring you pretty far. If you want to use the bicycle as an electric motorcycle then you will need many more times of battery.

    Controller

    The controller must fit the battery voltage. A battery voltage too high will destroy it. A battery voltage too low and the controller will cut off believing the battery is empty.

  • Current project status

    marcus06/12/2017 at 08:39 1 comment

    Controller hardware

    After several revision the hardware is working really well and has been tested for several thousand kilometers now. A mini series of five pieces has been produced to check the DFM.

    Controller firmware

    The controller firmware is mostly finished but still has some hardwired lines in it. A few minor things are still on the list for example soft fade out of assist when reaching the speed limit. Time needed: a few dozen hours.

    Android app

    Not yet on the market. Needs to be published. However there is a sister app for offline map usage with openstreetmap which has its first beta on the market. If you want to give it already a test run, you can find it here.

    A screenshot of the app:

    Website

    Only the very basics but upload and display of tracks from the app are working. See an example track.

  • PCB production in pictures

    marcus06/10/2017 at 22:31 0 comments

    Here are some pictures of the various steps of the PCB production. My -not exactly cheap- european fab house sends them per email which shortens nicely the waiting time until the PCBs finally arrive.

    The first step is drilling the holes for THT components and for the vias. It's more than 150 of them!

    The next step is applying the photo mask and etching. You can already see very well the structure of all the traces.

    And this is what the board looks like right after the etching:

    The final steps are then to apply the solder mask and the silk screen and to finish the pads with ENIG gold plating:

    That's it, almost ready. The final steps are cutting and shipping. Pictures of the assembly will follow...

  • Pin assignments microcontroller

    marcus06/10/2017 at 11:01 0 comments

    Assigning the pins is quite a puzzle. We have digital pins and analog pins, pins that need to do PWM and pins that need to do serial output. Other pins need to be connected to interrupts. Thus we need to juggle assignments until everything fits.

    The pin assignment on the controller looks like this:

    First consideration are the PWM pins for driving the half bridges. This could either be the OCxA or the OCxB pins. The OCxB pins allow for a more flexible configuration thus we'll use PD2, PD3 and PD5. Next we assign the hall sensor pins. These are digital and should be next to each other and more importantly they need to be on the same port to generate the same interrupt. PB0 to PB2 is the good choice. Next we assign the 3 shut down pins for the half bridges. For ease of programming they should be next to each other and on the same port. PB3 to PB5 are free and fit these conditions. Also fixed are the serial pins for the communication with the bluetooth chip. Thus PD0 and PD1 are used as RX and TX lines.

    Pins needing analog input are the BEMF pins. These are for voltage sensing on the phases and can be used for sensorless operation. Then obviously the throttle, the voltage and current sensing and motor temperature. Last not least we use an analog pin for a three button switch together with a resistor network.

    Further inputs are brake, speed and pedal sensors. They are all digital inputs with no specific requirements.

    This leaves us with two pins of which we'll use one for a blinkenlight LED and the other to switch a small MOSFET for the bike light or for a brake light.

  • Basic board layout

    marcus06/10/2017 at 09:35 0 comments

    After the decision for the microcontroller is done we need to make decisions for the basic board layout. This also includes the choice of housing for the MOSFETs. The basic choice here is whether to use SMD fets or THT fets. As we want to run up to 1000W through the board the choice of THT is more sensible and TO-220 is a good form factor with a large choice of products.

    Let's do a quick back-of-the-envelope calculation. We have 50Volt from the battery and we want 1000W output. Thus we have at least 20A going through the fets. However, the controller acts together with the inductance of the motor as a DC/DC converter and the amperage can thus be even higher unless being limited by the firmware.

    So we'll assume 50% margin which results in 30A. The on-resistance of a reasonable MOSFET is around 5mOhm. Thus we have 30A*30A*0.005Ohm = 4.5W. As a rule of thumb a TO-220 can dissipate roughly 1 Watt when not mounted on a heat sink. Thus at 1000W we need to properly mount them on the enclosure.

    Here is a picture of the general layout in a 3D rendering from KiCAD:

    The board measures 100x60mm. The board is properly designed into sections. The dark blue part is the power stage. The power stage contains the 6 MOSFETs, the 3 half bridge drivers with boot strap circuitry and the caps.

    The green part is the brain with the uC and various I/O connectors for throttle, hall sensors, brake, speed sensor, pedal sensor and ICSP.

    On the right side in red there are the power regulators. The top one converts the 50V from the battery to 12V for driving the fets. It has 0.6A output thus can produce up to 7.2W. The board itself needs about 1W so we have 5W left for LED lights on the bicycle. Below is the old classic 7805 linear regulator for powering the brain.

    Finally we have on the lower left the bluetooth section. This contains another voltage regulator for 3.3V and a logic level converter for the 5V TTL to 3.3V TTL.

    That's it, stay tuned for the next diary entry!

  • Design decisions - OMG Arduino

    marcus06/09/2017 at 19:31 0 comments

    Choice of microcontroller

    First and foremost the decision of the microcontroller had to be made. While there are dedicated chips available, I like to code embedded systems and thus the whole control should be done in firmware. The following GPIOs are needed:

    • 6 digital ports with hardware PWM for the 6 MOSFETs
    • 3 digital ports for hall sensors in the motor for position sensing
    • 3 analog ports for phase sensing for sensorless operation
    • 3 digital port for brake switch, pedal sensor and speed sensor
    • 3 analog ports for throttle, assist mode and thermal motor sensor
    • 2 digital ports for light switching
    • 2 analog ports for sensing battery voltage and current

    It so happens that this fits onto an Atmega328PB. The 328PB has the advantage of having 5 timers versus 3 timers on the 328P on the Arduino boards. This is a nice convenience as 3 timers can be used for the PWM generation, while still having two more timers left for general timing purposes.

    Why 8-bit and not 32-bit ARM core? The idea behind this choice is a bit hacker ethics - you can still fully understand what is happening under the hood of an 8-bit chip and the datasheet is only 400 pages. In order to program the 32 bit chips you wont easily do it without using boiler plate code produced automatically by Atmel Studio. So it is a minimalist approach. Or as Antoine de Saint-Exupery put it: “Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.”

    What else is needed?

    The input voltage needs to cover up to 13s lipo batteries. 13s means 13 cells in series which adds up to 54.6 Volt when fully charged. These battery packs are usually sold as 48V packs and are a common standard. The controller itself needs 10-12V for driving the MOSFETs and 5V for the microcontroller.

    Coming down from 55V to 12V is best done with a switching regulator. This gives also enough output power to connect a normal bicycle light. The second stage 12V to 5V is done with a linear regulator as the microcontroller and the bluetooth only need a few dozen mW of power.

    Power stage

    The MOSFETs gates cannot be powered directly from the uC ports for two reasons: the gates need at least 10V to fully switch on and you need to switch them on and off very fast to minimize switching losses. Very fast means in the order of 100ns. There are plenty of dedicated chips out there and I choose the International Rectifier IR2104 half bridge driver for this purpose. The chip offers shoot-through protection, i.e. high and low side MOSFET will never both be switched on at the same time. This is nice to have because "shoot through" means a battery short circuit and therefore the release of magic smoke with a loud bang.

    The chip also has a bootstrap circuitry thus N-channel MOSFETs can also be used for the high side.

    That's it, those are the main components of the BLDC controller.

    Next up: board layout overview, coming tomorrow.

View all 11 project logs

Enjoy this project?

Share

Discussions

TheNameOfTheGameX3 wrote 05/30/2024 at 01:01 point

Well... nice project but it would be nicer to be able to access the code...

  Are you sure? yes | no

techgalaxyindia wrote 05/16/2022 at 08:04 point

very helpful: can you please share firmware 

  Are you sure? yes | no

prince1890sharma wrote 06/05/2019 at 11:18 point

Hi, your project is superb, I am currently doing same project. Can you please let me know what is difference between Assist and PAS. Hoping for your reply.

  Are you sure? yes | no

kashif5783 wrote 02/14/2019 at 18:28 point

Thank you for this great information. Can you please design and fabricate one of these BLDC controllers for me? What will be the price of such a board ?

It would be very kind of you to share the design files and the arduino code. What will be the cost of that ?

Can we contact for further information on this?

  Are you sure? yes | no

orpheus345 wrote 01/14/2019 at 02:21 point

Thank you for sharing this wonderful project, if you dont mind... May I know the mosfet you used and the resistance value for driving the bldc motor? I am currently develop a controller for 48V 1000W ebike. I am about to try irf3808. Hope for more update for this project. Thank you.

  Are you sure? yes | no

dh.rijalusalam wrote 10/02/2018 at 17:44 point

may i have the avr / arduino program ?

  Are you sure? yes | no

Yvoz wrote 03/30/2018 at 22:38 point

Thank you for this wonderful project and for sharing.

Where is the Arduino code ?

  Are you sure? yes | no

EngineerAllen wrote 10/10/2017 at 07:03 point

atmega328 isnt fast enough for commutation?

  Are you sure? yes | no

shafqat571 wrote 09/29/2017 at 21:47 point

great project, I happy to buy one and participate in testing 

  Are you sure? yes | no

rafeh1 wrote 09/11/2017 at 23:58 point

what fets are you using? what is deff between using a VESC?

rafe

  Are you sure? yes | no

marcus wrote 09/12/2017 at 06:32 point

For the 1000W version I use various 60V 3-4mOhm Fets, for the 2000W version I use 1.3mOhm Fets. The need to be rugged and have a low gate charge in the area of 100nC.

Compared to the VESC mine is optimised for eBike use:

- lower cost 
- smaller firmware, more educational
- easier to fix/repair
- plugs for throttle, halls, pedal sensor, brake
- regenerative braking
- Bluetooth
- android app for setting max speed, wheel diameter etc
- website to upload your trips
- power output for normal bike light
- TO 220 MOSFETs - better to cool and easier to replace - more continuous power 
- atmega 328 easy to program

  Are you sure? yes | no

Ya Wonder wrote 09/11/2017 at 19:03 point

I am quite interested in buying a ready made one. if i am to turn my bike into a ebike i would really prefer to use a libre hardware, libre software product.
Hmm.. i see your buying parts from digkey and the alike. ive been following a project that has been quite educational for me. apparently i believe i remember these shops buy up old components and when you go to china you can’t necessary buy the same components. wheres by using common china components, products can be made a lot cheaper and the maker has a much easier time sourcing the components.

if of interest, that project was http://rhombus-tech.net/ the posts on the mailing list: http://lists.phcomp.co.uk/pipermail/arm-netbook/ and the updates from the crowdfunding, had some nice written up experiences i think: https://www.crowdsupply.com/eoma68/micro-desktop

  Are you sure? yes | no

marcus wrote 09/12/2017 at 06:46 point

You just got it reversed. In China you get old components and what worked last month doesn't work next month any more. Components are often a lot cheaper but also often counterfeited. I had a batch made last year by a company that does smart prototyping and I got fake LM2576HV. Instead of being capable to do 60V, they blew at 40V taking all other components on the board down with them. A waste of time to figure out what was going on and almost $1000 for the boards.

If you buy from digikey you get reliably top quality directly from the manufacturers - no grey market stuff.

  Are you sure? yes | no

Ya Wonder wrote 09/12/2017 at 11:06 point

yea for us buying online its all to easy to get crap. ive had a few crap boards ive bought when i went for the cheapest or unknown/uncommon design.

I was referring to my memory's (I dont fully trust my memory btw.) of lukes experiences, where he and a knowable person from china that knows and lives in the place. Went in person to china shops in china for sourcing components.

Heres the post i was thinking of: https://www.crowdsupply.com/eoma68/micro-desktop/updates/post-shenzhen-reflections

and heres another with more experiences:

https://www.crowdsupply.com/eoma68/micro-desktop/updates/2409

  Are you sure? yes | no

steffen.eyhorn.me wrote 09/11/2017 at 12:36 point

That is one beautiful project! Also, whenever you're going small-series, I'd love to buy one from you and help with the testing.

  Are you sure? yes | no

marcus wrote 09/11/2017 at 12:43 point

Deal! ;) i'll keep you updated!

  Are you sure? yes | no

steffen.eyhorn.me wrote 09/11/2017 at 14:14 point

Merci beaucoup!

  Are you sure? yes | no

ejonesss wrote 09/10/2017 at 14:19 point

does it have to be "ATMEGA328PB"  can it be "ATMEGA328P"  does the "B" make a difference?

there are a bunch of ATMEGA328P on ebay .

  Are you sure? yes | no

marcus wrote 09/10/2017 at 19:42 point

The 328P has two I/O ports less. But yes, I already changed the PCB to accommodate the 328P, I have to write a project update. However, I buy them directly from the major distributors as long as they are available there.

  Are you sure? yes | no

steffen.eyhorn.me wrote 09/11/2017 at 14:28 point

Interesting, they're also only "on order" at Mouser  (http://www.mouser.de/Search/Refine.aspx?Keyword=atmega328pb), which I mostly use. Seems like they'll be back soon, but still, weird delay.

I remember there was an article on Hackaday introducing the 328PB, got me excited and we almost used it for some project - I guess luckily we sticked to the 328P?

  Are you sure? yes | no

evandrorech wrote 09/10/2017 at 03:10 point

Congrats by the project! I'm in a project that will use a 1 kW brushless hub motor too, it is a flywheel battery and I want to acquire a motor used in ebike conversion. Do you know the speed (rpm) you can achieve with your motor with no load? It only depends of the controller? Thanks!

  Are you sure? yes | no

marcus wrote 09/10/2017 at 19:41 point

It only depends on the motor and the battery voltage. A motor has a kv constant which tells you how many rpm per volt it does. EBIke motor will often be around 330RPM at 36V. You can ask the manufacturer for a fast winding.

  Are you sure? yes | no

evandrorech wrote 09/11/2017 at 00:02 point

Thanks!

  Are you sure? yes | no

Tindie wrote 06/23/2017 at 00:31 point

Congratulations on being one of the Internet of Useful Things Hackaday Prize Finalists! We'd love to see more e-bike projects on Tindie. 

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates