Using potentiometer to demonstrate ADC of Analog pin

I am reading about analogInput pins on Arduino Uno, and some tutorials are using a potentiometer to demonstrate the ADC and it's range of output which can vary from 0 to 1023 to represent 0 to 5v sensed at the analog pin.

In this tutorial, it is showing that the analog pin is reading 0.

But doesn't it mean that the 5v and the Gnd is shorted? And shorting ground and 5v is bound to cause problem, right? What I am I missing here.

Thanks!

No, a potentiometer is a fixed resistance between begin and end. The wiper just taps off somewhere in between. So if you have a 10k pot and set it to 50% you have 5k from begin to wiper and 5k from wiper to end. Set is to 75% you have 7k5 from begin to wiper and 2k5 from wiper to end. Set it to 0% and you have 0Ω between begin and wiper and 10k between wiper and end. Aka, begin to end stays 10k all the time.

Btw, the website you like to contains the error made by a lot of people. The correct way to calculate the voltage is NOT to divide it by 1023 but by 1024. See https://www.gammon.com.au/forum/?id=12779&reply=1#reply1

There is another (more accurate) way of drawing a schematic for a pot. That "better" schematic shows that the full-resistance always exists between 5V and ground... as long as it's wired correctly. :wink:

The input resistance of the Arduino is super-high so the pot adjustment doesn't affect current flow.

Post your code.

@DVDdoug @septillion Thanks!

@raschemmel As you can see from the other posts - the code is not needed to answer the question.

quazirfan:
@DVDdoug @septillion Thanks!

@raschemmel As you can see from the other posts - the code is not needed to answer the question.

But its still got a bug in it. It should be printing "analog value =", not "digital value =" :slight_smile:

raschemmel:
If it's not needed then why are you posting ?
It doesn't work and an analog input would not be printing "digital value" (for obvious reasons)
If you want our help you are supposed to cooperate. and provide whatever we request.
(it's up to us to decide whether it is relevant after we see it)

Take the time to read the original post. Follow the properly embedded link. All your questions would be answered, if you could be bothered.

@WattsThat Although it's in the link, @raschemmel is right tough. It should not be needed for us to read a lengthy tutorial to help you. This time I just scanned it because it wasn't really needed for the answer. And, like I said, that tutorial makes a basic mistake and thus is wrong :wink:

septillion:
The correct way to calculate the voltage is NOT to divide it by 1023 but by 1024.

Who cares if you use this line.

analogVoltage = (digitalValue * 5.00)/1023.00;

5.00 (assuming VCC = 5.00volt) is going to introduce more error than 1023 or 1024.
Leo..

But its still got a bug in it. It should be printing "analog value =", not "digital value ="

perhaps if you posted your code?

@Wawa I do, and I think newbies should as well, because it's simply wrong. I don't divide/multiply by 99 if I want something in percentage as well... Does not matter if it's close or not. Doing something slightly wrong without gaining anything (for example, simplicity) just makes it harder to understand want's really happening.

@wawa I must agree with @septillion;

Also if (as I would recommend) you work in mV and integers, using 1024 is a simple right shift, while /1023 is not.

Why do I have a problem with floats? Because so many people divide eg 312 * 1000 / 1023

and get 304.9853372434017595307917888563

The understanding of the limit of resolution of the ADC is lost.

I was only trying to say that in this case "5.00" could be 50 times more wrong than using 1023 or 1024.
I just don't understand that people want to see a voltage from something you can't calculate a voltage from (default Aref). Just keep it a digital value, or a ratio.

I do agree that 1024 should be used in most cases though.
Leo..

Even a float division by a power of 2 is faster than division by any other number. The reason is, the mantissa doesn't have to change. The exponent is binary, so the operation is performed by simply subtracting 10 from the exponent. Addition/subtraction is lightning fast.

I don't know if the compiler is really doing that optimization but it certainly should, especially for constant values.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.