DC Motor Controller for Electric Bicycle





Introduction: DC Motor Controller for Electric Bicycle

I designed this controller for my Crystalite Sparrow 48V electric bicycle hub motor.  The core function of a DC motor controller is to periodically read the throttle setting and adjust the current being supplied to the motor.  It does this with a technique called pulse-width modulation or PWM (more on this later).  Other functions of the controller include:  1) low-voltage cutoff .. monitor the battery voltage and shut down the motor if the battery voltage is too low .. this protects the battery from over-discharge.   2) over-temperature cutoff .. monitor the temperature of the FET power transistors and shut down the motor if they become too hot .. this protects the FET power transistors.   3) over-current cutoff .. reduce the current to the motor if too much current is being supplied .. this protects both the motor and the the FET power transistors.  4) brake cutoff .. shut down the motor when the brake is applied .. this is a safety feature .. if the user applies brake and throttle, the brakes win.

Note1: This is a relatively advanced instructable.  Don't attempt it if you don't have experience with power electronics.  The voltages and currents used in this project can be dangerous and appropriate safety precautions must be used.  This instructable outlines what I did to make this project, but it is not a substitute for proper safety training in power electronics.  Check with your local community college for availability of classes in your area.

Note2: In addition to the 48V battery voltage, this controller requires a 12V power supply.  If your battery pack consists of 12V cells, then you can just tap 12V from the pack.  This was not possible for my battery pack, so I used a separate DC-to-DC converter to supply the 12V power.  See my other instructable on constructing this DC-to-DC converter.

Note3: This controller is over-designed for this application.  The IRFP4468 FETs are rated for a maximum of 195 Amps (each) at 100V.  This application will typically use less than 10 Amps at 50V.  I have been commuting (10 mile round trip) almost every day for the past 2 months using this controller and it has been trouble free (knock-on-wood :)

Step 1: Parts List

Here is the parts list (with Digikey part numbers) for all the electronic parts.

You will also need:
a) a prototype circuit board (the one I used is from a local electronics surplus store)
b) wire.  I used 30AWG wire for the low current connections and 14, 12 and 10AWG wire for higher current connections.
c) 1/8" heat shrink tubing (about 2" in length)
d) two 6-32 x 1" screws
e) 4 x insulating pads for the FETs and power diodes (these can be salvaged from a broken PC power supply)
f) a heat sink for the power section.  (this can be salvaged from a broken PC power supply)
g) an enclosure.  (this can be salvaged from a broken PC power supply)

The following tools are required:
a) a programmer for the microcontroller.  I used an AVR ISP programmer (check EBay)
b) a soldering iron (and solder of course)

The following tools are recommended for debugging:
a) a digital multimetter (DMM) for checking connections, etc.
b) an oscilloscope is handy for checking the PWM waveform, etc.

Step 2: Schematic Drawings

Here are the schematic drawings. Sheet 1 is the digital section and sheet 2 is the power section.

Step 3: Digital Section

This photo shows the digital section (page 1 of the schematic) wired up and connected the the Atmel programmer.

Step 4: Pulse-Width Modulation (PWM)

This photo shows the PWM signal (pin 15 of the ATMega8 micro) used to turn on/off the power FETs. When the signal is high, voltage is applied to the motor.  This waveform is for about a 1/4 throttle setting.

Step 5: Power Section Construction Details

These photos show how the FETs and power diodes are attached to the heat sink.  They must be kept electrically isolated from the heat sink.  The screws are covered with 1/8" heat shrink tubing and the FET and power  The heat sink that I used is re-purposed from an old broken PC power supply.

Step 6: Assembly and Enclosure

These photos show the controller with digital PWM and power sections completed.  The monitors (e.g. battery voltage monitor) are not connected yet.

Step 7: Circuit Board Layout

I used a circuit board CAD program to create this layout.  I have not fabricated this circuit board.

Step 8: Software

The software is not currently available ..



    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    69 Discussions

    I am looking at modifying this circuit to run a 24V DC Motor with stall current of 125A. What is the purpose of power Diodes D1 & D2? Are D1 & D2 there to prevent EMF current spikes to the MOSFETs or something else? The specs say they can handle 30A . So do I needs to find diodes that can handle the stall current or something less? Thank you for your time.

    Sorry but I am not sure how the FETs and PowerDiodes are electrically isolated from the heat sink. I understand the heat shrinking the screws. Is there a heat conducting but electrical insulating film between the heat sink and the FETs and PowerDiodes?

    1 more answer


    Background information. For an aquarium. DC controller to run a 24 volt DC motor to run water pump. This motor is a DC 9-24 volt, powered off a 24 volt marine battery, if a power outage takes place, the pump would still run. And yes, I will have a battery charger charging the battery 24 X 7 X 365.

    What's needed. A controller that will be variable and not go below 9 volts and not above 24 volts. If the water flow is to high at 24 volts, the controller would be turned to reduce the motor speed, there by reducing pump flow. This pump would be running 24 X 7 X 365, with exception for powering down to change cartridge filter.

    This controller would not be powered from the 120 volt 60 hertz house power. This controller is powered by the DC 24 volt battery.

    Plese include safety circuits also. Overheat protection, over voltage protection, etc.

    Note this will not be a throttle type of speed control. The speed would be variable to the point of a stationary set speed according to water flow, and then continuous run at that speed. ??Would this be a potientiometer which is similar to a volume control for audio equipement??

    Could you design a circuit to function like this?

    Thanks, Ken

    1 reply

    A DC motor control circuit could meet your requirements. If you don't want to build your own, you could do a Google search for a 24V DC motor controller. You need to know how much current your 24V motor will require at full load in order to choose an adequate motor controller. Since your controller will be running 24x7x365, choose a controller that can handle that load without overheating. Safety features (such as thermal shutdown, etc.) are very important. If you are not comfortable choosing a controller by yourself, find someone (not me) with adequate technical knowledge to help you choose a controller.

    Can anyone help me with the code?

    Nice instructable. I have some questions.

    1. What was your switching frequency, and why did you choose that value?

    2. What was your PWM boundary? as in 0 to 100% or some where inbetween?

    3. Does your lower value pwm duty cycle (say 50% duty cycle) send half the voltage (ie 24v) to the motor?


    2 replies

    1. I think it was about 20Khz (high enough that you can't hear it) (higher frequencies waste power in switching)
    2. 0 to 100%
    3. In effect yes (due to capacitive filter effect).

    Best Regards,

    Thanks. How did you come up with the values for your capacitors? Was there a calculation? or you just chose available parts? How did you achieve the braking aspect? Did you stop the motor when you applied the brakes? Was there a stop switch..?

    Thanks for sharing and you have my admiration for the simplicity of the design.

    Just a question. You oversized the components just to be sure to fit into your engine power requirements but cutting the power unit in two and using only one power diode and one fet but how much power do you think an alternative board would be able to handle considering

    A. A good sw pwm implementation
    B. current monitoring and consequent protection
    C. Eventual spike current generated by the engine during start


    I'm quite interested in developing a control board for an ebike engine but I'd like to understand if it is worthy first.

    Thank you.



    2 years ago

    i just orden 250W 24 volt motor my e-bike project and i think how i make arduino code speed controller whit FET and how i made over current limited here ? and then how control gel battery (2 12V serial=24V out) how code at NOT

    over-discharged the battery ? how measure and protect battery. im not good write code to arduino.if somebody have working code and schematic i try made and test my project this. or have better use e-bike kit own controller ? but i think how safe battery not over discharge empty and think arduino whit i2c lcd can show battery volt,+speed+current+time+battery empty alarm,etc etc what must be.

    hello sir... i need the code for this... can u send it...???

    1 reply

    I have put the code here:


    Note: This code is incomplete and I have not worked on it or updated it in quite some time. Use at your own risk.

    thank u sir

    sir i need the code....if u have possible please send me the code


    2 years ago

    I'm planning to do an hybrid two wheeler as a part of my project.What all i should considered about this.Can u give a brief detail.

    Really this project is interesting for engineering students and it also intents them to do next level so millions of thanks to author :) (Y)
    And i'm also doing my e-bike with this instructables i got idea to design my controller with basic functionalities but now i stuck at one point the motor that im using was BLDC three phase with hall elements at stator.I dont know how to design a controller for this application.So pls someone(preferably author of this project) help me to ctrl my motor.Thanks in advance :)

    3 replies

    Very poor choice with a 3 phase motor. If the grounds short the bike can kill you.

    For a sensored BLDC motor controller, you will need to control (at least) 6 FETs (3 phases x 2 current directions). At any one time only 2 of the 6 FETs are active and of the 2 active FETs, one is on and the other is PWM modulated for speed control. I am not an expert on 3-phase motor controller, so I cannot offer much specific advice, but there are many sensored BLDC motor control application notes available that can help you (just try a google search).

    Thank you sir :)