What is an Analog Value?

Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a binary 0 and a five volts (5V) as a binary 1.But what if the signal is 2.72V? Is that a zero or a one? We often need to measure signals that vary; these are called analog signals. A 5V analog sensor may output 0.01V or 4.99V or anything in between.

Luckily, nearly all microcontrollers have a device built into them that allows us to convert these voltages into values that we can use in a program to make a decision.But for processing and for purpose of microcontroller processes only digital values in th binary form is understood ,hence it is important to convert analog to digital form using ADC.

What is ADC?

ADC short for Analogue to Digital Converter. It is the process of conversion of values/readings from analog to digital form and the steps included in ADC mainly consists of ,

Sampling and Holding

In the process of Sample and hold (S/H), the continuous signal will gets sampled and freeze (hold) the value at a steady level for the particular least period of time. It is done to remove variations in input signal which can alter the conversion process and thereby increases the accuracy. The minimum sampling rate has to be two times the maximum data frequency of the input signal.(2fs>=fi).

Quantizing and Encoding

Quantizing: It is the process in which the reference signal is partitioned into several discrete quanta and then the input signal is matched with the correct quantum.

Encoding: For each quantum, a unique digital code will be assigned and after that the input signal is allocated with this digital code.

ADC and Analog Values in Arduino Uno

Not every pin on a microcontroller has the ability to do analog to digital conversions. On the Arduino board, these pins have an ‘A’ in front of their label (A0 through A5) to indicate these pins can read analog voltages.So the analog pins in Arduino Uno are- A0,A1,A2,A3,A4,A5.

ADCs can vary greatly between microcontroller. The ADC on the Arduino is a 10-bit ADC meaning it has the ability to detect 1,024 (2^10) discrete analog levels. Some microcontrollers have 8-bit ADCs (2^8 = 256 discrete levels) and some have 16-bit ADCs (2^16 = 65,536 discrete levels).In the arduino uno the analog value detected will lie between 0 and 1023 because arduino uno is a 10 bit decoder.( Let the bit number be “n” upper limit – 2^n= 1023). Other boards will have different ranges depending on the bit number.

One of the most common technique used in ADC is to charge up an internal capacitor and then measure the time it takes to discharge across an internal resistor. The microcontroller monitors the number of clock cycles that pass before the capacitor is discharged. This number of cycles is the number that is returned once the ADC is complete.

Syntax

analogRead(pin)// pin

Parameters

pin: the name of the analog input pin to read from (A0 to A5 on arduino uno boards, A0 to A6 on MKR boards, A0 to A7 on the Mini and Nano, A0 to A15 on the Mega).

Returns

pin: the name of the analog input pin to read from (A0 to A5 on arduino uno , A0 to A6 on MKR boards, A0 to A7 on the Mini and Nano, A0 to A15 on the Mega).

Reading Analog Values with Ardunio Uno

Let’s use the Arduino Uno to detect an analog voltage. Use a potentiometer/voltage divider, or light sensor, or simple voltage divider  to create a voltage. Let’s setup a simple trimpot circuit for this example:

Circuit Diagram
Circuit Diagram

Example Code

Using the below code snippet you can see in realtime the variation in analog values depending on the input given either manually in the case of a potentiometer or values detected from a sensor.

pinMode(A3, INPUT); //Pin initialization of A3 as “input pin”

int x = analogRead(A3); //Reads the analog value on pin A3 and stores into x.

Serial.print(“Analog value: “);// to simply print the string “Analog value”
Serial.println(x);// print the analog value received.

Notes and Warnings

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.).

Conclusion

The above mentioned in just a basic understanding and introduction to analog values,their application in the word of electronics and reading of analog values using an arduino uno. To view a project related to an application using a combination of analog and pulse width modulated signals click here or go to the below article.

Author

Write A Comment