Most microcontrollers today have built-in analog to digital converters (ADC) .
Analog signals: Directly measurable quantities in terms of some other quantity
                       Some examples: 
                       Thermometer: The mercury liquid inside the thermometer rises as temperature rises 
                       Car Speedometer: Needle of a car speedometer moves farther right as you accelerate 
                       Audio Amplifier: The volume of an audio amplifier increases as you turn the knob. 
Digital Signals: Have only two states. or 1on or off. 
                       Example: A switch can be either on or off.

Figure 1: Arduino Uno Analog inputs

Not all pins of the Arduino board can be used as analog inputs, the numbers of these pins depend on the Arduino model you are using, the Arduino Uno has 6 analog inputs labelled A0, A1, A2, A3, A4 and A5 as shown on figure 1 above. 

These analog to digital converters allow analog continuous voltages to be converted into a discreet 10-bit digital numbers inside the microcontroller as the microcontroller can only process digital numbers. This basically mean the analog pins have the ability to detect 1,024 (210) discrete analog levels compared to two levels only (0 and 5V) of the digital pins. This can enable the Arduino to be connected to analog sensors such as temperature sensors, pressure sensors, humidity sensors, optical sensors, and power sensors. 

Any sensor which can generate a voltage between 0V and a maximum 5V can be used. If the output voltage is higher than 5V, a method to step it down should be used such as a voltage divider with resistors.  Figure 2 below shows a potentiometer wiper pin connected to A0 pin of the Arduino. By varying this potentiometer, the voltage across will change as well and displayed on the LCD.

Figure 2: A potentiometer and LCD on breadboard connected to Arduino Uno

                                         Arduino Analog Functions
Description: This function configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:

  • DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
  • INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
  • INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
  • INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
  • EXTERNAL: the voltage applied to the AREF pin (between 0 to 5V only any other voltage may damage your board) is used as the reference.



Description: This function reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analogReference(). It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second. This function will return a int value between 0 and 1023. If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

Arduino ADC Example

Figure 3 below shows a potentiometer wiper pin connected to A0 pin of the Arduino. By varying this potentiometer, the voltage across will change as well and displayed on the LCD.

Figure 3: potentiometer connected to A0 pin of the Arduino Uno

The potentiometer will vary the voltage from 0 to 5V, with 10 bits of resolution for Analog/Digital conversion (1024 different values to represent the voltage). Thus, the maximum value (1023: It is from 0 to 1023) will be 5V. The halfway will be 511 or 2.5V, and so forth.

In doing math with float numbers, you need to add a decimal point, otherwise it will be treated as an int. That is why we used 5.0 and not just 5.

You can download the full project files (Arduino Sketch and Proteus Schematic design) below here. All the files are zipped, you will need to unzip them (Download a free version of the Winzip utility to unzip files).

Download: Analog_sketch

Download: Arduino-Analog-Proteus