AnalogReadSerial
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
I was reading about some code and the author talked about the "AnalogRead() Method" With a potentiometer hooked up like the above description, the author got a range of 0 to 1,023. I need to ask a really stupid question. What is the 1,023? I know it is not ohms, voltage, or current. Is it bits? Sorry for the really dumb question.
I am new to Arduino and programming. In Tools, will the serial port read the range of the potentiometer without listing any code, or do you need to put in code?
It is a number that is proportional to the ratio between the input voltage and the reference voltage.
Each count represents 1/1024th of the interval between 0 V and the reference voltage minus one count.
Thus, zero represents zero volts, and 1023 approximates 5V minus 5V/1024 (for a reference voltage of 5V. Which it almost never is)
There will now be a long discussion about whether it is 1023 or 1024.
I'll get popcorn
The math is VCC/1024. The output is 0-1023. Drops mic
Right.... It is reading voltage, but the units are not "Volts".
With the default 5V reference, 5V will read 1023 and 2.5V will read ~512, etc.
The pot, when connected to 5VDC is working as a variable [u]Voltage Divider[/u].
The analog-to-digital converter in the chip is 10-bits and 1023 is a decimal value that represents the maximum you can "count to" with 10 binary bits (digits):
0000000000 binary = 0 decimal
0000000001 binary = 1 decimal
0000000010 binary = 2 decimal
0000000011 binary = 3 decimal
0000000100 binary = 4 decimal
...11 1111 1111 binary = 1023 decimal