Subscribe to Arduino Academy and start learning today for FREE!

Rotary Encoder Controlling Servo Position, With Last Position Memory

Ok, that was a long title, but what does it mean? I have a ham radio buddy that wants to control a variable capacitor with his Arduino. I’m using a Rotary Encoder (digital) for precision instead of a potentiometer (analog) to control the angle of a Servo. The values are constrained to only legitimate values the servo can use.

This project is based on two of my previous articles:

Fun with Servos

Using a Rotary Encoder with the Arduino

The problem we ran into, was that at power down, a rotary encoder does not retain it’s position information, so when you power back up, you start back at zero. I added a few lines that writes the current position to EEPROM every time there is a change, so that on power up, the servo returns to the last known position.

Next modification is to add a LCD display instead of using the serial monitor.

Code –

Become the Maker you were born to be. Try Arduino Academy for FREE!

Notify of
Inline Feedbacks
View all comments
5 years ago

does not work. with your code my rotary encoder works like a pot, without step, simply continue rotation CW or CCW

Steve Spence
5 years ago

Ah, but is does work, as you can see in the image. You may have a wiring or other technical issue, but rotary encoders are not like pots, they don't do "resistance".


Would love your thoughts, please comment.x