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.