Arduino

What is AREF in Arduino

Arduino is an electronic board that can take both analog and digital inputs. Arduino has multiple input output pins out of which six analog pins are used to read analog data. Arduino cannot directly read analog data, so a 10-bit built-in ADC (Analog to Digital Converter) is used. To convert analog values to digital Arduino by default uses a 5V reference voltage. Arduino also have AREF pins which can use external voltage as a reference also. Let’s discuss analog reference in detail.

What Is AREF

AREF stands for “Analog Reference” and it is the reference voltage for the Arduino microcontroller Analog to Digital converter (ADC). The reference voltage inside Arduino VREF, indicates the maximum conversion value possible in a microcontroller. Arduino has a 10-bit ADC which means it can divide analog values into 1024 readings ranging from 0 to 1023. Arduino by default VREF is 5V however it’s possible to integrate an external reference voltage using the Arduino AREF pin.

Boards Analog Pins Max Resolution of ADC
Uno A0 to A5 10 bits
Mini, Nano A0 to A7 10 bits
Mega A0 to A14 10 bits

analogReference()

The analogReference() function in Arduino programming helps to set up reference voltage for Arduino microcontroller internal ADC. Arduino ADC takes input voltage between two limits and converts them into numbers. This number is defined by the number of bits required to represent it.

For example, in Arduino Uno (Atmega328p), that number is 10-bit starting from 0 to 1023 representing a total value of 1024. So, the upper limit an ADC can measure in volts is equal to Reference Voltage. By default, Arduino uses Vcc input voltage as analogReference(), that can be either 5V or 3.3V in most of the Arduino boards.

Let’s do some calculation to clear this further:

  • Applying 0.0V into an Arduino analog input pin where reference voltage is 5V Arduino will give 0x0000 (0 in Decimal) from the ADC.
  • Applying 5V into an Arduino analog input pin where reference voltage is 5V Arduino will give 0x03FF (1023 in Decimal) from the ADC.

Note: While using Arduino with 3.3V Vcc don’t apply more than Vcc at analog input it will damage the Arduino microcontroller chip, because you have applied more than the reference voltage that is 3.3V.

analogReference(type)

analogReference(type) in Arduino configures what type of voltage we want to set as reference. Normally by default Arduino uses 5V as analog reference, however using this function we can also configure an external reference. The analogRead() will return 1023 when input at analog pins becomes equal to the set reference voltage.

Three different ways to configure AREF are:

  1. DEFAULT: The Default AREF is 5 volts.
  2. INTERNAL: This is a built-in reference voltage, which is equal to 1.1volts and 2.56 volts on ATmega168 and ATmega8 respectively. To know further about other microcontrollers AREF voltages, click here.
  3. EXTERNAL: Voltage at AREF pin applied externally.

Parameters
Type of AREF we want to use is defined here. type: (DEFAULT, INTERNAL, or EXTERNAL).

How to Use External AREF

Using the AREF pin just beneath the ICSP connectors in the Arduino board we can set an external reference voltage for ADC. External reference voltage can come from a regulated power supply or Arduino 3.3V pin is also a good source for AREF voltage.

While using Arduino AREF with external voltage supply make sure to connect Arduino GND with external power supply GND Or if you’re using Arduino 3.3V as AREF voltage connect both with help of jumper wire.

Write following command in void setup() to activate external AREF:

analogReference(EXTERNAL);

This command will set any voltage connected at AREF pins as a reference.

Note: While using external voltage as reference make sure to set AREF as EXTERNAL before calling analogRead() otherwise it will short the active internal reference and the AREF pin, which may result in damaging the Arduino microcontroller.

To set the AREF back to original use the command below:

analogReference(DEFAULT);

How to Use Internal AREF

Arduino microcontroller have also an internal reference voltage of 1.1V. To activate the internal AREF type following command in void setup():

analogReference(INTERNAL);

For Arduino Mega boards:

analogReference(INTERNAL1V1);

Arduino Mega has another 2.56V reference voltage available. To activate type command written below:

analogReference(INTERNAL2V56);

Once the analogReference() is set make sure to calibrate reading using a good ammeter to avoid any error.

Conclusion

Arduino can measure analog signals using internal ADC. Arduino ADCs have a reference voltage of 5V however because of Arduino flexibility in reading analog input one can use an external voltage reference for ADC. Here we covered three ways of configuring Arduino AREF. Using these three ways we can enhance Arduino functionality to read exact analog data.

About the author

Kashif

I am an Electrical Engineer. I love to write about electronics. I am passionate about writing and sharing new ideas related to emerging technologies in the field of electronics.