Introduction: DC Motor Controller for Electric Bicycle

Picture of 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

Picture of 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

Picture of Schematic Drawings

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

Step 3: Digital Section

Picture of 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)

Picture of 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

Picture of 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

Picture of 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

Picture of 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 ..


mahio4u (author)2017-11-21

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?


scd (author)mahio4u2017-11-21

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,

grecchia (author)2016-09-06

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.


MattiV (author)2016-06-23

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.

varun1234 (author)2016-03-21

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

scd (author)varun12342016-03-22

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.

pavan60 (author)2016-03-08

thank u sir

pavan60 (author)2016-03-08

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

nob143 (author)2016-02-20

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.

MageshW1 (author)2015-11-12

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 :)

Fluidenergy (author)MageshW12016-01-30

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

scd (author)MageshW12015-11-13

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

MageshW1 (author)scd2015-11-14

Thank you sir :)

Fluidenergy (author)2016-01-30

Ingenius. This help will go a long way towards my developement of fluidenergy technologies. Saved me quite a bit of time back in the classroom labs. Combined with my own chipset the batteries are not needed lol. Sorry that I cannot elaborate further but fluidenergy is a trade secret.

AnkitS71 (author)2015-12-07

Can you explain Dc to Dc direct convertor

scd (author)AnkitS712015-12-07

As the name suggests, a DC-to-DC converter converts one DC voltage to another. There is a ton of more detailed info on converters online ..

davmie (author)2015-11-06

This project is awesome.

I can't see the schematics in good quality... i can't read the values. Can you post it in high resolution or in PDF format.

Thanks for all.

scd (author)davmie2015-11-06

Done :)

davmie (author)scd2015-11-06

Thank you very much.

MageshW1 (author)2015-10-31

Did you have pwm code

zutuyu (author)2015-10-17


Please can you share with us the software part :) ??

Thanks for all.

dallen20 (author)2015-10-06

Can we smooth out a square wave to reasonable sinewave, (like our grid mains supply) with passive inductor or capacitor? The square wave gives harmonics, tiny stutters and less efficiency.

scd (author)dallen202015-10-06

The FET gate needs to be turned on/off quickly, otherwise more time is spent in the FET's linear/resistive region and thus more heat will be generated.

dallen20 (author)scd2015-10-07

Yep, figures,... so can a capacitor-resistor be made to slow the FET's output to a less abrupt rising and falling voltage after the FET has switched in its efficient square wave fashion ?? I'm also thinking of audio passive RC filters that can be tuned to smooth out a square wave. I need to buy a scope and experiment ;-)

scd (author)dallen202015-10-07

Most motor controller designs have some parallel capacitance on the output to the motor (my controller has 3x 470uF caps), and the motor itself is a resistive and inductive (but primarily inductive) load, so there is some filtering happening. I would not recommend adding any series resistance, but you might experiment with adding (or subtracting) parallel capacitance and measure the effect on the motor voltage waveforms.

JohnnyD9 (author)2015-09-15 we really need a controller for a hub motor ...can we just hook a battery to it
and a switch to press on when we need the extra boost when we are tired of pedaling?

scd (author)JohnnyD92015-09-15

As you suggest, for a DC motor it would be possible to just implement a "boost" switch for cruising. You would need a very robust switch because of the high currents involved, but this would be dangerous since high current would be flowing through the switch. A relay would be safer since it offers some isolation and a solid state relay would be more reliable than a mechanical relay, but once you've done all that then you are very close to just implementing a controller ;)

yosoufe (author)2015-09-10


in one model of arduino (arduino Due) it has 2 real analogue output. I am thinking of using these analogue outputs instead of PWM. Do you know any driver circuits working with analogue signals instead of PWM? Because sometimes the noise of a motor controlled by an analogue signal is less than when it is controlled by PWM.

FreestyleR54 (author)2015-05-25

Why the MOSFETs need to be electrically isolated from the heatsink, in the schematic the Drain pins are connected together anyway..

Rondol (author)FreestyleR542015-08-07

To get better heat transfer

scd (author)FreestyleR542015-05-25

It is safer. Bicycles can vibrate and shake and it may be possible (for example) for the case to accidentally contacts the heat sink.

iwogan (author)2015-01-13

Will this controller work if use 36volts instead of 48?

scd (author)iwogan2015-01-13

This controller will work at either 36V or 48V since it does not do any low-voltage checks on the battery. I just manually check the battery before and after every ride and I my commute is short, so I never over-discharged the battery. However, adding a low-voltage check to the controller would be a good (and recommended) enhancement that would help protect the battery from over-discharging.

xmas (author)2014-07-29

I am totally blank on electric motor controller designs and i am looking for a multi-motor controller for my DIY electric bike & scooter. I was told I can use a stock controller with proper voltage and wattage (especially, wattage) to control two brushed motors for either bike or scooter. My goal is to use two low wattage hub motors (front and rear; kinda like all-wheel-drive) to drive an electric bike or scooter. your article gives me a close look into the construction of controller. thank you!!

khakhi (author)2014-07-02

is it single phase dc motor? can you send me its link.

GalFisk (author)khakhi2014-07-24

It is a single phase brushed DC motor. Brushless motors are more reliable in general, but demand a more complex controller.

scd (author)khakhi2014-07-02

It is a Crystalyte Sparrow.

ajvarath (author)2014-05-18

Good work...

I would also like to design a speed controller for 48 V/1000 W BLDC motor on a bicycle. I wanted to integrate Cruise control, few cut off functions, and be able to externally display velocity,voltage,rpm,etc. Would a PWM circuit works fine or should i use an Ardrino instead? I am an Electrical Engineering Tech student, but had done very basic microcontroller programming . How could i proceed?

scd (author)ajvarath2014-05-18

I used the free C compiler that comes with the Atmel AVR Studio software. I have not used Arduino, but I have heard that many functions are easier to implement because they have Arduino library support. You could do all the features that you listed using a simple 8-bit Atmel ATmega8, but you may also want to look at the newer 32-bit Arm-based microcontrollers which really don't cost much more than the old 8-bit controllers and they have more capabilities. I'm sure you will have lots of fun exploring. All the best !!


telesforo58 (author)2013-07-18

excellent for a greener world

rchan10 (author)2013-06-12

Hi, can you mind teach me how to choose a suitable motor to drive an e-bike. The weight that the motor can support is 100kg. So, how I am going to choose a motor that can support 100kg of weight?

scd (author)rchan102013-06-12

I weigh about 100kg and I use a non-geared hub motor that is rated at 750W. I still need to pedal on hills, but overall I find 750W is adequate. I suppose the answer depends on a) how much you want to pedal and b) how flat or hilly is the terrain in your area.

Nithin_T (author)2013-03-17

I was working on E-bike project using a 0.5HP (360W), 48V brushed motor (PMDC), so the current here will be around 8A or 16A while starting, with this circuit, will I be able to achieve speed control without burning the motor? If no, what will be the changes, especially in the motor driver part, which IC should I use.

scd (author)Nithin_T2013-03-18

To protect the motor from over-current, the controller needs to have a current limiter. I had planned to include this in the firmware, but never got around to it. The current limiter firmware would need to periodically read the shunt voltage and calculate the average current, and it this exceeds the maximum allowed current then the PWM would need to be shut down.

myshanks (author)2012-02-07

I am looking oout for a complete design and source code to controll a BLDC 250W motor for an e cycle project, battery could be either Lead Acid or Li-Ion of 24V with trottle control and Break cut off. Can any one help me. I am ready to pay professional charges for this project. My mail id is myshanks(at)

koylum (author)2012-01-07

Which kind battery did you used. Ordinary lead acid battery or NMH or another type battery. And also I will ask the Power of the battery howmany Amper-Hour? And you said 10 miles trip every day is your way stright? You made agood job thanks for sharing this project

scd (author)koylum2012-01-07

I have had a few e-bikes which have used either "deep-cycle" lead-acid batteries or LiFePO4 Lithium Ion batteries. The deep-cycle lead-acid batteries are OK, but they are heavy and they don't take as many charging cycles as LiFePO4 Lithium Ion. I have found that a 10AH battery is adequate for my10 mile commute which is mostly-flat with a few small hills. I weigh about 200 lbs (about 90.5 kgs). I peddle while I ride, but I think the motor does more work than I do :)

wobbler (author)2011-11-26

Nice to see a design for this. How much current does the board itself take?

scd (author)wobbler2011-11-26

The prototype board is hand wired using 12AWG wire for the power sections so it should be able to handle 50 Amps or so. A printed circuit version would require using heavy (3oz) copper clad circuit board material and/or beefing up the traces by soldering wire in parallel with the high-current traces.

For handling really high currents in a DC motor controller, you should check out this instructable by Paul Holmes:

wobbler (author)scd2011-11-28

Sorry, I phrased my question badly. What I was asking about was the actual current used by the controller board electronics to run, not the current it is capable of controlling. Thanks.

About This Instructable




More by scd:A Simple LED Flashlight Hack (3xAAA to Lithium Battery)USB-Rechargeable Battery Pack for Bicycle Lighting Recycling a Laptop Battery Pack for Bicycle Lighting
Add instructable to: