Hacker's smart electric bicycle controller

Create an Atmega based BLDC controller made for electric bicycles, add bluetooth, an Android mobile app and a cloud service

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

* 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...

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


  • 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


    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.


    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.


    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:


    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.

  • The very Basics - BLDC control

    marcus06/07/2017 at 22:20 0 comments

    The most simple form of an electric motor is a brushed DC motor where two brushes are used for power transmission and commutation. The disadvantage is the fact that the brushes burn down and need to be replaced regularly.

    In a BLDC = brushless DC motor the commutation is done electronically and the motors most often have three phases which sit at an angle of 120°.

    Thus a BLDC controller needs correspondingly three half bridges with two MOSFETs each. The MOSFETs are driven by a PWM to control speed an torque of the motor.

    The phases are commenly named U, V and W. The MOSFETs which switch the plus side are the high side MOSFETs, In order to run current through the motor one or two high sides and one low side MOSFET are switched on.

    The challenge of a BLDC controller project is the fast switching of the MOSFETs to avoid switching losses. You'll find plenty of information on Wikipedia and also here on hackaday.

View all 7 project logs

Enjoy this project?



Tindie wrote 7 days ago 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