Go Down

### Topic: Measuring voltage, using AREF pin? (Read 3394 times)previous topic - next topic

#### evolion

##### Jan 28, 2013, 10:31 am
Heya,

When using the arduino as a voltmeter AND using the Aref pin for accuracy, what should the circuit's path look like?
~I thought I would make an inquiry before experimenting to avoid doing anything foolish.

For instance:
Say I want to measure line/signal voltage either to or from a component (similar to that carried on the third wire of a servo) and I know it is less than 5V (no resistance or division required for analog input).

I'm thinking that I would need to splice into or otherwise probe the line for a voltage to route to an analog input pin, then return (analog output pin) to the ground of that signal.

Now, what gets used as a voltage for Aref?  Would it be the +voltage (Vn) before the load/impedance from which the signal originates?  Or should the arduino use its own internal reference? is it possible for arduino to use an internal reference to measure an external voltage?
-All of these questions are basically asking: how is Aref pin properly applied to voltage measurement?

I found this and it appears to work nicely, except I don't need to measure voltage on the board.  It looks like it may be useful but first I need to figure out what the 'voltmeter' circuit should look like.
Code: [Select]
`//voltage returned in millivolts 5000 = 5V//although for Arduino it usually makes more sense to measure against Vcc, the positive power rail. //measure how large the known 1.1V reference is in comparison to Vcc, you can back-calculate what Vcc is with a little algebra.//http://code.google.com/p/tinkerit/wiki/SecretVoltmeterlong readVcc() {  long result;  // Read 1.1V reference against AVcc  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);  delay(2); // Wait for Vref to settle  ADCSRA |= _BV(ADSC); // Convert  while (bit_is_set(ADCSRA,ADSC));  result = ADCL;  result |= ADCH<<8;  result = 1126400L / result; // Back-calculate AVcc in mV  return result;}void setup() {  Serial.begin(9600);}void loop() {  Serial.println( readVcc(), DEC );  delay(1000);}`

#### MarkT

#1
##### Jan 28, 2013, 02:15 pm

Heya,

When using the arduino as a voltmeter AND using the Aref pin for accuracy, what should the circuit's path look like?
~I thought I would make an inquiry before experimenting to avoid doing anything foolish.

For instance:
Say I want to measure line/signal voltage either to or from a component (similar to that carried on the third wire of a servo) and I know it is less than 5V (no resistance or division required for analog input).

I'm thinking that I would need to splice into or otherwise probe the line for a voltage to route to an analog input pin, then return (analog output pin) to the ground of that signal.

Now, what gets used as a voltage for Aref?  Would it be the +voltage (Vn) before the load/impedance from which the signal originates?  Or should the arduino use its own internal reference? is it possible for arduino to use an internal reference to measure an external voltage?
-All of these questions are basically asking: how is Aref pin properly applied to voltage measurement?

Typically you would:

1) Call analogReference(EXTERNAL) in setup() - very important to avoid burning out the chip...
2) Connect the external voltage reference to GND and AREF - these wires shouldn't be carry any significant current, note.

The ADC outputs are then ratiometric (you don't care about absolute voltages, only the ratio between signal and AREF voltages).

So if you have a circuit where AREF is being driven from a voltage below the supply you must never upload a sketch that
calls analogRead() without calling analogReference(EXTERNAL) - otherwise you'll push a lot of current through a single
FET on the chip and may damage it.  The first call to analogRead() by default will turn on this FET that connects Vcc to AREF,
unless you setup the analog reference as external.

You can add a 1k resistor between your reference voltage and AREF to protect against this failure mode, but you will lose
accuracy...

The other important caveat is to be very sure that the external reference to AREF can never exceed the Arduino supply by 0.5V
(say you power down the Arduino while that reference is still connected....).  Adding a schottky diode between AREF and
Vcc can be a wise precaution (worst case the external supply will power the Arduino as well).
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### evolion

#2
##### Jan 28, 2013, 06:31 pm
Thank you very much for the pointers and advice.  It's exactly what I was looking for to get started.

I'm sure I will have more questions in the near future.  This will end up being a fairly involved project dealing with sensor manipulation of my vehicle where I'm going to try to make otherwise impossible adjustments to the fuel injection system.

I just found this and it looks like what I need to begin
Code: [Select]
`/*Example 22.1  Measuring range of analogRead() using a 1.8V AREF voltage  tronixstuff.com/tutorials  CC by-sa-nc*/int analoginput = 0; // our analog pinint analogamount = 0; // stores incoming valuefloat percentage = 0; // used to store our percentage valuefloat voltage =0; // used to store voltage valuevoid setup(){  Serial.begin(9600); analogReference(EXTERNAL); // use AREF for reference voltage}void loop(){  delay(200);analogamount=analogRead(analoginput);percentage=(analogamount/1024)*100;voltage=analogamount*1.75; // in millivolts  Serial.print("Percentage of AREF: ");  Serial.println(percentage,2);  Serial.print("voltage on analog input (mV): ");  Serial.println(voltage,2);}`

I'll be back after I've done some experimenting/testing

Thanx!

#### evolion

#3
##### Jan 31, 2013, 07:41 am
So I built a simple pulse generator using a 555 chip to run some tests with before I start cutting wires on my ride.  I'm having trouble getting an accurate voltage reading because of the pulse effect.  I wouldn't be too worried about it except I'm having to power the circuit at 6.5V (I don't have an easy 5Vcc source and the next increment on the supply is 4.5V where the 555 doesn't like to operate correctly).  I think there should be enough of a voltage drop through the generator before Vout but it would be nice to verify it before connecting it to the arduino.

MarkT:

I think I will need as much accuracy as possible.  1/10th Volt will be more than a significant difference in the return signal to the PCM (powertrain control module, aka ECM).  Do you think diodes can be used to accurately drop voltage before Aref?

When you refer to 'Vcc', is this to Vin on the arduino for power?  If the answer is yes, is the forward direction of the diode from Vcc to Aref?  and then, Does it need to be a Shottky?  I may have one but I'm not sure I'd be able to distinguish them from others.

Is it a good idea, or even possible, to use the arduino supply voltage as the reference to Aref as well?
The sensor supply should be at 5V, I'm thinking I could parallel the arduino with it and also use it as the reference since the PCM is most likely measuring the sensor's return signal against this same supply voltage as well. (the PCM supplies all of the sensors with 5Vn)

Seems like a good idea to me but I don't know that my thinking is correct

Thanx

Go Up

Please enter a valid email to subscribe