Close
0%
0%

Magnetic Incremental Rotary Encoder

A compact solution for your closed loop positioning requirements

Similar projects worth following
Rotary encoders are used to measure angular position of a shaft. Several types of rotary endcoders exist, the differerence being the strategy used to measure angular position increments, with the most common ones being mechanical and optical ones. This project aims to provide a compact, easy to use, relatively high resolution and arguably cheap encoder. It uses the AS5040 IC from Austria Microsystems.

Quick Intro to Rotary Encoders

A mechanical rotary encoder uses a wiper (or wipers) that closes a circuit along a set of contacts distributed along a circumference. The wiper is attached to the shaft one is working with, and as this shaft turns, the wiper opens and closes a circuit, thus generating a pulse train that can be used to determine the angular position of the shaft (and its higher order derivatives with respect to time)by counting the number of pulses. A similar idea its used on the optical encoders, with the set of contacts replaced by a disk full of cutouts attached to the shaft, and a light source/photodetector that are placed on opposite sides of said disk to make the disk sequentially block and allow the light to shine onto the photodetector, again generating a pulse train containing useful Kinematic information.

One light source/photodetector pair is useful if one does not need to determine the direction of rotation of the shaft. By adding a second set of cutouts (or a second light source/photodetector pair) 90 degrees out of phase with respect to the first one, one can detect the direction of rotation of the disk. Devices that employ this technique re called quadrature encoders, and they normally designate the photodetectors as A and B.


Enter the AS5040

The AS5040 is sensor that detects changes in the angular position of the poles of a magnet, and outputs a two pulse trains, analog to the A and B outputs of optical encoders. I find this IC more versatile than an optical encoder. Some of its advantages are:

  • End user settale resolution: 128, 256, 512 or 1024 state changes per revolution with 4x decoding.
  • Only requires a two pole magnet to work.
  • On chip decoding of the quadrature singnal.
  • 30,000 rpm maximum speed!
  • Operates at 3.3 V or 5 V.
  • End user settable zero.
  • Can be used as a brushless motor sensor.

The end user settable resolution its useful for avoiding bogging down the controller decoding the pulse train, specially at high speeds. Also, gluing a magnet onto a shaft and then alligning the PCB containing the sensor its easy, in contrast to fabricating a disk with 256 cutouts and mounting it to the corresponding shaft and light source/photodetector. Also, the final result is far more compact compared to the cheap otical encoders with similar resolution out there.


  • 1 × B4B-PH-K-S(LF)(SN) CONN HEADER PH TOP 4POS 2MM
  • 2 × SML-D12V8WT86 LED RED DIFFUSED 0603 SMD
  • 1 × 0.1 in male 90º header 3 pin header
  • 2 × CC0603KRX7R9BB104 CAP CER 0.1UF 50V X7R 0603
  • 1 × RC0603FR-0710KL RES SMD 10K OHM 1% 1/10W 0603

View all 7 components

View all 4 project logs

  • 1
    Step 1

    Glue the magnet onto the rotating object to be measured. Be sure it is centered. Epoxy is useful for this step.

  • 2
    Step 2

    Place the PCB near the magnet. When the sensor is too far away from the magnet or not alignet with it, the onboard LEDs will be lit. Move the sensor around a bit until the LEDs turn off.

  • 3
    Step 3

    When the LEDs turn off, rotate the object with the magnet. If you see the LEDs flash it means that the assembly is still not fully aligned. Adjust until you can rotate the magnet without seeing the LEDs flash.

View all 3 instructions

Enjoy this project?

Share

Discussions

ekaggrat singh kalsi wrote 12/19/2020 at 22:58 point

i am looking for a way to connect 3 of these sensors to a single arduino . Is it possible ? i cant seem to find anywhere that how multiple seonsors can be used on a single mcu. 

  Are you sure? yes | no

James Newton wrote 02/09/2016 at 20:14 point

I'm confused as to how you adjust the PCB... with the setup you have in the picture, it looks like it would be a fixed distance from the magnet. Actually... I'm confused as to how it's being held onto the back of the motor. Are there screws that I can't see in the picture? Or is it glued on?

  Are you sure? yes | no

ottoragam wrote 02/09/2016 at 20:44 point

The pcb adjustment is done by moving the thing parallel to the motor's endcap, because the magnet needs to be centered relative to the encoder IC.

In this case I glued the enclosure to the motor. You could drill and tap some holes in the endcap, if it's more convenient, to hold the enclosure (it has those two extra holes for that) or to hold the PCB directly. You could also glue some standoffs

  Are you sure? yes | no

James Newton wrote 02/12/2016 at 20:19 point

Excellent! I'm thinking about all the different ways to mount it mechanically...

  Are you sure? yes | no

alpha_ninja wrote 12/07/2015 at 01:06 point

[verified: no design files missing]

  Are you sure? yes | no

Boris van Galvin wrote 11/15/2015 at 01:11 point

Hi ottoragam, here is a quick video of the shaft. 

The shaft now has an optical encoder strip on the side and works OK however i had contemplated replacing this with a magnetic strip, the same type of  magnetic sheet that is used for magnetic signs on cars set.  At the moment  the optical encoder gives me about 3mm of resolution and is accurate enough for this project. 

The shaft must be easy to swap in and out.




  Are you sure? yes | no

ottoragam wrote 11/15/2015 at 02:29 point

What resolution does the encoder you're using there have? If you want more resolution and want to keep using a rotary encoder maybe you could consider using the AS5045B. It's the higher resolution (12-bit) brother of the AS5040 and it's pin compatible with it.

  Are you sure? yes | no

Boris van Galvin wrote 11/15/2015 at 03:03 point

I only need about 3mm or so resolution. just needs to sense if the shaft jamms and does not move to the target that is set, either continue to try or reverse back to the zero point. 

at present the encoder strip is glued to the other side of the shaft and im using an optical pololu wheel encoder set so it can be used in a linear manner. 

The reason I can't use the encoder as a rotary is the friction drive from the motor to the shaft may slip so the sensor on the shaft was the best option. 



  Are you sure? yes | no

ottoragam wrote 11/15/2015 at 03:41 point

I don't know why the reply button ios missing from your most recent comment.

Regarding the encoder, I don't know the arrangement of the hall effect sensors inside the AS5040, so I can't say if using a magnetic strip with this particular sensor will work, as it is designed for rotary sensing. Maybe you're better off by using the AMS sensors specifically designed for linear motion. It also occurs to me that you could place a non powered roller contacting the bar, but this one covered in something compliant that has a high coefficient of friction, like poliurethane rubber, and mount it very close to the bar, so it presses hard against it, insuring no slippage. Then you can istall the rotary encoder on this extra roller and use it to determine the linear displacement.

  Are you sure? yes | no

Boris van Galvin wrote 11/14/2015 at 22:40 point

Looking forward on seeing more of this, would be interested to see if there was a way to convert it to sense linear motion as that is something that is a real pain in the rear. optical sensors seem to be the only option at the moment. 

  Are you sure? yes | no

ottoragam wrote 11/15/2015 at 00:01 point

Hi Boris, this could be used to measure linear motion, by attaching
it to a rolling element (e.g. a ball bearing) coupled to the object that
performs the motion. You could also check the AS5311 sensor, it is
somewhat analogous to the one I'm using here, but the downside is tht it
requires a magnetic strip to work.
May I ask how are you planning to use it?

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates