Maker.io main logo

Input Control for Everyday Projects: Rotary Encoders and Potentiometers

2023-11-10 | By Antonio Velasco

Potentiometers Movement Encoder Rotary

Introduction

In electronics projects with microcontrollers, you’ll often find yourself wanting to add some level of input or control. Whether this is increasing rover speed or changing the volume of a speaker, adding a component that allows you to modify values externally proves very useful. You could just recode the values into the microcontroller, but that’s rather inconvenient when all you want to do is change a number or setting, especially when you’re on the go or don’t have access to a computer/adapter.

Introducing rotary input–a vital type of input that plays a role in allowing users to control parameters on their electrical components. The two most commonly used components for rotary input are rotary encoders and potentiometers, which we’ll go over and compare.

Potentiometers - Simple and Effective

Potentiometers (aka pots) are essentially resistors that can change resistive value depending on the position of their “wiper.” The wiper is just a component in the potentiometer that, when turned, will move along the resistive track and either decrease or increase the resistance. The difference in resistance is then converted into an analog voltage value. They’re represented in circuit diagrams with this symbol:

image of Input Control for Everyday Projects: Rotary Encoders and Potentiometers

They’re typically used where you would like a level of analog control like adjusting motor speed or LED brightness, as microcontrollers can interpret their value and utilize them as variables within their code. Pots are very easy to use and implement in projects.

Potentiometer Project Examples

I’ve used potentiometers across two projects–an Arduino that can play songs when coded with notes and an Autonomous Underwater Vehicle (AUV) Sea Glider.

For the song playing Arduino, I utilized the pot to set the song that I wanted the project to play. As shown in the code below, I took all the possible values and divided them into 3 sections–1 for each of my songs. When I would turn the pot, it would be within one of the three intervals and play the song designated there. This allowed me to change the song I wanted to play without having to change the Arduino code.

image of Input Control for Everyday Projects: Rotary Encoders and Potentiometers

For the AUV Sea Glider, I utilized the pot to set the dive cycle times. It would be in a diving phase for a certain number of seconds and a surfacing phase for the same amount. The longer the diving time, the deeper the Sea Glider would go. To account for the different depths and bodies of water it was tested in, I had to adjust the diving cycle so it wouldn’t go too shallow or too deep. Having a potentiometer helped in these cases as I was able to directly correlate the diving time to the potentiometer decision by using the value as a variable. The LED would indicate the relative diving time (more red is closer to 0 and more blue is a higher time).

image of Input Control for Everyday Projects: Rotary Encoders and Potentiometers

Rotary Encoders - Precise and Adaptable

Rotary encoders are very similar to pots in the aspect that they still produce rotary values. However, they work very differently, and as a result, can have other applications. Rotary encoders measure the rotational movement as opposed to resistance and come in two inherently digital types.

Incremental Rotary Encoders give off pulses for every specific increment of degrees that they rotate. It can be thought of as “steps” and allows for much more precise values during operation. They’re typically used in applications where it’d be more practical to add or subtract to an existing value, such as changing the audio of a speaker.

Absolute Rotary Encoders have a specific value for every position, meaning that each point on the disc will return a unique value. For example, having the encoder at 37 degrees off from its original point will return a value of 37 to a microcontroller. This is very similar to a regular potentiometer, except that an absolute rotary encoder can spin without limitation.

image of Input Control for Everyday Projects: Rotary Encoders and Potentiometers

Here you can see that in the incremental disk position, there will either be values of increasing or decreasing, relative to the direction. In the absolute disk positions, each spot has its own unique "code."

Rotary Encoder Project Examples

I have yet to use a rotary encoder in a project but have plans to implement them very soon. While I still think a potentiometer may be the best to have for my Arduino song player, I wanted to experiment with audio levels and figure out how to increase and decrease them. An incremental rotary encoder would be perfect for this as it’d allow me to increase or decrease the volume to its maximum or minimum values, respectively, without physical limitation.

I’ve also wanted to use an absolute rotary encoder for selecting menu options on an LCD screen. Because each position has a specific value, I’d be able to put corresponding options in those areas and, when it reaches the end, it would automatically loop to the first menu option. An encoder would work perfectly for this application as it would be durable and last a long time.

Which Should I Use?

The main difference between Rotary Encoders and Potentiometers is the fact that you can continue spinning rotary encoders in any direction infinitely whereas pots have a physical barrier. This provides a more convenient experience for the user. Additionally, this physical limitation means that pots can be broken easily because of overturning, something that’s plagued my projects several times. Resoldering in a new potentiometer is truly a hassle.

Furthermore, potentiometers experience more mechanical wear and tear due to their sliding wiper, and as a result, typically have a lower lifespan than that of the encoder.

That’s not to say that encoders are always the solution, though. Rotary encoders tend to take up more space than a simple potentiometer. For example, in my Sea Glider, it might’ve been more practical to use an incremental rotary encoder to decrease or increase the number of seconds it would dive for. However, because my parts needed to be small enough to fit in a water bottle, and thus near flush to the board, the potentiometer proved to be the better option. To add to that, potentiometers are also more cost-effective and simple to implement than rotary encoders.

Conclusion

To conclude, both Rotary Encoders and Potentiometers have their fair share of pros and cons, but when it comes to your usage, it just depends on what you’re looking for. If you need a high level of precision, durability, and the ability to turn in either direction infinitely, maybe consider a rotary encoder. If your project doesn’t require a super sophisticated input control approach and just needs to change a value, like my song player, then a potentiometer is a solid and cost-effective solution. They offer simple, intuitive analog control for projects that aren’t very long-term.

Pick the component that best fits your needs, and be sure to assess what your project requires to pick the best solution. Regardless of what you choose, you’ll find that rotary input values can be very useful and allow you to control your projects more conveniently.

 

制造商零件编号 PEC16-4220F-S0024
ROTARY ENCODER MECHANICAL 24PPR
Bourns Inc.
¥16.36
Details
制造商零件编号 PEC11R-4215F-S0024
ROTARY ENCODER MECHANICAL 24PPR
Bourns Inc.
¥17.91
Details
制造商零件编号 P0915N-FC15BR10K
POT 10K OHM 1/20W PLASTIC LINEAR
TT Electronics/BI
¥24.26
Details
制造商零件编号 3362P-1-253LF
TRIMMER 25K OHM 0.5W PC PIN TOP
Bourns Inc.
¥9.28
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum