Arduino

Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

Blog » | Forum » | Playground »

Reference Language (extended) | Libraries | Comparison | Board

## analogReference(type)

#### Description

Configures the reference voltage used for analog input. The analogRead() function will return 1023 for an input equal to the reference voltage. The options are:

- DEFAULT: the default analog reference of 5 volts.
- INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 and 2.56 volts on the ATmega8.
- EXTERNAL: the voltage applied to the AREF pin is used as the reference.

#### Parameters

type: which type of reference to use (DEFAULT, INTERNAL, or EXTERNAL).

#### Returns

None.

#### Warning

It is a good idea to connect external voltages to the AREF pin through a 5K resistor. This will prevent possible internal damage to the Atmega chip if analogReference() software settings are incompatible with the current hardware setup. Connecting external voltages through a resistor also make it possible to switch the AREF voltage on the fly, say from the 5 volt DEFAULT setting, to a 3.3 volt EXTERNAL setting (and applied voltage), without the hardware setup affecting either ADC configuration.

#### Use of the AREF pin

The voltage applied to the AREF pin directly governs the ADC and sets the voltage at which the ADC will report its highest reading, 1023. Lower voltages applied to ADC (analog) pins will be scaled proportionally, so at the DEFAULT setting (5 volt internal connection), 2.5 volts on an analog pin will report approximately 512.

The default configuration on all Arduino implementations is to have nothing connected externally to the AREF pin (Atmega pin 21). In this case the DEFAULT analogReference software setting connects the AVCC voltage, internally, to the AREF pin. This appears to be a low impedance connection (high current) and voltages, other than AVCC, applied (erroneously) to the AREF pin in the DEFAULT setting could damage the ATMEGA chip. For this reason, connecting external voltages to the AREF pin through a 5K resistor is a good idea.

The AREF pin may also be connected internally to an (internal) 1.1 volt source with analogReference(INTERNAL). With this setting voltages applied to the ADC (analog) pins that are 1.1 volts (or higher) will report 1023, when read with analogRead. Lower voltages will report proportional values, so .55 volts will report about 512.

The connection between the 1.1 volt source and the AREF pin is a very high impedance (low current) connection, so that reading the 1.1 (internally supplied) voltage at the AREF pin may only be done with a more expensive, high-impedance multimeter. An external voltage applied (erroneously) to AREF pin while using the INTERNAL setting will not damage the chip, but will totally override the 1.1 volt source, and ADC readings will be governed by the external voltage. It is still desirable to connect any external voltage to the AREF pin however, through a 5K resistor to avoid the problem cited above.

The correct software setting for using the AREF pin with an external voltage is analogReference(EXTERNAL). This disconnects both of the internal references and the voltage applied externally to the AREF pin sets the reference voltage for the ADC.

#### See also

- Description of the analog input pins
- analogRead

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.

Edit Page | Page History | Printable View | All Recent Site Changes