Building A Magnetic Rotary Encoder

[Long Haired Hacker] has undertaken a high-resolution 3D printer build. He got his hands on some motors to drive the build platform but it doesn’t have a built-in encoder. He knows that optical encoder wheels can have problems due to dirt and grim as well as ambient light so he set out to find a better way of providing feedback to the controller. He ended up building his own magnetic rotary encoder which is shown above.

At the heart of the system is an AS5043 magnetic rotary sensor. The chip, which runs from $6.50-$11, can detect and report the rotation of a magnetic field with great precision. The rotation data can be read out in degrees using SPI, but it sounds like there’s also grey code output on a few pins if that suits your needs a bit better. The magnet which the chip measures is mounted in a sleeve milled to seat inside of a bearing ring.

The 3D printing method [Long Haired Hacker] has chosen uses a projector and light-cured resin to achieve the kind of results seen in this other hi-res printer.

15 thoughts on “Building A Magnetic Rotary Encoder

  1. Just a minor correction. I’m assuming you meant to say “dirt and grime” instead of “dirt and grim” (unless you really did mean to suggest that a modern decedent of the famous fairy-tale recorders is going around sabotaging optical encoders. In which case, it should be two ‘m’s and you forgot to capitalize the ‘G’.).

      1. I have found that the device is somewhat tolerant of the magnet and chip not sharing the exact same axis of rotation; so if your magnet is offset from the axis of rotation slightly that is okay. However I have also found that the chip and magnet need to be plane-parallel and that the distance separating the two needs is important. From the datasheet of the part I’ve used:

        “NOTE: For the accuracy specified the center line of the magnet
        needs to be square to the chip within 2° and aligned within
        the center of the board ±0.1 mm (mid point between the 2
        mounting holes).”

        The +/-0.1 mm alignment is easier to achieve than the 2deg plane alignment if you’re limited to a drill press and hand tools.

        Datasheet Link:
        ( )

    1. The chip is centered on the axis of rotation with the top facing towards the wheel and the circuit board is affixed directly to the wheel with screws.

      The magnet goes on the end of the axle, inside the bearing, a few mm from the top of the chip.

  2. I’ve played with a bunch of the AS504x chips. The 5040 will output quadrature encoder, so it can plug straight into a servo amp like Gecko’s. The 5045 only has SPI output but having 12 bit resolution is pretty cool. I have arduino code for both the ’40 and ’45 here: and do sell the chips on breakout boards as well. I’m just finishing a version that’ll fit inside a small sparkfun RC servo and replace the potentiometer — but hoo boy there’s not much room inside that little plastic case. You need the magnet centered on the chip, but the chip has two LED outputs that will visually tell you when it’s aligned correctly. It’ll also give you good output up to crazy rpm’s. They work beautifully for robotics and CNC control.

  3. Also, is a great starting point for finding good prices; I’ve found Component Distributors International and Future Electronics have the best prices on Austrian Microsystems chips.

  4. Not to be a twat or anything, but it strikes me that a magnetic encoder is a step backwards. Mainly because the automotive industry (who used magnetic encoders for decades) now use optical encoding for engine RPM and engine bays get a lot grimier than most things. Missing tooth encoding may be a better option.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.