analogReference()
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:
Arduino AVR Boards (Uno, Mega, etc.)
DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
INTERNAL1V1: a built-in 1.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
Arduino SAMD Boards (Zero, etc.)
AR_DEFAULT: the default analog reference of 3.3V
AR_INTERNAL: a built-in 2.23V reference
AR_INTERNAL1V0: a built-in 1.0V reference
AR_INTERNAL1V65: a built-in 1.65V reference
AR_INTERNAL2V23: a built-in 2.23V reference
AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference
Arduino SAM Boards (Due)
AR_DEFAULT: the default analog reference of 3.3V. This is the only supported option for the Due.
Syntax
Parameters
type : which type of reference to use (see list of options in the description).
Returns
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 5V 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 5K 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 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) =
analogReference()
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:
Arduino AVR Boards (Uno, Mega, Leonardo, etc.)
DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V 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.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
Arduino SAMD Boards (Zero, etc.)
AR_DEFAULT: the default analog reference of 3.3V
AR_INTERNAL: a built-in 2.23V reference
AR_INTERNAL1V0: a built-in 1.0V reference
AR_INTERNAL1V65: a built-in 1.65V reference
AR_INTERNAL2V23: a built-in 2.23V reference
AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference
Arduino megaAVR Boards (Uno WiFi Rev2)
DEFAULT: a built-in 0.55V reference
INTERNAL: a built-in 0.55V reference
VDD: Vdd of the ATmega4809. 5V on the Uno WiFi Rev2
INTERNAL0V55: a built-in 0.55V reference
INTERNAL1V1: a built-in 1.1V reference
INTERNAL1V5: a built-in 1.5V reference
INTERNAL2V5: a built-in 2.5V reference
INTERNAL4V3: a built-in 4.3V reference
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference
Arduino SAM Boards (Due)
AR_DEFAULT: the default analog reference of 3.3V. 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 V reference
AR_INTERNAL: built-in 0.6 V reference
AR_INTERNAL1V2: 1.2 V reference (internal 0.6 V reference with 2x gain)
AR_INTERNAL2V4: 2.4 V reference (internal 0.6 V reference with 4x gain)
Syntax
Parameters
type : which type of reference to use (see list of options in the description).
Returns
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 5V 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 5K 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 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) =
Функция analogReference() в Arduino IDE
С помощью функции настраивается один из важнейших параметров, определяющих точность измерения АЦП – источник опорного напряжения.
Величина опорного напряжения принимается за 100% (1023) и все значения рассчитываются относительно этого опорного напряжения.
Возможные источники опорного напряжения (ИОН):
- DEFAULT – стандартное значение, равное величине напряжения питания (5В для плат, рассчитанных на работу от 16МГц и 3.3В для плат, работающих на частоте 8МГц).
- INTERNAL – встроенный (не очень точный) ИОН. Выдаёт 1.1В на платах с микроконтроллерами ATMega328 и ATMega168, 2.56В на платах с ATMega8 (Arduino NG).
- INTERNAL1V1 – встроенный ИОН на 1.1В (только Arduino Mega, так как имеет внутри два ИОН).
- INTERNAL2V56 – встроенный ИОН на 2.56В (только Arduino Mega).
- EXTERNAL – внешний ИОН, позволяющий многократно повысить точность измерений.
Синтаксис
Аргументы
CVStype – тип источника опорного напряжения (CVS – ConstantVoltageSupply)
Возвращаемое значение
Замечания
В случае использования внешнего ИОН, рекомендуется подключать его через сопротивление в 5 Ком. В противном случае возможно повреждение микроконтроллера из-за разницы потенциалов.
Единственный минус подключения – напряжение будет немного просаживаться, так как внутри контроллера уже установлено сопротивление. Однако такое подключение позволит «на лету» менять ИОН со внешнего на внутренний и обратно.
Теория использования ИОН
Напряжение ИОН используется в микроконтроллерах как верхняя точка измерения АЦП. В продвинутых внешних АЦП, кроме положительной верхней границы, существует напряжение нижней границы (в старших сериях AVR оно тоже есть – AGND, Analog ground). Остальные поступающие на вход АЦП значения рассчитываются пропорционально относительно верхних точек.
К примеру, если подать на вход АЦП 2.5В при ИОН = 2.56В, то на выходе получим
1000, а если ИОН = 5В, то значение преобразования АЦП будет равно
По умолчанию вывод AREF не используется, а напряжение верхней точки берётся относительно аналогового питания, при этом AREF находится в низкоимпедансном состоянии и не терпит напряжений на входе.
При выборе внутреннего ИОН значения АЦП считаются, опираясь на напряжение, меньшее чем напряжение питания. В таком случае, любое напряжение, поступившее на вход АЦП, значение которого будет больше, чем напряжение ИОН, будет восприниматься как максимальное (1023).
Значение внутреннего ИОН также будет выведено на вывод AREF. Его возможно измерить лишь мультиметром с сопротивлением, близким к бесконечности, так как характер подключения – высокоимпедансный. Опять же, рекомендуем подключать внешний ИОН через сопротивление, чтобы ненароком не уничтожить аналоговую часть микроконтроллера.
В любом случае, самым оптимальным решением будет использование внешнего источника опорного напряжения, выполненного на специализированной микросхеме.
Не стоит забывать и про необходимость правильно разводить печатную плату под устройство с учётом всех экранов и соединять аналоговую и цифровую земли лишь в одной точке. Не помешают и фильтры по питанию… но это уже отдельная тема, выходящая за рамки статьи.
analogReference()
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:
Arduino AVR Boards (Uno, Mega, Leonardo, etc.)
DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V 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.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
Arduino SAMD Boards (Zero, etc.)
AR_DEFAULT: the default analog reference of 3.3V
AR_INTERNAL: a built-in 2.23V reference
AR_INTERNAL1V0: a built-in 1.0V reference
AR_INTERNAL1V65: a built-in 1.65V reference
AR_INTERNAL2V23: a built-in 2.23V reference
AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference
Arduino megaAVR Boards (Uno WiFi Rev2)
DEFAULT: a built-in 0.55V reference
INTERNAL: a built-in 0.55V reference
VDD: Vdd of the ATmega4809. 5V on the Uno WiFi Rev2
INTERNAL0V55: a built-in 0.55V reference
INTERNAL1V1: a built-in 1.1V reference
INTERNAL1V5: a built-in 1.5V reference
INTERNAL2V5: a built-in 2.5V reference
INTERNAL4V3: a built-in 4.3V reference
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference
Arduino SAM Boards (Due)
AR_DEFAULT: the default analog reference of 3.3V. 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 V reference
AR_INTERNAL: built-in 0.6 V reference
AR_INTERNAL1V2: 1.2 V reference (internal 0.6 V reference with 2x gain)
AR_INTERNAL2V4: 2.4 V reference (internal 0.6 V reference with 4x gain)
Syntax
Parameters
type : which type of reference to use (see list of options in the description).
Returns
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 5V 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 5K 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 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) =
analogReference()
Description
Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are:
Arduino AVR Boards (Uno, Mega, Leonardo, etc.)
DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V 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.1V reference (Arduino Mega only)
INTERNAL2V56: a built-in 2.56V reference (Arduino Mega only)
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
Arduino SAMD Boards (Zero, etc.)
AR_DEFAULT: the default analog reference of 3.3V
AR_INTERNAL: a built-in 2.23V reference
AR_INTERNAL1V0: a built-in 1.0V reference
AR_INTERNAL1V65: a built-in 1.65V reference
AR_INTERNAL2V23: a built-in 2.23V reference
AR_EXTERNAL: the voltage applied to the AREF pin is used as the reference
Arduino megaAVR Boards (Uno WiFi Rev2)
DEFAULT: a built-in 0.55V reference
INTERNAL: a built-in 0.55V reference
VDD: Vdd of the ATmega4809. 5V on the Uno WiFi Rev2
INTERNAL0V55: a built-in 0.55V reference
INTERNAL1V1: a built-in 1.1V reference
INTERNAL1V5: a built-in 1.5V reference
INTERNAL2V5: a built-in 2.5V reference
INTERNAL4V3: a built-in 4.3V reference
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference
Arduino SAM Boards (Due)
AR_DEFAULT: the default analog reference of 3.3V. 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 V reference
AR_INTERNAL: built-in 0.6 V reference
AR_INTERNAL1V2: 1.2 V reference (internal 0.6 V reference with 2x gain)
AR_INTERNAL2V4: 2.4 V reference (internal 0.6 V reference with 4x gain)
Syntax
Parameters
type : which type of reference to use (see list of options in the description).
Returns
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 5V 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 5K 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 32K resistor on the AREF pin. The two act as a voltage divider, so, for example, 2.5V applied through the resistor will yield 2.5 * 32 / (32 + 5) =