Lesson-04 ADC

Definition

ADC stands for Analog-to-Digital Converter. It is an electronic component or subsystem that converts an analog signal, such as a voltage or current, into a digital signal that can be processed by a digital system, such as a computer or microcontroller.

Analog signals are continuous and can take on any value within a range, while digital signals are discrete and can only take on specific values. ADCs are used in a wide range of applications, such as measuring physical quantities like temperature, pressure, and light, or converting analog audio signals into digital data for processing in music players or computers. The accuracy and resolution of an ADC can greatly affect the quality of the digital signal output.

ADC in Arduino

The ADC (Analog-to-Digital Converter) on an Arduino board can vary depending on the specific board model. Here are some common points about the ADCs on a few popular Arduino boards:

  1. Arduino Uno: The Uno has a 10-bit ADC, which means it can represent analog voltage levels with a resolution of 2^10 or 1024 discrete values. It has 6 analog input pins, labeled A0 to A5.
  2. Arduino Mega: The Mega has a 10-bit ADC as well, but it has 16 analog input pins, labeled A0 to A15.
  3. Arduino Due: The Due has a 12-bit ADC, which means it can represent analog voltage levels with a resolution of 2^12 or 4096 discrete values. It has 12 analog input pins, labeled A0 to A11.
  4. Arduino Nano: The Nano has a 10-bit ADC, with 8 analog input pins, labeled A0 to A7.

To read an analog voltage using the ADC on an Arduino, you would use the analogRead() function in the Arduino IDE. This function takes as an argument the analog input pin number, and returns an integer between 0 and the maximum value of the ADC (1023 for a 10-bit ADC, or 4095 for a 12-bit ADC) representing the digital approximation of the analog voltage level.

Example

here is an example of using the ADC (Analog-to-Digital Converter) on an Arduino Uno to read the voltage from a potentiometer connected to analog input pin A0:

void setup() {
  Serial.begin(9600); // initialize serial communication
}

void loop() {
  int reading = analogRead(A0); // read the voltage on analog input pin A0
  float voltage = reading * (5.0 / 1023.0); // convert the ADC value to voltage
  Serial.print("Analog Input Voltage: ");
  Serial.print(voltage); // print the voltage to the serial monitor
  Serial.println(" V");
  delay(1000); // wait for 1 second before reading again
}

Explanation

  1. The setup() function is called once when the Arduino is powered on or reset.
  2. Serial.begin(9600) initializes the serial communication between the Arduino and the computer at a baud rate of 9600 bits per second.
  3. The loop() function is called repeatedly as long as the Arduino is powered on.
  4. analogRead(A0) reads the voltage from analog input pin A0 and stores the result as an integer in the variable reading.
  5. The 5.0 / 1023.0 is a scaling factor used to convert the ADC value to voltage. The ADC on an Arduino Uno has a resolution of 10 bits, which means it can represent 2^10 (or 1024) different voltage levels. Since the voltage range of the ADC is 0-5V, each step corresponds to a voltage change of 5/1024 or 0.00488V.
  6. reading * (5.0 / 1023.0) calculates the voltage based on the ADC value.
  7. The voltage is stored as a floating-point number in the variable voltage.
  8. Serial.print("Analog Input Voltage: ") prints the string “Analog Input Voltage: ” to the serial monitor.
  9. Serial.print(voltage) prints the voltage value to the serial monitor.
  10. Serial.println(" V") prints the string ” V” to the serial monitor and moves the cursor to the next line.
  11. delay(1000) waits for 1000 milliseconds (or 1 second) before reading the voltage again.
  12. The program loops back to step 4 and repeats the process indefinitely.

Other Inbuilt Functions in Arduino For ADC

  1. analogReference(type): This function sets the reference voltage used for the ADC. The type can be DEFAULT (the default voltage reference is used), INTERNAL (the internal reference voltage of the Arduino is used), or EXTERNAL (an external reference voltage is used).
  2. analogWrite(pin, value): This function writes an analog value (between 0 and 255) to a PWM (Pulse-Width Modulation) pin. The duty cycle of the PWM signal determines the average voltage output.
  3. analogReadResolution(bits): This function sets the resolution of the ADC to the specified number of bits. The default resolution is 10 bits.
  4. analogWriteResolution(bits): This function sets the resolution of the PWM output to the specified number of bits. The default resolution is 8 bits.

These are some of the most commonly used ADC-related functions in Arduino. There are other functions and libraries available as well for more advanced usage.

    Leave a Reply

    Your email address will not be published.

    Need Help?