background preloader

Rhl_b

Facebook Twitter

AnalogReference. Reference Language | Libraries | Comparison | Changes Description Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). The options are: 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 ATmega328 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.

Parameters type: which type of reference to use (DEFAULT, INTERNAL, INTERNAL1V1, INTERNAL2V56, or EXTERNAL). Returns None. Note After changing the analog reference, the first few readings from analogRead() may not be accurate. Warning Don't use anything less than 0V or more than 5V for external reference voltage on the AREF pin! See also Reference Home.

Tutorial: Arduino and the AREF pin - Birds on the Wire. Welcome back fellow arduidans! Today we are going to spend some time with the AREF pin - what it is, how it works and why you may want to use it. First of all, here it is on our boards: Uno/TwentyTen AREF [Please read whole article before working with your hardware] In chapter one of this series we used the analogRead() function to measure a voltage that fell between zero and five volts DC. But why is the result a value between 0~1023? We measure resolution in the terms of the number of bits of resolution. It is easier to imagine this with the following image: So with our example ADC with 2-bit resolution, it can only represent the voltage with four possible resulting values. With our Arduino's ADC range of 0~1023 - we have 1024 possible values - or 2 to the power of 10.

However - not all Arduino boards are created equally. What if we want to measure voltages between 0 and 2, or 0 and 4.6? And therein lies the reason for the AREF pin! So how do we tell our Arduinos to use AREF? Using the aref pin.. Hi the really technical answer to this is in the Atmega datasheet, pages 205-206. If you look through the associated Arduino C files, you wil probably find the statement that configures the Atemga8 for an internal reference... then you can change it however you like. Look for "ADMUX" in the C code.

The software side of things is really not my strong point, but looking in wiring.c I see the following lines, which seem to match what is stated in the manual. // set a2d reference to AVCC (5 volts) cbi(ADMUX, REFS1); sbi(ADMUX, REFS0); and here is the manual-- look at the last part, table 74. ADC Multiplexer Selection Register – ADMUX ADC Multiplexer Selection Bit 7 6 5 4 3 2 1 0 REFS1 REFS0 ADLAR – MUX3 MUX2 MUX1 MUX0 ADMUX Read/Write R/W R/W R/W R R/W R/W R/W R/W Initial Value 0 0 0 0 0 0 0 0 • Bit 7:6 – REFS1:0: Reference Selection Bits These bits select the voltage reference for the ADC, as shown in Table 74. Table 74. How to convert analogRead value from accelerometer.