# Using two references in the same ADMUX

I'm making a project and I neee to use 2 different references on the same ADMUX. One reference is 0-5V and the other is 0-2.5V. I'm aware that I can use the reference of the Arduino to the 5V sensor. But how I put a 2.5V reference while using the 5V at the same time?

• You can try to read 2.5V sensor twice, sum it and divide by two. Or you can double the input voltage by using non-inverting OP AMP with amplification factor 2. Or if you don't mind half resolution, you can use 5V reference voltage and just read it.
– KIIV
Sep 6 '16 at 5:53
• Do you really need 10-bit precision on both voltages? Sep 6 '16 at 9:08

First of all a reference is just a voltage, not a range.

If you use a reference of say 5V than your analogRead(...) calls will return a 10 bit number where 0 stands for 0V and 1023 stands for 5V.

Second, the AREF pin is there for that purpose: feed your 2.5V reference to that pin and use:

analogReference(EXTERNAL);

when you want to read using the 2.5V reference (0 stands for 0V and 1023 stands for 2.5V in this case), or

analogReference(DEFAULT);

UPDATE

Nothing can be done at the exact same time on an Arduino/ATmega328 because it has one single processing unit. In case of analog to digital conversion you can not even perform two conversions on two pins too fast because you have only one ADC which is multiplexed (shared) among all the analog pins.

You have no choice to perform one reading, wait, then perform the other reading. You can change the voltage reference between the two conversions though, but you need to ensure the internal ADC capacitor is properly discharged: if you read a 5V line and then read a 2.5V line without discharging the internal ADC you are more than probably going to always read the maximum value.

How long you will have to wait depends on the impedance of the line you are sampling: higher the impedance, longer the time you have to wait for the ADMUX capacitor to discharge/charge up (Arduino/ATmega328 ADC is a store and sample comparator).

• But how? In the ADMUX, one pin needs to be configured to 5V and other is configured to 2.5, and I need to do the conversion at the same time. And also I need the code in AVR. Sep 5 '16 at 23:29
• Are you using the ATmega328 internal ADMUX or an external component? In case it's an exaternal component, which is the EXACT part number? Sep 5 '16 at 23:44
• If you have a 2.5 V reference connected to the AREF pin, then calling analogReference(DEFAULT) will short that to +5V, possibly destroying your voltage reference or the Arduino. C.f. the warning in the documentation of analogReference(). Sep 6 '16 at 9:33