BLDC Motor Control with Arduino, salvaged HD motor, and Hall Sensors by dlginstructables
There is a lot of interest these days among hobbyists in controlling brushless DC (BLDC) motors, which have improved performance and better energy efficiency over
traditional DC motors, but are more difficult to use. Many off-the-shelf products exist for this purpose. For example, there are lots of small BLDCs controllers for RC
airplanes that work really well.

For those wanting to delve more deeply into BLDC control there are also many different micro controllers and other electronic hardware intended for industrial users and
these usually have very good documentation. So far, I have not found any comprehensive descriptions of how to do BLDC control with an Arduino microcontroller. Also, if
you are interested in doing regenerative braking, or using a BLDC for power generation, I have not found many products that are suitable for use with small motors or
much information on how to control a 3-phase generator.

This instructable started out as a demonstration project in a class on real-time computing, and which I continued after the class ended. The idea for the project was to
demonstrate a scale model of a hybrid electric vehicle with flywheel energy storage and regenerative braking. The motors used in the project are small BLDCs
scavenged from broken computer hard drives. This instructable describes how to implement BLDC control with one of these motors, an Arduino microcontroller and Hall-
Effect position sensors, in both motoring and regenerative braking modes. Note that having access to an oscilliscope is extremely helpful, if not essential, to doing this
project. If you don't have access to a scope, I have added some suggestions for how it might be done without one (step 5).

One thing that this project doesn't have that should be included in any practical motor controller is any safety features, such as overcurrent protection. As it is, the worst
thing that can happen is that you burn out the HD motor. However, it would not be too difficult to implement overcurrent protection with the current hardware, and perhaps
I will do it at some point. If you try controlling a larger motor, please do add overcurrent protection, to protect your motor, and for your own safety.

I would like to try using this controller with a larger motor that can do some "real" work, but I don't have a suitable motor yet. I noticed an 86W motor for sale on eBay for
around $40.00 that seems like a good candidate. There's also an RC website called "GoBrushless" that sells kits for putting together your own BLDC. These are not too
expensive and building one is a worthwhile experience. Note that the motors from this web site do not have Hall sensors.

Whew! It was a lot of work to write up this instructable. I hope you find it useful and please post your comments and suggestions.
 
Remove these adsRemove these ads by Signing Up

Step 1: Video

first frame.jpg

1-40 of 49Next »
elabz says: Mar 24, 2013. 9:44 PM
I love to spin these up to 10,000 RPM + myself but just a bit of a warning is in order here I think. Just yesterday I've opened a 2.5" (laptop) HDD in which the platter has shattered to thousand very dangerous looking glass shards. I assume not all HDDs have ceramic platters, especially not very old ones, but if they do, you spin it up high and it breaks from vibration or you've overtightened the bolt(s) or something like this, the result would be very much like an explosion of a grenade and someone will end up in a hospital or dead. For any serious RPMs you need to have some sort of a cover - the HDDs own body is nice or perhaps a cover from a 100-CD blanks box or some such.

Other than that, happy spinning!
dlginstructables (author) says: Apr 5, 2013. 4:41 PM
Thanks for the comment. I thought that the hd platters were made of metal, but I looked it up and some of them are in fact glass/ceramic. In my project, I had several of them glued together and they were never screwed down tightly, but, when I get a chance, I will add a suggestion that a clear cover be put over the platters.
CraigHyatt says: Apr 3, 2013. 3:05 PM
This is one of the best instructables I've seen. I like that you broke down how the Hall sensors and bridge operate in such a detailed day. Bonus that you included regenerative braking. I've read a ton of documents on this topic, and this is the first time I have actually understood what is going on. Thanks!
dlginstructables (author) says: Apr 5, 2013. 4:37 PM
Thank you very much for the compliment! I put a lot of work into describing everything and I like to know that people are benefiting from it. Yeah, regen braking is hard to grasp, and I by no means have it down. I don't know why there isn't more info out there about it. By the way, I recently drove a Nissan Leaf, and when it does regenerative braking it sounds pretty much the same as my little disk drive motors do!
elabz says: Mar 24, 2013. 9:35 PM
Not sure what you mean by "running the motor as a stepper motor, not as a BLDC" - 9 cog 12 pole BLDC motor is very much like a 36 SPR stepper. Did you mean that his commutation sequence did not include a high-Z state for one of the windings in each step?
E_motor says: Feb 28, 2013. 7:45 AM
awesome guide this! Just fyi, step 5's first picture tag shows 15 degrees, so does the second last line on that page, and the second line in step 7 also says 15, where they should be 30 degrees apart. Was a bit lost until I saw your exchange with Carl.
guillempq says: Jan 1, 2013. 8:42 AM
Is it better control 4 brushless motors through receiver or this special chip?
guillempq says: Dec 31, 2012. 8:18 AM
Can you write an example about the Arduino working with a commercial Brushless Motor, please?

int motor = 0;
void setup() {
pinMode(motor, OUTPUT); //analog Pin
}
void loop() {
analogWrite(motor, 255);
delay(1000);
analogWrite(motor, 40);
delay(500);
}
But it doesn't work?
Regards and thanks
dlginstructables (author) says: Dec 31, 2012. 1:59 PM
The arduino digital pins can only output a very small amount of current, so if you have your motor directly connected to the Arduino, I wouldn't expect it to work. What you need to do is use the analogWrite output to control a separate power source.

Here is one instruct able that uses a special chip for controlling motors that will allow you to operate the motor in both directions: http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/?ALLSTEPS

If you only need to run the motor in one direction, then you can use a MOSFETtransistor like this one, which has a link to an arduino tutorial:
https://www.sparkfun.com/products/10213

Good Luck!
mhyanni says: Nov 1, 2012. 8:18 AM
Man,You're Great !!
I'm gonna start on the Project thanks for your help my friend !
dlginstructables (author) says: Nov 1, 2012. 10:45 AM
Thank you. I put a lot of work into this instructable, and I hope it helps you do the project successfully.
tomshirvo says: Sep 19, 2012. 4:36 PM
Hi,

Yes they all support 2A but after some troubleshooting I found that the motor only draws .05A from a working 3 phase controller I have. I did find that one of the hall sensors is not working correctly.

I have tested everything;
I tested that the out puts work High, Low and NC they are fine. I am using 24V and not 12V like you did, does that mean that I should have made some changes with resistors. The one thing I did do was connect both the Sense one and two together and then connected the resistor to GND.

The motor just doesn't seem to spin at all.


dlginstructables (author) says: Sep 21, 2012. 1:40 PM
There are three Hall Sensors and each one must have its own resistor and its own input to the Arduino.

Have you tried getting the motor to turn by manually powering the phases (see step 4)

Step 1 2 3 4 5 6
Clockwise: CB, AB, AC, BC, BA, CA
Counter Clockwise: BC, BA, CA, CB, AB, AC]

have you tested the Hall sensors? You should be able to make them go high by putting a magnet near them.

Do you have an oscilloscope? It helps to have that to see if the hall sensors are in synch with the motor (you can spin the motor by hand and watch the sensor output
tomshirvo says: Sep 22, 2012. 12:28 AM
Ok really strand thing, even though my multimeter give me a reading of 24v out of the outputs 1,2,3 when I make output 1 positive and output 2 negative I get a reading out on the multimeter 24v. BUT this is a big but, when I connect just a plane old dc motor to it nothing happens. If I put the motor on the 24v directly it works fine.

I keep thinking that it has something to do with the sense 1 and 2. you did say that you needed a 400ohm from sense to GND but mine is 470ohm.

dlginstructables (author) says: Sep 24, 2012. 8:06 AM
Try measuring the voltage of the output while the DC motor is connected. If the voltage goes way down, then maybe not enough current is being supplied.

I don't know if it makes a difference to have 470 or 400 ohms on the sense pins.

I need to go back and read the instructable because I have forgotten so much. I will do that when I have time.

tomshirvo says: Sep 25, 2012. 11:56 PM
I have done the same and I don't know where I got the 400ohm resister from. I took that out of the system and it WORKS, sort of. It seems to spin some of the time. Some times it will spin for a while and then start to slow down and stop. Some times it will turn once and stop. and so on.

Thanks for your help so far i'm very grateful, but if you have any ideas with the new problem I'm happy to hear it.

Thanks again
dlginstructables (author) says: Nov 1, 2012. 10:44 AM
Also, take a look at the Hall sensor calibration, to make sure that it matches the back EMF
dlginstructables (author) says: Nov 1, 2012. 10:43 AM
Sorry I haven't replied in a long time. Have you had any progress? Based on your last message, I would take a look at the sequence of the motor's back EMF and make sure that your software is firing the digital outputs in the correct order. Do you have an oscilloscope to look at this?
tomshirvo says: Sep 22, 2012. 12:09 AM
One hall sensor is dead I'm not sure why but the others all work and my circuit works for that.

If you put the motor on a motor controller I have it works fine.
If you just take two of the phases and put them across the positive and negative terminals the motor moves a fraction.

I have a multimeter and when I put it on the terminals I can get a positive and negative and NC reading from each of the 3 phases of the out pins.

I have gotten this motor to turn just using relays it was slow and very noisy but it worked my point is the motor works.

I will list a few of the voltages coming off the L6234 below;
Vs: 24v
VBOOT: 31.7v
VCP: 4.61v
VREF: 9.24v
Sense 1 & 2: 0

I hope this helps. I'm so stuck right now. I don't understand how I can get voltage out of each output but nothing works



tomshirvo says: Sep 18, 2012. 11:53 PM
Hi,

I have been trying to follow this instructable and I just cant get it to work.
I have built the electronics but the nothing works. the only difference is that I am using a 24v 2A BLDC and a Arduino UNO R3

Do you know if the code doesn't work with the UNO R3
dlginstructables (author) says: Sep 19, 2012. 1:25 AM
Hi, you are the first person to write that you are trying to do this project :)

I wrote the code for a Duemilanove, but I think it should work fine with an UNO. I did this project three years ago, but I can try and help you troubleshoot.

My first question is: Do all of your electronic components support 2A?

Second, you say that nothing works. Why don't you start with an individual step iin the instructable and describe what is happening.
chuvso says: Mar 30, 2012. 6:43 AM
How can I check operation of Hall sensor?
Can I check it by Sanwa Analog Multitester ?
dlginstructables (author) says: Apr 7, 2012. 8:33 PM
The best way to test the Hall sensor is with an oscilloscope, but you can use a multitester (we call it a multimeter in the U.S.).

First, connect the sensor as shown in my instructions, and then move a magnet slowly across the sensor. When the sensor works, you will see the voltage go high when it senses the magnetic field. A refrigerator magnet is useful for this, because it has stripes of magnets and as you move it across the sensor, the voltage will go high-low-high-low...
Pash1987 says: Nov 4, 2011. 10:54 AM
I'm relatively new to Arduino and am currently still finding my feet on it.

I am designing a parking sensor and need to use the analogWrite() function to control my sensor as the tone() function is tied up somewhere else.

I was wondering if you could run me through how you altered the frequency of the analogWrite() PWM.

Any help would be greatly appreciated.
BradyZ says: Jan 14, 2012. 10:57 AM
You modify the TCCRnB ('n' is the number of the timer) register for one of the TIMER's. The ATmega328P has 3 timers (TIMER0, TIMER1, and TIMER2). If you want to change the PWM frequency, you just modify the prescaler value for whatever timer you want to change. TIMER0 is used for delay() and millis(), so it's better to use any timer other than TIMER0; but usually nothing bad happens if you modify TIMER0. Your program just wont have/use the correct values in delay() and millis(). To change the PWM frequency on pins 3 and 11 (they use TIMER2) to be ~4kHz (3906.25) you simply place the following line of code in your "void setup()" space:

TCCR2B = TCCR2B & 0b11111000 | 0x02;

- The default for TIMER2 is "0x04"
- If the code is confusing, check out these links for some help:  
      -http://arduino.cc/en/Reference/Boolean  
      -http://arduino.cc/en/Reference/BitwiseAnd  
      -http://arduino.cc/en/Reference/BitwiseXorNot
      -http://arduino.cc/en/Reference/Bitshift

This will work on any 'ATmega' or 'ATtiny' that is supported by Arduino (install ATtiny 'cores' to program them with Arduino 0022 or Arduino 1.0)


I did not figure this stuff out myself. I'm just passing the information onward. Check out this page in the Arduino Playground. It's extremely helpful!
      -http://arduino.cc/playground/Main/TimerPWMCheatsheet
Nakiros says: Nov 4, 2011. 2:05 AM
For higher power you should better turn to mosfet bridges(like the irf3704s-77A@10V) and gate drivers (ir2101 or ir2110). Just google 'Open BLDC' and you will find more info.
Spydamonky says: May 25, 2010. 12:02 PM
 so is the speed of the motor variable? cause im making a autonomus hexacopter and need a speed controller based on a arduino. also dus it use the hall effect sersors for the speed control or only for braking. is there any feedback about the rmp?? ie can you read off the current rpm of the motor any time ??
lampuiho says: Oct 28, 2011. 5:01 PM
the speed of the BLDC motor is determined by the frequency of the pulses of voltage sent to the stator windings. So what you need to do to increase the speed is to reduce the period of the signal and vice versa.
dlginstructables (author) says: May 28, 2010. 9:29 PM
I'm also interested in building a quadracopter, but I wouldn't recommend this for your project. Yes, the Hall sensors can be used to vary the speed, but it pretty much takes all of the arduino's capacity to do the motor commutation. There wouldn't be much computing power left for other functions, and you would need one arduino for each of the 6 motors, plus another to do the control. I know that commercial electronic speed controllers are not cheap. There is one, the Markus 10 that only runs about $25. It's very small but powerful enough for your needs.

Thanks for your interest.
lampuiho says: Oct 28, 2011. 4:54 PM
Are you controlling the field current directly? If not, that's probably the reason why it didn't work well.
Gnutella says: Sep 30, 2011. 4:33 AM
My HD motor has 4 contacts . can you please explain how i could make them turn clockwise and counter clockwise? explain it to me like youre explaining it to a Four year Old.
dlginstructables (author) says: Sep 30, 2011. 8:25 AM
Three of the contacts are the three phases and the fourth one is the center tap, where all the phases meet (search on the Internet for "BLDC Wye Configuration") This contact can be used as a sort of reference "ground" voltage, but you don't need to use it for the control scheme described in this instructable.

Use an ohmeter to figure out which are the three phases and which is the center tap. The resistance between any two phases should be double the resistance between a phase and the center tap.

As far as getting your motor to spin CW or CCW, please read the instructable carefully, as I believe I put detailed instructions on how to do that. If you still have problems, send another comment.
rany says: Aug 31, 2011. 10:17 PM
Thanks a lot for the the nice upload ... superr..
carl says: Jun 17, 2011. 12:02 PM
It looks to me like the hall sensors need to be 30 mechanical degrees apart, which I think would be 120 electrical degrees. Am I making a conceptual error? My motor has 12 slots and 8 poles, which appears to me to be similar to your motor.
dlginstructables (author) says: Jun 17, 2011. 12:22 PM
It's been a long time since I designed the system, so I'd have to go back and confirm why I chose 15 degrees, but I know that it works this way. I believe there are often multiple ways to configure hall sensors on a motor, so 30 degrees may work as well.
carl says: Jun 17, 2011. 1:46 PM
Thanks for the reply. I too am trying to learn about bldc motor control by starting small. I wouldn't have questioned the 15 degree spacing except that I couldn't fit my hall sensors 15 degrees apart without overlap on a sketch of the rotor diameter. From your photos it looked to me like your hall sensor holder was built at 30 degree spacing (it looks like an equilateral triangle will fit between the center and the outer two Hall sensors). I thought I'd ask before I started hacking into my holder material. I guess this is the opportunity for learning that I was looking for!
dlginstructables (author) says: Jun 17, 2011. 2:12 PM
I'm happy that someone is actually using this Instructable! I wrote 15 degrees in my text, but I'll try and take a look at it this weekend. Do you know how to actually figure out hall sensor spacing on a motor?

I'm curious, do you have access to an oscilloscope?
carl says: Jun 17, 2011. 10:00 PM
I drew a sketch of the poles and sensors, then rotated the poles to try to understand how the signals change during rotation. A 30 degree spacing works. A 15 degree spacing does not work (a 111 and 000 shows up at that spacing since the sensors span 30 degrees and a pole spans almost 45 degrees). It looks like the image in step three shows sensor B output inverted, making it look like the sensors should be spaced 60 electrical degrees apart when they should be 120 electrical degrees apart. That's my story at the moment. I will need to throw something together and put it on the oscilloscope and see what happens.
dlginstructables (author) says: Jun 18, 2011. 3:03 AM
You are right! My sensors are placed 30 degrees apart, which is 120 electrical degrees. I corrected the text. Thanks for catching that!
carmatic says: May 7, 2011. 4:56 PM
This looks like 'dynamic' braking rather than 'regenrative' braking, as in the motor is basically shorted out, and the energy would be dissipated as heat in the wires... I do not see how the energy is stored from braking?
1-40 of 49Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!