arduino rotary encoder

 


 
, 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, neodymium magnets, but also the motor of the hard drive. After removing its platters I’ve freed it from its enclosure and realized 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 work and 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 and use 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 works and 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 and black 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 encoder. While 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 clockwise, the 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 alternating polarized 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 oscilloscope and 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 frequency is 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 L3 to 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 use and if so also checks continuously alternating, whether L2 or L3, is 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’s rotation 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 encoder. That is why I removed the motor wires from the Arduino and instead connected them to two MCP602 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 and including 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 platters and 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.

 
 

arduino rotary encoder Video

 

 

 

 

 

 

arduino rotary encoder news

 

 

 

 

 

 

 

arduino rotary encoder Social

 

 

 

 

official.arduino
2019-09-13T20:23:14+0000

See the world through the eyes of this camera-equipped, snake-like robot.
safe image.php?d=AQB2kdm3zOD71KQX&w=720&h=720&url=https%3A%2F%2Fblog.arduino.cc%2Fwp content%2Fuploads%2F2019%2F09%2FUntitled 2 3 - arduino rotary encoder
official.arduino
2019-09-13T16:58:23+0000

This 3D-printed prosthesis uses computer vision to adjust its grip depending on the object.
safe image.php?d=AQD dQbotzfS6mLl&w=720&h=720&url=fbstaging%3A%2F%2Fgraph.facebook - arduino rotary encoder
u2s xsPw normal - arduino rotary encoder
keyestudio1
Tue Aug 06 07:13:08 +0000 2019


Ks0013 keyestudio Rotary Encoder Module for Arduino
The rotary encoder can count the pulse outputting times during the process of rotation in positive and reverse direction by rotating.
wiki: https://t.co/VrhXakH1a3 https://t.co/sjXSNgSFtX

https://t.co/VrhXakH1a3

keyestudio1 photo

3D printing at home

linux-works photo

DIY Macro Rail

Jelly Brain photo

2016-04-15T14:35:45



 photo

2016-04-15T14:35:40



 photo

2016-04-15T14:35:36



 photo

 

 

(Visited 25 times, 1 visits today)

About The Author

You might be interested in

Comment (23)

  1. What about this used in bl dc for field measurement and drive bldc accordingly? but in this case back emf should be problematik. It might be some how high voltage protection.

  2. 5:30 would be easier/more intuitive to see if you offsetted it: counterclockwise is L3 L2 L1 (which is the exact reverse of clockwise L1 L2 L3)

  3. JESUS CHRIST SCOTT DON’T POINT SHARP OBJECTS TO YOUR SCOPE I had a heart attack here what if you touch with it…..

  4. GreatScott: *makes super easy to understand circuit and code*
    Me: Wow! That’s sup-
    GreatScott: EXTERNAL INTERRUPTS

  5. As usual, great content and great presentation from Great Scott, who is always GREAT!

    A fun project would be to add some audio FeedBack for each ‘tick’ as when a key is tapped on a smart phone and then add a little ‘KICK’ with reverse voltage back into the phases to produce tactile FeedBack.

    Again, GREAT vid.

    Russ in NH

  6. 2:07 some years ago in an exam there was a problem that included a balanced network with a neutral wire. One part of the problem was to determine the current across the neutral…I wrote 2 pages of calculus…to only realize after the test tje right answer was only 1 line I=0 and I knew it but the nerves tricked me in middle of the exam.

  7. beatmania iidx controllers use an extremely similar mechanism to figure out the position of the turntable on it. some home controllers (such as the one I have) use optical encoders instead for ease of use/cleaning purposes. this gives me a lot of cool ideas for stuff I could do with some old drives.

  8. I was looking for a way to make a rotary encoder from a HDD motor but found your instruction very interesting and easy to understand. Thanks and keep em coming.

LEAVE YOUR COMMENT

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