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

**The Electric Bike Conversion Project: Creating a Sensored ESC**

As warm seasons approach, it's time to free my bicycle from dust and oil its chain. And, as you can see, its mechanical drive system still works without a problem. But for an electronics enthusiast like me, it's 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.

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.

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.

**The Theory Behind BLDC Motors**

Let's get started! 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, which 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 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 ESC in a previous project, so definitely have a look at that if you want to know more about the theory behind it.

**Creating the Sensored ESC**

What the code 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.

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

**Testing the Sensored ESC**

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!

WEBVTTKind: captionsLanguage: enSince warm seasons are slowly approaching, it was time for me to free my bicycle from dust and oil it's chainAnd, 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 componentsSo, 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!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 rotatingSimplified, 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. Ialready talked about how you can make them rotate by creating your own ECE in a previous projectso definitely have a look at that if you want to know more about the theory of those motors asas a reminder thoughWe simply must connect each phase of the motor to either the supply voltage or ground in a very specific orderWhich repeats continuously it too creates the rotational movementsBut 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 workBut definitely not optimal since such bike wheels are supposed to rotate much slower than traditional BLDC motorsThat is why it got those three Hall effect sensors attached to the motorBy connecting their red wire to five volts and that black wire to groundWe can hook the output of each of them up to the oscilloscope and see that whenever a magnet comes close to themThey pull their outputs up to 5 voltsThis way we got 3-year phase shift to square waves that tell us where the rotor is locatednow we can use this information to determine when the next step should be initialized andJust like that we no longer need to back electromotive force of the floating facewhich was proportional to the rotation speeds and thus only possible at high speeds andwith the motor control theory out of the way, let's start creating our own censored ESC asAs you can see I use P channel and N channel MOSFETs with an appropriate driver for eachTo connect the three motor phases either to the supply voltage or groundBut since the p-channel MOSFETs turn on at zero volts and turn off at 5 voltsWhich is the exact opposite of the N-Channel MOSFET behaviorI simply added a hex may trigger inverter to the control lines of the p-channel MOSFETsSo that the programming for the Arduino will be easier later onThe last mandatory component was a potentiometer to set the rotation speeds and three inputs for the Hall effectsensors andWith those guidelines in mind I started creating a schematic for the project which in the end turned out to look something like thisso I gathered all the required components and started soldering them to a piece of perfboardand afterwards to one another according to the schematicand if you're interested in experimenting with your own sensor BLDC motorThen you can of course find the schematic, code, pictures and more information about this project as always in the video descriptionafter four hours of soldering the circuit was finally completeand after inserting the ICs all that was left to do was the programmingNow while the codes which, I created looks pretty intimidating it is quite easy to understand if you are familiar with external interruptspin change interrupts the free run mode of the ADCTimers and port manipulation, so have a closer look at my other videos and learn all about it if you're interestedAnyway, 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 activatedThen timer one says okay, let's activate the corresponding MOSFETs of the stepBut after a certain amount of time which is determined by the potentiometerTimer one then says let's connect all phases to one another and take a quick break before we power the phases once againThis creates a PWM signal which basically lowers the average voltage and thus lowers the currentWhich lowers the magnetic forces and thus the rotation speedThis process continues until there's an another Hall effect sensor state change, which then activates the next stepSo in theory the code should work finewhich means it was time to upload it connect the motor wires as well as the Hall effect sensor wires to the boards andPower it all up and as you can see the wheel starts rotating and the speeds can be adjusted by the potentiometerBut as expected the wheel rotates rather slowly with a 15 volt supply voltagebut it is still a lot of fun to play around withI hope you enjoyed watching this video and are looking forward to the next episode of the electric bike conversion projectAs always don't forget to Like share and subscribeStay creative, and I will see you next time