AREF pin setup

I have a quick question for those "in the know" :stuck_out_tongue:

I don't know that total project details are needed, but feel free to ask whatever questions you may have for me :slight_smile: What I'm wondering is - I'm thinking about using the AREF pin on my Mega 2560 because I have an external 5v power board (Pololu Step-Down Voltage Regulator D15V70F5S3) that I'm using to power all of my 5v sensors. However, the power board is outputting 5.04 volts. I'm curious if that is close enough to the tolerances of the AREF pin to not screw things up? The Arduino itself is powered by a separate dedicated 7.1 volt power supply via the barrel connector, and all 4 of my power boards (3v3, 5v, 7v1, and 12v) share a common ground.

This is what I was looking at:

EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.

Is there anything else that I need to be aware of with the potential use of this setup? (The reason for looking at the external AREF is I'm trying to narrow down some small variations in the readings of some of my analog sensors (two TMP36, three voltage dividers, and an ACS711 current sensor.) Doing the double-read with a 10ms delay in between the readings definitely helped, but there's still some oddity there occasionally.)

(deleted)

Awesome, thanks much! I shouldn't have to worry about exceeding that; if I do, I have a feeling a lot of magic smoke will be released :slight_smile:

The other caution you should consider is if your external +5vdc sensor power is ever active but the arduino supply is turned off it's possible damage could result from high ref pin current.

If the Arduino gets no power, and the external power supply is 5.04, current will flow into the AREF pin. A protection resistor of about 4k7 would be nice.
Can you power the Arduino with the external power supply ? In that case, you can use the DEFAULT voltage reference.

(while I was typing this, retrolefty wrote the same)

Cool, thanks guys!

That's definitely a good thing to be aware of; since the arduino is on a different power supply than the rest of the system. I'm already isolating my Beaglebone Black's serial lines from the Arduino using a tri-state buffer to make sure that the BBB doesn't get a serial signal when it's powered off; would the 4k7 resistor be sufficient to protect the arduino, or should I try to do something similar with the AREF connection on the arduino that I am with the BBB? If so, I'm assuming that I'd just stick the 4k7 resistor inline with the AREF feed?

Out of curiosity, will it work to power the arduino with 5v through the barrel connector? I'd read that it was possible, but could have some less-than-desirable results. So that's why I was using a separate 7v supply. Or would I just need to supply 5v directly through the power pins, bypassing the internal regulator?

On an aside, I'm still getting some weird readings from the TMP36's. I could understand the values being a bit off before because the sensors were getting 5.07 volts, but the AREF pin on the arduino was delivering 4.97v., so there was almost a 0.1v difference between the two. I'd hoped that using the AREF would eliminate that, but I know that at least the outside temperature sensor isn't accurate all the time; earlier this morning it was saying that it was 50 degrees outside when it was closer to 70. Any thoughts about how I could get this to be more accurate?

A list of the last outputs of all of my analog sensors:

Sensor Value Location Last Refreshed
Battery Amperage -0.15A Basement 2014-07-08 08:54:00
Battery Voltage 13.52VDC Basement 2014-07-08 08:54:00
System Voltage 13.60VDC Basement 2014-07-08 08:54:00
Utility Voltage 122.12VAC Basement 2014-07-08 08:54:00
Outside Temp 50.21° Outside 2014-07-08 08:54:00

The last few hours' of readings:

+-----------+------------+-------------+---------------------+
| sensorNum | sensorType | sensorValue | timestamp           |
+-----------+------------+-------------+---------------------+
|         5 | 3          |       77.48 | 2014-07-08 05:54:00 |
|         5 | 3          |       66.05 | 2014-07-08 06:04:00 |
|         5 | 3          |       64.29 | 2014-07-08 06:14:00 |
|         5 | 3          |       67.81 | 2014-07-08 06:24:00 |
|         5 | 3          |       63.41 | 2014-07-08 06:34:00 |
|         5 | 3          |       64.29 | 2014-07-08 06:44:00 |
|         5 | 3          |       62.53 | 2014-07-08 06:54:00 |
|         5 | 3          |       65.17 | 2014-07-08 07:04:00 |
|         5 | 3          |       77.48 | 2014-07-08 07:14:00 |
|         5 | 3          |       75.72 | 2014-07-08 07:24:00 |
|         5 | 3          |       65.17 | 2014-07-08 07:34:00 |
|         5 | 3          |       65.17 | 2014-07-08 07:44:00 |
|         5 | 3          |       57.25 | 2014-07-08 07:54:00 |
|         5 | 3          |       66.93 | 2014-07-08 08:04:00 |
|         5 | 3          |       71.33 | 2014-07-08 08:14:00 |
|         5 | 3          |       66.93 | 2014-07-08 08:24:00 |
|         5 | 3          |       63.41 | 2014-07-08 08:34:00 |
|         5 | 3          |       66.05 | 2014-07-08 08:44:00 |
|         5 | 3          |       63.41 | 2014-07-08 08:54:00 |
|         5 | 3          |       66.05 | 2014-07-08 09:04:00 |
|         5 | 3          |       64.29 | 2014-07-08 09:14:00 |
|         5 | 3          |       73.09 | 2014-07-08 09:24:00 |
|         5 | 3          |       65.17 | 2014-07-08 09:34:00 |
|         5 | 3          |       69.57 | 2014-07-08 09:44:00 |
|         5 | 3          |       63.41 | 2014-07-08 09:54:00 |
|         5 | 3          |       62.53 | 2014-07-08 10:04:00 |
|         5 | 3          |       64.29 | 2014-07-08 10:14:00 |
|         5 | 3          |       50.21 | 2014-07-08 10:24:00 |
|         5 | 3          |       62.53 | 2014-07-08 10:34:00 |
|         5 | 3          |       51.09 | 2014-07-08 10:44:00 |
|         5 | 3          |       65.17 | 2014-07-08 10:54:00 |
|         5 | 3          |       60.77 | 2014-07-08 11:04:00 |
|         5 | 3          |       59.89 | 2014-07-08 11:14:00 |
|         5 | 3          |       59.89 | 2014-07-08 11:24:00 |
|         5 | 3          |       65.17 | 2014-07-08 11:34:00 |
|         5 | 3          |       55.49 | 2014-07-08 11:44:00 |
|         5 | 3          |       61.65 | 2014-07-08 11:54:00 |
|         5 | 3          |       61.65 | 2014-07-08 12:04:00 |
|         5 | 3          |       63.41 | 2014-07-08 12:14:00 |
|         5 | 3          |       62.53 | 2014-07-08 12:24:00 |
|         5 | 3          |       59.89 | 2014-07-08 12:34:00 |
|         5 | 3          |       59.01 | 2014-07-08 12:44:00 |
|         5 | 3          |       62.53 | 2014-07-08 12:54:00 |
|         5 | 3          |       64.29 | 2014-07-08 13:04:00 |
|         5 | 3          |       57.25 | 2014-07-08 13:14:00 |
|         5 | 3          |       61.65 | 2014-07-08 13:24:00 |
|         5 | 3          |       61.65 | 2014-07-08 13:34:00 |
|         5 | 3          |       64.29 | 2014-07-08 13:44:00 |
|         5 | 3          |       50.21 | 2014-07-08 13:54:00 |
|         5 | 3          |       52.85 | 2014-07-08 14:04:00 |
|         5 | 3          |       56.37 | 2014-07-08 14:14:00 |
|         5 | 3          |       63.41 | 2014-07-08 14:24:00 |
|         5 | 3          |       66.05 | 2014-07-08 14:34:00 |
|         5 | 3          |       51.97 | 2014-07-08 14:44:00 |
+-----------+------------+-------------+---------------------+

so you can see that there is some pretty decent variation in the temperatures there.

This is my sketch: SUSE Paste

You better make a function to read the temperature.
In that function you can add averaging. For example the average of 5 to 1000 samples. Do you have mains voltage noise of 50/60Hz ?
Those DTH sensors have a temperature sensor, do you use that ?

Cool, good idea! I wrote it to do 10 samples with a 10ms delay in between each sample. So, we'll see how it does :slight_smile:

Oh, and, there shouldn't be 60Hz noise on the line. The power supply has an extra emi/RFI filter on its ac input, and that plugs into an APC SmartUPS, which is connected to its own dedicated circuit, so I'm hoping that that would catch any noise that might crop up.

Hmm, well...

This is the code of the function that I wrote:

float readAnalog(int sensorNum) {
  //We poll twice to help offset the charge delay.
  //http://forums.adafruit.com/viewtopic.php?f=25&t=11597
  analogRead(aSensors[sensorNum]);
  delay(10);
  float sumOfReadings;
  int numReadings = 0;
  
  //Take the average of 10 readings  
  for (int loops = 0; loops <= 10; loops++) {
    sumOfReadings += analogRead(aSensors[sensorNum]);
    delay(10);
    numReadings++;
  }
  
  float result = (sumOfReadings / numReadings) * (5.0 / 1023.0);
  return result;
}

and I'm calling it like this:
float sensorVoltage = readAnalog(curAs);

and so far, it looks ok:

0,v,13.71
1,v,13.60
2,a,-0.16
4,3,-10.85
5,3,69.75
7,u,123.09

I'll keep an eye on it and see how it does :slight_smile:

Instead of delay(10), you can do many more samples without delay. Use long integer if the result won't fit in a normal integer.
I think that delay(10) is very long, at least make it delay(1).

Cool, I did just that. Now it polls 100 readings and does the average of them all. Seems to be really accurate and consistent now :slight_smile:

One quick question about the aref again if I may - does the resistor need to be 4k7, or could I use one of the 10k's I have lying around?

I think 10k is about the maximum for a good accuracy.