Description
Configures the reference voltage used for analog input (i.e. the maximum voltage that can be sensed). The options are:
Arduino AVR Boards (UNO, Mega, Leonardo, etc.)
- DEFAULT: the default analog reference of 5 volts (on 5 VDC Arduino boards) or 3.3 volts (on 3.3 VDC Arduino boards).
- INTERNAL: a built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega32U4 and ATmega8 (not available on the Arduino Mega).
- INTERNAL1V1: a built-in 1.1 VDC reference (Arduino Mega only).
- INTERNAL2V56: a built-in 2.56 VDC reference (Arduino Mega only).
- EXTERNAL: the voltage applied to the AREF pin (0 to 5 VDC only) is used as the reference.
Arduino Renesas Boards (UNO R4, Portenta C33)
- AR_DEFAULT: the default analog reference of 5 volts.
- AR_INTERNAL: a built-in reference, equal to 1.5 Volts on the RA4M1 of the UNO R4.
- AR_INTERNAL_1_5V: a built-in reference, equal to 1.5 VDC on the R7FA6M5 of the Portenta C33.
- AR_INTERNAL_2_0V: a built-in reference, equal to 2.0 VDC on the R7FA6M5 of the Portenta C33.
- AR_INTERNAL_2_5V: a built-in reference, equal to 2.5 VDC on the R7FA6M5 of the Portenta C33.
- AR_EXTERNAL: the voltage applied to the AREF pin (0 to 5 VDC only) is used as the reference.
Arduino SAMD Boards (Zero, etc.)
- AR_DEFAULT: the default analog reference of 3.3 VDC.
- AR_INTERNAL: a built-in 2.23 VDC reference.
- AR_INTERNAL1V0: a built-in 1.0 VDC reference.
- AR_INTERNAL1V65: a built-in 1.65 VDC reference
- AR_INTERNAL2V23: a built-in 2.23 VDC reference
- AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference
Arduino megaAVR Boards (UNO WiFi Rev2, Arduino Nano Every)
- DEFAULT: a built-in 0.55 VDC reference
- INTERNAL: a built-in 0.55 VDC reference
- VDD: Vdd of the ATmega4809. 5 VDC on the Uno WiFi Rev2 and Nano Every
- INTERNAL0V55: a built-in 0.55 VDC reference
- INTERNAL1V1: a built-in 1.1 VDC reference
- INTERNAL1V5: a built-in 1.5 VDC reference
- INTERNAL2V5: a built-in 2.5 VDC reference
- INTERNAL4V3: a built-in 4.3 VDC reference
- EXTERNAL: the voltage applied to the AREF pin (0 to 5 VDC only) is used as the reference
Arduino SAM Boards (Due)
- AR_DEFAULT: the default analog reference of 3.3 VDC. This is the only supported option for the Due.
Arduino Mbed OS Nano Boards (Nano 33 BLE), Arduino Mbed OS Edge Boards (Edge Control)
- AR_VDD: the default 3.3 VDC reference
- AR_INTERNAL: built-in 0.6 VDC reference
- AR_INTERNAL1V2: 1.2 VDC reference (internal 0.6 VDC reference with 2x gain)
- AR_INTERNAL2V4: 2.4 VDC reference (internal 0.6 VDC reference with 4x gain)
The Nicla Sense ME and Nicla Voice analog reference is fixed to 1.8 VDC and can not be configured by software.
Syntax
Use the following function to change the voltage reference for analog inputs in supported boards:
analogReference(type)
Parameters
The function supports the following parameter:
type: which type of reference to use (see list of options in the description).
Returns
This function returns nothing.
Notes and Warnings
After changing the analog reference, the first few readings from analogRead() may not be accurate.
Don’t use anything less than 0V or more than 5 VDC for external reference voltage on the AREF pin! If you’re using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead().
Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.
Alternatively, you can connect the external reference voltage to the AREF pin through a 5 K resistor, allowing you to switch between external and internal reference voltages. Note that the resistor will alter the voltage that gets used as the reference because there is an internal 32 K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5 VDC applied through the resistor will yield 2.5 * 32 / (32 + 5) = ~2.2 VDC at the AREF pin.
See also