Articles, Blog

Make your own Sensored ESC || Electric Bike Conversion (Part 1)

Make your own Sensored ESC ||  Electric Bike Conversion (Part 1)


Since warm seasons are slowly approaching, it was time for me to free my bicycle from dust and oil it’s chain And, as you can see its mechanical drive system still works without a problem. But for an electronics enthusiast like me, it is kind of boring… That is why I ordered an E – bike conversion kit for around 200 euros ($246.95 US), which is not a bad deal if you compare the price to commercial E – Bikes. But anyway, once I received the kit, I unpacked all the delivered goods and found the front wheel with integrated hub motor, a throttle, brakes, and electric speed controller, and a couple of complementary components So, I simply removed my old front wheel, as well as my front disc brake, and secured the new electric front wheel in place. The whole process barely took around 10 minutes. Next, I wanted to test the new wheel at home, and thus connected the three motor wires… Along with the motor sensor connector, and the throttle connector to the electric speed controller, according to how the manual describes it. Then, I connected the battery connector to my lab bench power supply, which was set to its maximum voltage of 30 volts and… By powering up the system, and turning the throttle control, the motor tried to start spinning, but never succeeded. The problem is that the 30 volts are, apparently, not high enough voltage for the electric speed controller. …which is something that bothered me quite a lot. So in this video we will create our own sensored electric speed controller, …which does work with low voltages and, thus allows me to test my new electric front wheel extensively. Let’s get started! [Intro + Music] This video is sponsored by JLCPCB. One fact about them: JLCPCB produces 200,000 square meters (656,000 feet) of single, double, or multiple layer PCBs monthly. Upload your Gerber files to order ten professional PCBs for only $2.00! To create a suitable sensored ESC, let’s firstly have a closer look at the hub motor. After removing its metal cover, we can see that it consists of a dozen of coils on the inside, that do not move when the wheel is rotating Simplified, the coil arrangement would look something like this: with the wires A, B, and C being leads through the outside. The rotating parts of the hub motor on the other hands, consist of neodymium magnets with alternating polarity… …which according to how current flows through the coil arrangement aligned in a certain way due to the magnetic forces. that means what we’re dealing here with is a so-called BLDC motor, aka a brushless direct current motor. I already talked about how you can make them rotate by creating your own ECE in a previous project so definitely have a look at that if you want to know more about the theory of those motors as as a reminder though We simply must connect each phase of the motor to either the supply voltage or ground in a very specific order Which repeats continuously it too creates the rotational movements But does that mean we could simply hook up an ordinary ESC to the bike wheel and powered like that? Well as you can see it does kind of work But definitely not optimal since such bike wheels are supposed to rotate much slower than traditional BLDC motors That is why it got those three Hall effect sensors attached to the motor By connecting their red wire to five volts and that black wire to ground We can hook the output of each of them up to the oscilloscope and see that whenever a magnet comes close to them They pull their outputs up to 5 volts This way we got 3-year phase shift to square waves that tell us where the rotor is located now we can use this information to determine when the next step should be initialized and Just like that we no longer need to back electromotive force of the floating face which was proportional to the rotation speeds and thus only possible at high speeds and with the motor control theory out of the way, let’s start creating our own censored ESC as As you can see I use P channel and N channel MOSFETs with an appropriate driver for each To connect the three motor phases either to the supply voltage or ground But since the p-channel MOSFETs turn on at zero volts and turn off at 5 volts Which is the exact opposite of the N-Channel MOSFET behavior I simply added a hex may trigger inverter to the control lines of the p-channel MOSFETs So that the programming for the Arduino will be easier later on The last mandatory component was a potentiometer to set the rotation speeds and three inputs for the Hall effect sensors and With those guidelines in mind I started creating a schematic for the project which in the end turned out to look something like this so I gathered all the required components and started soldering them to a piece of perfboard and afterwards to one another according to the schematic and if you’re interested in experimenting with your own sensor BLDC motor Then you can of course find the schematic, code, pictures and more information about this project as always in the video description after four hours of soldering the circuit was finally complete and after inserting the ICs all that was left to do was the programming Now while the codes which, I created looks pretty intimidating it is quite easy to understand if you are familiar with external interrupts pin change interrupts the free run mode of the ADC Timers and port manipulation, so have a closer look at my other videos and learn all about it if you’re interested Anyway, what the codes basically does is firstly waiting for state change of one of the Hall effect sensors? If one happens the Arduino determines, which step needs to be activated Then timer one says okay, let’s activate the corresponding MOSFETs of the step But after a certain amount of time which is determined by the potentiometer Timer one then says let’s connect all phases to one another and take a quick break before we power the phases once again This creates a PWM signal which basically lowers the average voltage and thus lowers the current Which lowers the magnetic forces and thus the rotation speed This process continues until there’s an another Hall effect sensor state change, which then activates the next step So in theory the code should work fine which means it was time to upload it connect the motor wires as well as the Hall effect sensor wires to the boards and Power it all up and as you can see the wheel starts rotating and the speeds can be adjusted by the potentiometer But as expected the wheel rotates rather slowly with a 15 volt supply voltage but it is still a lot of fun to play around with I hope you enjoyed watching this video and are looking forward to the next episode of the electric bike conversion project As always don’t forget to Like share and subscribe Stay creative, and I will see you next time

100 comments

wouldn't it make more sense making a controller that creats 3 sine waves with 120° phase shift instead of turning a pwm signal on and of?

GreatScott, your driver has one serious problem – if you only use inverters to switch between the FETs, there is no dead time. The transistors don't turn off instantaneously, so you are going to have very nasty current spikes (shoot-through) because for a short moment both transistors are on, causing a short circuit across the power rails. That's bad both because it will cause the FETs to get hot (or even blow them up), because you are generating a ton of EMI with it and also because it wastes energy, which is important if you want to run this from a battery on a bike.

That's why proper FET drivers for half bridges have an option to set dead time. Many microcontrollers designed for driving motors/bridges have an option to generate programmable dead time too. If you are using an Arduino (ATMega328 and similar), you will have to generate this dead time in software by inserting a delay between switching one FET off and the other from the pair on. You will pretty much never see a simple inverter used in this kind of application.

Why did my esc now broke? The resistor gets really hot and nothing worked but why did this happen any idea? ( i couldnt see and smell a short circut and the shunt was fine.

Hi great Scott! This was a great video, you are a genius! There is one thing I really want to point out to you for your own good. I have made many ebikes, I purchased a hub motor for the front just like you. When I put it on my bike the hub motor the second I put power to it on the ground the mounting taps broke on the forks. I don’t know what it is but the magnesium alloy is very brittle to the motors torque. I really hope you see this because I have broken 3 forks like that and had to get steel ones. I think it’s a huge safety hazard and don’t want it to happen to you!!!

I might be missing something !!
Why aren't you just change the battery into a stronger one . .that will solve the problem right?

Hi Scott, another thing I would like to see. Could you make some deep approach showing the relationship between number of poles of stator and rotor. Where to place the magnets and when to commute phases. I don't see, for example, a motor with same number of poles in stator and rotor. Thanks a million

Yeah, I wouldn't do that if efficiency is something you care about (6:45)… If you wanna use a PWM-ish approach to control the speed, by only applying voltage for a limited amount of time, be sure to leave the phases floating while not applying voltage (except during regenerative braking of course).

i am wanting to look into some electronics engineering and i was wondering if you or anyone else could recommend a good place to start with it. i thought about find schematics online and learning how they work then build them or if buying a kit would be a better route?

Hi great Scott, is it possible to increase the rotation speed of the engine? I have an electric bike and I would like to make it go faster.

you should set up a generator, so when you move on the bike the wheel rotates the generator and powers the batterie

Lately, I am struggling to make prototypes on a piece of pcb. I really love your technique of making solder traces, but I really don't succeed in making traces? How do you do them?

I dont understand a heck about what you are talking about, but i like your videos, what is this called (the carrer)?

Hey, i have a project i'd like your help in, I need an audio amplifier with 100w on one mono channel, but i need to be able to mount the volume knob through an enclosure. I have not been able to find an off the shelf amp that lets me do these things, is there any service i could use to have one custom made? or even have you design a circuit that i could assemble?? or is there a two channel amplifier that i could bridge??

Have you ever given any thought to making a video on a diy smps to turn mains power into 5vdc, so it can be used to power a micro controller. I've looked all over but I can't seem to find a decent video or tutorial on the subject.

Is it possible to create a sine wave controller with regen braking that can handle high voltage and output high amount of watts?

Hi there. I've created an ESC control and I would like to comment some things. I'm using 16.5KHz AND the potentiometer only control the PWM which starts with 5%. The next step will happens when the hall sensors to change. This way you don't need to wait. You will be always in sync, even in low or high speeds. Sorry my poor English.

Sorry,I have a question. The TC4427 chip's operating range 4.5V to 18V,why you use LM7815 15V regulator? why don't use the LM7805 5V regulator ? Could the three pieces of TC4427 & one 74HC14 Hex Inverter Schmitt Trigger share the output of LM7805 5V regulator?

Great video! What is going on with the diy jbc soldering station? Are you still using it? If you don’t, what are you using as your main soldering station at this moment

The best conversion is the Tongsheng Or Bafang BBS02/ HD. Mid drive has the controller inside and looks much better on a bike. Yo also keep both original wheels that are most of the times better than the one that comes with the motor.
You can also use your rear gears to get a more efficient ride.
The screen on those mid drive motors are nicer too

BE CAREFUL!! that front fork looks like an aluminum one to me. You should NEVER use a hub motor with aluminum forks. I learned this the hard way. My fork failed and caused me to have a severe accident that landed me in the hospital for two days, suffering a concussion, severe abrasions to my face and shoulder, as well as a lacerated liver. On my new bike I have used a steel fork and welded on reinforcements on the front and back to make darn sure that it does not fail again. These things are very dangerous when not used correctly, as I learned.

How to add regenrative breaking feacture in this controller. I want to know how the controller and motor works during the regenrative breaking. Plz plz give the reply

Sir how i can make esc for brushed motors .i am making arduino based drone but the motor running slow .
What can i do ?

Hey Great Scott!

Why did you use Mosfets? Any specific reasons or are there any alternatives to there use here?

Hi, first of all, i whould like to say congratulations! Your channel is amazing and helpfull a lot on my projects. What about to create a serie, in which you analyze the projects of the followers, giving suggestions and tips to improve them?

why have not you written anything in void loop in the code. please tell me soon because i am making same like this one, sir… thank you

hello, ı don't understand why did you use the Schottky diodes for each mosfet?
Because MOSFETs has internal Diodes already…

wants to test esc but requires somewhat higher voltage: builds sensored esc from scratch that works with lower voltages

Thanks a lot for this awesome project but ı dont understand why you are using extra 15V voltage regulator to supply mosfet driver ?
Drivers also work between 4,5 – 18 V

Nice work I watch your video a lot however my question is can this ESC works on a IGBT at 220v dc also is the 15 volt that drives the IC has to be isolated
Thank you

Why you just supply the correct voltage. Your going to run it off batteries, so hook them up. Your not going to ride it with an extinction cord. Waist of time.

BTW, it's not "codes", it's just "code". When referring to programming, "the code" refers to all the program instructions. Each line of code is just call that, a "line of code", not a "code". A "code" is what you'd use to encrypt your messages so the enemy cant read them.

6:40 But doesn't turning on all the N FETs or all the P FETs cause a braking effect? I thought you were supposed to turn all FETs off during the PWM off duty time.

Thank you! @Greatscott!
Great job as always… I am also working on a similar project. Can this circuit be used with a input supply voltage of 48V?

This is actually pretty good. You should have turned this into a PCB, and then either etch a PCB at home or order from JLC PCB. Also about the ESC, is a micro controller really mandatory, or is there a way around it, because I am terrible at anything that involves code, and I think it can be done. Also, I recommend SMD components for the final board. Good job.

Wonderbar. I would like to add more power to the project. What would be the recommended MOSFETs for 48V, 100A or near to that. Danke !

Great job. Can you make a video in which you explain how we can replace encoder of AC servo motor as this is something tricky to align U V W of the motor with with encoder U V W. As you know modern servo motor use encoder instead of hall effect sensors. Popular companies like Yaskawa and so provide software and kits to do so but its an expensive solution and there are many companies which provide good and cheap servo motor and drives but without this feature. We work with CNC machines were we find fault in just encoder but we can't change encoder due to this alignment issue and at the end we need to buy whole motor with encoder mounted and cost more 🙁

Thank you For making this video, its Great, What needs to be changed for a higher power motor? say a 72 volt 200A motor? please help

Where do those two electrolytic capacitors go in the schematic? I notice they are in a few of the images but not in the schematic.

Hey Scott, I think I found an error in your code and a reason why the motor wouldn't spin very fast. In your switch cases I think you have your ports D and B backwards for case 3, 4, and 5. If you look at the direction (DDRD) registers in setup() you are manipulating registers that you haven't declared as output, which also happens to be exactly flipped between D and B. I think the only thing you'll need to do is flip them back.
Another reason the wheel won't spin quickly is because you only had it hooked to 15 volts. From the looks of it you'll need at least 36.

Great video and clarity in explanation. it is good for rotating the wheel with no load but if will burn out if u use it for the eBike. i would be great to see a real 48v version of this. i have been trying my own but current level is too high.

Great Scott can u provide a video on generation of three phase spwm variable frequency drive of induction motor control using arduino ??.. :)))

Hey GreatScott I have a question: Is it possible to build this with regenerative braking, and a higher supply voltage?

Hi, is there a way to hack a SENSORED ESC to make it a sensorlesss one , i meen to generate a signal and feed it to the ESC thinking like a hall sensor is attached to it , to simulate the desired pedal speed ?

Great videos! Now the series is complete it'd be pretty helpful to have links to part 2 and 3 in the description here.

Leave a Comment

Your email address will not be published. Required fields are marked *