Where I describe the function - analogRead().
Introduction#
The function analogRead() is similar to digitalRead(), in the sense, it takes a pin number as a parameter and returns the pin’s value. In the case of analogRead, the value will be a number between 0 and 1024. With the range of numbers corresponding to the range of voltages on the pin, typically between 0V and 5V.
Digital vs Analog#
In the microcontroller world, there are two methods of measurement, digital and analog. The former identifies a binary value, HIGH or LOW. The latter describes a linear range of values, based on the voltage which appears on the pin and the number of bits of the analog-to-digital controller (ADC) on the microcontroller. For example, the Uno has a 10-bit ADC, which means the value may range from 0-1024. One more element defining the value is the analog reference (AREF) voltage, which defines the highest voltage, the value 1024 will represent. Typically, (and in our case) this value will be 5V. (There are ways to define it as 1.1V or to an external voltage on a specific pin.) Therefore, the range of voltages which can be returned by analogRead() are 0V to 5V, and each step is 5V/1024 or .00488V or 4.88mV.