When working on projects, sometimes it's really useful to be able to track the rotation of an object. Whether that's the shaft of a spinning motor, or a knob that you turn to select an item on a user interface. In this post I'll talk about how encoders work, and how to read them with a microcontroller. I'll even go over a couple of mistakes that I've made that you should avoid. Encoders come in two different varieties. There's the electromechanical kind that have physical switches that open and close inside them. Then there are the contactless kind that usually use magnetic fields or light to detect the rotating shaft.
Bill of materials
Rotary encoder: https://www.digikey.com/short/d4pn3mj2
Limit Switch: https://www.digikey.com/short/8j5jchvf
Nema 17 Stepper motor: https://www.digikey.com/short/b9fzpttt
Fluke 117 Multimeter: https://www.digikey.com/short/q2jqvjhj
Resistor Kit: https://www.digikey.com/short/q4w7wj75
Jumper Wire Kit: https://www.digikey.com/short/8n0p92pn
Rigol DS1054 Oscilloscope: https://www.digikey.com/short/3j4b3vrb
Geared DC motor with encoder: https://www.digikey.com/short/9bd8mh0v
Arduino Nano Microcontroller: https://www.digikey.com/short/bzc8j5wn
Breadboard: https://www.digikey.com/short/nbh4q298
Github project: https://github.com/bytesizedengineering/stepper-motor-encoder
Learn More:
What is Switch Bounce and How to Debounce https://www.youtube.com/watch?v=IvU8m_30iK0
Byte Sized Engineer channel - https://www.youtube.com/@bytesizedengineering
Maker.io - https://www.digikey.com/en/maker
DigiKey’s Blog – TheCircuit https://www.digikey.com/en/blog
Connect with DigiKey on Facebook https://www.facebook.com/digikey.electronics/
And follow us on X: https://twitter.com/digikey