4

First of all I am a newbie. So please excuse.

After doing the first basic project, in which I had hooked up the positive of a LED to a digital input of the Arduino and the negative to the ground of the board, I am assuming that the digital pins in Arduino are positive (are they 5v?).

So why can't the potentiometer be connected in the same way?

Thank you.

1
  • A rotary knob encoder may do the trick. It looks very much like a potentiometer, but can be read out by digital pins.
    – aaa
    Jan 30, 2017 at 8:05

6 Answers 6

6

A potentiometer is an analog device, meaning it communicates its position by varying the voltage rather than sending discrete ones and zeros.

If a linear potentiometer is turned half way then the output of the pot will be at half the voltage of the input. If it is turned all the way then the output will equal the input voltage and if it is not turned at all then the output will be 0V.

In order to make sense of the potentiometer you must connect the output to the analog pins and it will give you a 10 bit number, the higher this number the closer the output voltage of the potentiometer is to 5v (or whatever you set the Analog Reference voltage to be, but don't worry about the AREF pin for now).

Digital pins are either on or off, there is no in between, so they do not work for this application

This page has an excellent potentiometer user guide: https://www.arduino.cc/en/Tutorial/Potentiometer        

2
  • What does “communicates its login” mean? Jan 30, 2017 at 6:55
  • @jwpat7 It was a typo I was going for "communicate its logic" but I changed it to "communicate its position" to be more clear. I am trying to say that a digital rotary encoder would tell the Arduino how far it is turned via a digital signal (a packet of ones and zeros), whereas a potentiometer tells the Arduino its position via varying the output voltage.
    – Joel
    Feb 1, 2017 at 6:19
3

I had hooked up the positive of led to a digital input of the arduino and negative to the ground of the board.

You shouldn't have done that. It damages both the LED and the Arduino.

The care and feeding of LEDs

So I am assuming that the digital pins in arduino are positive (are they 5v?).

Yes and yes (assuming a 5V Arduino).

So why cant the pot be connected in the same way?

The pot has 3 terminals, so I'm not sure what you mean by that. You are going to connect them to ground, a digital pin, and what else?


Normally you connect one end of the pot to ground, the other end to +5V, and the middle terminal to one of the analog inputs. Then when you turn the pot, the voltage at the analog input changes to be somewhere between 0V and 5V.


A potentiometer is a form of voltage divider - I suggest you read those links to understand more about them.

2

I am assuming that the digital pins in Arduino are positive (are they 5v?).

On a 5V Arduino, when a GPIO pin is set to OUTPUT and switched HIGH then yes, it is (almost) 5V. When switch LOW it is (almost) 0V or GND. When it is set to INPUT it is neither - it is "high impedance" and senses the voltage on the pin using a set of thresholds.

When the voltage being applied to the pin is above the high threshold (known as VIH) the pin sees it as a logic HIGH and digitalRead() reports it as such. When the voltage being applied is below the low threshold (known as VIL) the pin sees it as a logic LOW and digitalRead() reports it as such.

So why can't the potentiometer be connected in the same way?

So yes, you can connect a potentiometer up to to a digital pin in the same way as you can to an analog pin (one pin to +5V, one pin to ground, and the middle "wiper" pin to the digital input):

enter image description here

When you turn it, instead of reading a value between 0 and 1023 as you would on an analog pin, you will either get a HIGH or a LOW depending on how far you have turned the knob and in which direction. In the region in the middle you will read "who knows?" - that is, maybe HIGH, maybe LOW, depending on the weather and the pin itself.

Note that connecting a potentiometer up like this on a pin set to OUTPUT is dangerous (not to you, to the Arduino) and has the potential to damage the GPIO pin's internal circuitry when the pot is turned all the way one way or the other, since it creates a dead short circuit to either ground or +5V, and the GPIO pin itself, when in OUTPUT mode, is also connected internally to either ground or +5V.

Some pins on microcontrollers (not sure about the Arduino off hand) have Schmitt Trigger inputs. These avoide the "who knows?" region by toggling the input HIGH or LOW depending on when the voltage passes a threshold. For the pin to change from reporting a LOW to a HIGH the voltage has to pass above the high threshold. To then switch to reporting a LOW again it has to drop all the way down to the low threshold. Any voltage in between the two thresholds is ignored completely and the previous state is retained.

1
  • Yes, the ATmegas do have Schmitt triggers in their inputs, as stated in the datasheet. Feb 1, 2017 at 8:48
1

For connect a LED you need use a little resistor to limit the current, so you can use the potenciometer with your LED and see the bright ajust.

I had hooked up the positive of a LED to a digital input

A Arduino digital PIN as cofigurable how input or output, if you use it as input you need use this pin for read a digital value (0 or 1), example a button. When you configure the pin to output you can set the value high (~5v) or low (0v).

1

It depends on what you are trying to accomplish. If you set the pin as output and turn it on, then can use it as 5v power source. This is done frequently when you want the software to be able to turn some part of your system on/off. If this is what you want, you can put a pot or any other component downstream as long as it doesn't try to draw too much power. See this post for details on that

If you are trying to read the "value" of the pot, it would work as an on/off switch because this is a digital pin. Digital means 0 or 1. When there is enough voltage, it will register as 1, once the voltage gets low enough, it will register as a zero. If you want to read a full range of values from the pot, you would have to use an analog pin.

1

Analog pot on digital pin will give, 0:from min to half way and 1: from half way to end position You can use it if this suits your program logic.

1
  • That is not correct. You might want to read up on voltage ranges for logic levels. Sparkfun offers a basic tutorial. Apr 18, 2018 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.