HACKED!: Using an HDD Motor as a Rotary Encoder?!

**Harnessing the Power of Hard Drive Motors: A DIY Guide to Rotary Encoders**

As an electrical component, rotary encoders are incredibly useful for selecting and changing variables with ease. Their rotation and direction can be easily determined, making them perfect for a variety of applications. In this article, we'll explore how hard drive motors can be repurposed as rotary encoders and provide a step-by-step guide on how to do so.

**The Joy of Mechanical Encoders**

I recently had the opportunity to disassemble an old hard drive and was surprised by the power of its neodymium magnets. The motor, once freed from its enclosure, felt satisfying to spin, unlike the incremental movement of traditional rotary encoders. This experience sparked my curiosity about using hard drive motors as rotary encoders.

**Understanding Hard Drive Motors**

A typical hard drive motor consists of a rotor with alternating polarities and a stator with copper wire wrapped around stator sheets to form coils. This structure is similar to that of a brushless DC (BLDC) motor. To confirm this, I connected an ESC (Electronic Speed Controller) to the three phases of the motor, excluding the star point. By increasing the on-time of the input signal, the motor began to rotate, proving it was indeed a BLDC motor.

**Determining Rotation Direction**

The challenge lies in determining whether the motor rotates clockwise or anti-clockwise. To solve this, I cracked open an incremental rotary encoder to understand its internal workings. The encoder features a circular metal disc with conductive silver points and non-conductive black points. A sliding contact system connects the VCC, ground, DT (data), and CLK (clock) pins of the encoder.

**Detecting Rotation Using Rotary Encoders**

When five volts is applied to the encoder, its metal disk is connected to this voltage potential. As you rotate the circle for one increment clockwise, the DT pin gets connected to five volts before the CLK pin does. If you rotate anti-clockwise, the order is reversed. This means we can detect the rotation and direction of the encoder by checking which pin gets connected to 5 volts first.

**Applying this Principle to BLDC Motors**

We discovered earlier that the rotor consists of alternating-polarized magnets when rotated, moving alongside the coils of the motor. A voltage is induced into them, creating a three-phase voltage whose amplitude and frequency are proportional to the rotation speed. By connecting each phase to one input of an oscilloscope and the reference voltage potential to the star point, we can observe this effect.

**Implementing BLDC Motors as Rotary Encoders**

To utilize the analog-to-digital converter (ADC) repeatedly, I connected the motor wires to two MCP602 rail-to-rail op amps according to a simple schematic. These op amps act as comparators with a small hysteresis, creating a three-phase voltage with square voltages. This allows me to connect the comparator output of L1 to an interrupt pin and connect the outputs of L2 and 3 to ordinary digital pins.

**Upgrading the Code**

By activating the interrupts and including digital read functions to see which face got a voltage induced afterwards, my code became more flexible and responsive to the rotation of the motor. The last step was to reattach the platters and have some fun with this satisfying rotary encoder.

In conclusion, hard drive motors can be repurposed as rotary encoders by understanding their internal workings and applying a few simple modifications. This DIY guide has provided a comprehensive overview of how to create a flexible and responsive rotary encoder using BLDC motors.

WEBVTTKind: captionsLanguage: enRotary encoders.They are very useful electrical components whose rotation and direction can easily be determined.Which makes them perfect to select and change variables.And even though they do their intended job without a problem,their incremental movement is not a lot of fun to play around with.And I'm only saying this because I recently took apart an old hard drive.And did not only I found quite powerful neodymiummagnets, but also the motor of the hard drive.After removing its platters,I've freed it from its enclosure andrealized that spinning it has a much more satisfying feel to it than using an incremental rotary encoder.So, in this HACKED! episode, we will find out how hard drive motors workand in which way it is possible to use them as rotary encoders.Let's get started!This video is sponsored by JLCPCB.A manufacturer of quick PCB prototypes for 10 years.Upload your Gerber files to get high-quality PCBs for ridiculously low prices and make your projects look more professional.If we take a close look at the motor, then we can see that it features four breakout points at the back of it.By measuring the resistance between all of them, I noticed that there is a resistance of 6.4 Ωbetween three points, while there's a low resistance of 3.3 Ω between each of the three points and the fourth point.This led me to believe that the motor features a Y connection with the fourth breakout point being the star point.But, of course, there also exists other HDD motor types with only three breakout points.If we would want to create a star point for them, we would have to add a high impedance resistor to each face anduse the binding point as a virtual star point. But for now let's get back to the four wire motor type.Luckily, I had a couple of those laying around,so it was no problem to sacrifice one and break it open with a bit of force.On the inside, we can see that the rotor consists of a permanent magnet with alternating polarities.While the stator consists of copper wire wrapped around stator sheets in order to form coils.This structure is almost identical to that of a BLDC motor. So, to confirm my assumption,I hooked up an ESC to the three phases of the motor - not including the star point - and powered it all up.As you can see, by increasing the on-time of the input signal of the ESC, the motor does start to rotate.Which proves that we are in fact dealing with a brushless DC motor.If you want more information about how a BLDC motor worksand how you can make your own driver for it, then make sure to watch my previous project about the subject.But the main question still remains: How can we determine if it rotates clockwise or anti-clockwise?To find a possible solution, let's crack open an incremental rotary encoder to understand how it works.On the inside we can see a circular metal disc that features a pattern with conductive silver points andblack non conductive points.And on the other side we got a few sliding contacts that are, in one way or another,connected to the VCC, ground, DT and CLK pin of the encoderWhile it is quite difficult to understand its functional principle through the real life example,the idea is quite easy to grasp with a drawing.Now, when five volts is connected to the encoder, its metal disk is connected to this voltage potential as well,which means once we rotate the circle for one increment clockwise,the DT pin gets connected to five volts before the CLK pin does. And if we would rotate anti-clockwisethe order would be the other way around.Which means we can detect the rotation and direction of the encoder by checking which pin got connected to 5 volts first.A similar principle can be used when it comes to a BLDC motor.As we discovered earlier, its rotor consists of alternatingpolarized magnets, that when rotated, move alongside the coils of the motor.That means a voltage is induced into them.Which we can observe if we connect each phase to one input of my oscilloscopeand the reference voltage potential to the star point.As you can see, by rotating the motor in either direction, a three phase voltage is created whose amplitude and frequencyis proportional to the rotation speed.If we have a closer look at the voltages during the clockwise rotation, we can see that the sequence is L1, L2, L3,while the sequence for the anti-clockwise rotation is L1, L3, L2.The reason for that is the coil arrangement itself.Which enables us to determine the rotation and direction by checking in which order the voltages appear.To do that, I connected L1, L2 and L3to analog inputs 0, 1 and 2, respectively.And the star point of the BLDC motor to ground of an Arduino Nano.For starters, I speeded up the ADC of the Arduino and set the analog reference voltage to the internal 1.1 V,since the induced voltages of the motor never reached above this value.Then I wrote a simple piece of code which checks if the L1 voltage is in useand if so, also checks continuously alternating whether L2 or L3is the next induced voltage.Based on that, the serial monitor then outputs clockwise or anti-clockwise.And after uploading the codes,opening the serial monitor and spinning the motor in both directions, it seems like everything worked just fine.But, of course, if you would add an LCD to the system and change a variable on it according to the motor'srotation and direction, it would look a lot more impressive.Now, at this point, we could end this mini project and call it a day.But what still bothered me was that we must utilize the analog to digital converter repeatedly.It would make more sense to use an external interrupt like I did with the traditional rotary encoderThat is why I removed the motor wires from the Arduino and instead connected them to twoMCP602 rail-to-rail op amps according to this simple schematic.Those op amps basically act as comparators with a small hysteresis.Which means once the voltage of the faces is higher than the star voltage the output of the comparator will be pulled to 5 V.While when the face voltage is lower than the star voltage, the output will be connected to ground.This creates a three phase voltage as well, but this time with three square voltages.This way I can connect the comparator output of L1 to an interrupt pin,while I connect the comparator outputs of L2 and L3 year to ordinary digital pins.Now, by activating the interrupts, which only set a flag andincluding the digital read functions to see which face got a voltage induced afterwards,the code became much more flexible and responsive to the rotation the motor.The last thing to do for me was to reattach the plattersand have some fun with this quite satisfying rotary encoder.I hope you enjoyed watching this video and maybe even learned something new along the way.If so, don't forget to like, share and subscribe.Stay creative, and I will see you next time!