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 – http://tny.cz/06b56746

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

Subscribe
Notify of
guest
2 Comments
Inline Feedbacks
View all comments
Unknown
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".

Archives

2
0
Would love your thoughts, please comment.x
()
x