Arduino — ADC

The Analog to Digital converter in the Arduino Uno is a very useful feature that converts an analog voltage into digital and gives it to the microcontroller. By converting the analog value to digital ones, we can start using electronics to interface to the analog world around us. For example, when we interface sensors or need to integrate biometric applications — the output of the sensor is most of the time analog in nature, but the microcontroller processes digital signals. So, for such scenarios, we use ADC that acts as a mediator between the sensor and microcontroller.

ADC in Arduino Uno

The Arduino Uno has 6 onboard ADC channels which can be used to read analog signals in the 0–5 V range. It has a 10 bit ADC, which implies that it’ll give a digital value in the range of 0–1023 (2¹⁰). This is called the resolution, which indicates the number of discrete values it can produce over the range of analog values.

Digital Output calculation

ADC Resolution = Vref/((2^n)-1)

Digital Output = Vin/Resolution

Where, Vref — The reference voltage is the maximum value that the ADC can convert and 2^n stands for the n-bit ADC (in this case 10).

For example, if the Vref is 5V, and Vin is 5V the Digital O/P value = 1023(10 bit)

Arduino ADC functions

analogRead (pin)This function is used to read the analog values from the specified analog pin and returns the corresponding digital values.

analogReference (type) — This is used for configuring the reference voltage used for analog input.

Now that we’re familiar with the ADC functionalities, let’s get started with a simple program that’ll help us understand the concept better. We’ll write a simple sketch to read varying analog values that are generated using a potentiometer when connected to the A0 analog channel. The digital values which we obtain from the Arduino ADC will be displayed on the serial monitor.

Connect the potentiometer in the following manner:

Once you’ve made the above connections, upload the following sketch in the IDE.

Compile and upload the code on the Arduino IDE. Once the code gets uploaded, slowly turn the potentiometer, increasing the values from 0V to 5V, and then slowly decrease it back. You should be able to see the corresponding digital values in the serial monitor.

The ADC provides a digital output that is proportional to each analog value, to obtain the corresponding voltage, you can use the following formula:

Aout = digital value*(Vref/2^n-1)

In this blog, we covered the Analog to Digital converter in the Arduino Uno board, learned how to obtain the digital values from analog inputs, and tried out a simple example with a potentiometer. Now you can easily use any sensor or application that consists of analog outputs and get the respective digital values.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store