Can I control LED brightness with potentiometer without any code, as well as reading the potentiometer value?

I am just getting back into electronics and have started to play around with making my own button box.

I am trying to control an LED's brightness using a potentiometer, while also reading the potentiometer's value with the Arduino's analogue pin. I want to limit the number of pins I am using for things because I have lots of buttons that will need to be hooked up, so I am trying to control the LED without any code.

I have put together the following circuit (sorry, not my tidiest diagram. I am also using a Pro Micro rather than a Leonardo, but I didn't think that would make any difference :) ).

This works to a degree. I am able to adjust the LED brightness using the pot, and I do get a reading on the Arduino from the pot, however, the reading does not go up linearly as I would expect. It seems to get to about 500 out of 1023 at 4/5 of the rotation and then jumps up to 1023 within the last 1/5.

Could someone explain why this happens, and if it is even possible to do what I am attempting?

• the resistor and the LED are in parallel with the pot .. just having a resistor in paralel causes non-linearity ... furthermore, the LED is not linear, so its "resistance" varies with the amount of current flowing through it Nov 4, 2020 at 20:37
• if you want linear response in the reading, then use two ganged pots Nov 4, 2020 at 20:38
• why are you doing this anyway? Nov 4, 2020 at 20:39
• You could try driving the LED through a MOSFET. If you get the parameters right, so that the MOSFET stays in it's linear realm, that should work I think. The gate of the MOSFET draws nearly no current, thus the measurement through A0 should not be disturbed by it. Nov 4, 2020 at 22:14
• @jsotola Thanks for explaining this. I have ordered a few dual gang pots to try this out. Nov 5, 2020 at 20:48

You need to "buffer" the potentiometer to separate it from the LED and resistor. The simplest circuit for that is a unity-gain voltage follower with an op-amp:

simulate this circuit – Schematic created using CircuitLab

You want to choose a "Rail to Rail I/O" op-amp so that it can get right down to 0V and right up to 5V, otherwise you will clip the top and bottom of the range of the potentiometer.

• So you're using an op-amp to create a "stiff" variable voltage from the voltage divider so the load of the LED doesn't affect the ADC reading? I wish my analog electronics chops were stronger. Nov 5, 2020 at 0:17
• It's worth noting that you want to be sure to use a linear pot. A log pot would give very squirrelly results. Nov 5, 2020 at 0:19
• Basically, yes. The potentiometer is just a reference for the opamp to create it's own output with lower impedance.
– Majenko
Nov 5, 2020 at 0:19
• And then the current limiting resistor lets more or less current though based on the input voltage, thus varying the brightness of the LED. I like it. Nov 5, 2020 at 0:20
• The resistor basically converts the voltage into a predictable current through ohms law.
– Majenko
Nov 5, 2020 at 0:21

Thanks for all the suggestions.

In the end, I ordered some dual-gang potentiometers as jsotola suggested and Mejenko confirmed would work. These are working perfectly in my circuit now.

Thanks again!

I am surprised that the pot has survived so far. LEDs are current devices not voltage devices. The above circuits will work to some extent but not very well. You need to vary the current either using an adjustable current source/sink or PWM.

Some good remarks have already been made by jsotola.

Potentiometer types

(updated because of Majenko's comment):

Note there are three types of pots:

• Logarithmic (with name A<value>K, e.g. A50K for a logarithmic 50K pot)
• Linear (with name B<value>K, e.g. B50K for a linear 50K pot)
• Reserve logarithmic/Exponential (with name C<value>K, e.g. C50K for a rserve logarithmic 50K pot)

Mapping values

However, in code you can map a value from a pot to any other value, even from logarithmic/linear to anything you want, using logarithmic or other functions available in C/C++.

Shift Registers

Also, to reduce the number of pins you need for buttons you can use shift registers. The most known is 74HC595 for output and in your case you need an input shift register, which is 74HC165, see e.g. https://dronebotworkshop.com/shift-registers/ or https://playground.arduino.cc/Code/ShiftRegSN74HC165N/

• Actually, to be pedantic, there are three types of pot: linear, logarithmic, and inverse logarithmic. Audio pots are actually inverse logarithmic. Exponential, if you like.
– Majenko
Nov 5, 2020 at 0:30
• @Majenko Thanks for the comment, however, I everywhere read that audio pots/tapers are A type. Nov 5, 2020 at 8:32
• Yes, a for audio. Log tapers are rare. Inverse log audio are more common.
– Majenko
Nov 5, 2020 at 8:36
• @Majenko, thanks for the clarification. I never heard of C types before, I used A for a guitar pedal (never finished, but learned a lot). Nov 5, 2020 at 8:40