Drifting ARef or ADC on Mega2560?

Greetings,

I’ve been working on a pool automation project since the pandemic started!!!

Measuring pressure has been a tough nut to crack…

After ordering a new set of cheap pressure transducers (10 and 80psi), things seemed to finally settle and I was getting the proper readings.

I’m working with an Arduino Mega, using the default internal reference. All 4 sensors, 2 each 10 and 80psi are supplied by the onboard 5V, which operates at 4.995V, very steady… Consumption of each of them is in the single mA…

At 5V, the sensors go from 0psi at 0.5V to MAXpsi at 4.5V… that’s basically 102 to 921/1024…

After powering up and letting the system stabilize, all sensors (32 reading avg) read about 90/1024…

This lasted for about two days. Then they all started drifting up in unison, to about 100, and two days later drifted down to about 70… All of them!

Initially I thought “cheap sensors”, but then I figured they can’t ALL drift by exactly the same amount… then I thought it’s temperature sensitivity… Then I thought it’s atmospheric pressure (just entered a period of heavy rains)…

Then I replaced one of the sensors with a 1k potentiometer and set it to 100ohms (10%, equivalent to 0psi). Lo and behold, the arduino returned the exact same drifted offset of 70 instead of showing 102! From that I concluded that the sensors are stable and the ADC/ARef drifted…

So I added analog reference(EXTERNAL) in setup() and a wire straight from the sensor board 5V to AREF… I’m back to reading 90. It should be 102…

I had monitored the 5V the entire time. It didn’t drift more than 10mV.

Grounds are set in Star layout… BUT, I noticed that when I connect the ethernet cable, all outputs drift up a bit as well. The unit will always be connected to the local network, so I’m not too worried about that, but it is an indication that there are some ground loops involved…

Questions:

1- is it normal for the internal ARef to drift, when the regulated 5V stays stable?

2- will using external fix this problem or does the ADC itself drift?

3- if 2 is correct, should I go with an external I2C based multiplexed delta-sigma ADC, like the MCP34xx?

Cheers!

There are two internal references, 1.1V and 2.56V and neither are default. Which reference are you using, and HOW are you using it with a 5V sensor?

Please post the code and a hand drawn wiring diagram, being sure to show power and ground connections.

Hello J,

According to arduino.cc, for analog reference():

Arduino AVR Boards (Uno, Mega, Leonardo, etc.)

  • DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)…

Attached the very poor schematic…

The sketch is easy enough:

sum AnalogRead(A8) 32x.
Divide by 32
Display…

Sorry, I won’t get to the IDE for a while…

Which sensors are they ? Do you know the brand and type or can you give a link to where you bought them ?
Can you try to find out what ‘ratiometric’ means when a sensor is connected to an Arduino ?

I think those sensors are ratiometric. That means you have to use the DEFAULT voltage reference (which is the internal 5V).

  1. The AREF does not drift. With ‘DEFAULT’ it is the same as VCC, it really is.
  2. The ADC does not drift, the AVR family microcontrollers are well known for their very good ADC (for the 10-bits that is).
  3. When dealing the ratiometric sensors, the easiest and best stable result is to use the internal ADC.

There can be many things that could go wrong.

  • The 6.5V power is low, can you give at least 7.5V to the board ?
  • The GND wire to your sensors should be connected between the Arduino board and a sensor. Connect a single GND wire to a single sensor and nothing else. That GND wire is just as important as the signal wire. Treat it in the same way as the small signal of the signal wire.
  • It could be something in the sketch.

Is that a capacitor in the drawing ? To which GND is it connected ? Can you remove it for a clean test ?

After reading your post once more, I still don’t know what the cause is. It might be something else.

1 Like

Do not connect Vref to 5V. Connect Vref to ground through a 0.1uF cap.

From the data sheet:

the reference voltage can be made more immune to noise by connecting a capacitor between the AREF pin and ground.

1 Like

Those sensors are ratiometric (should be) and should follow Vcc even if it drifts a little, I think your problem is the 6.5 volts to the barrel connector, that’s right at the borderline of the regulator’s dropout point. Either up the barrel connector voltage above 7V or use regulated 5V connected to the 5V pin. Have you tried it powered through the USB socket?

1 Like

Hello @Koepel, @groundFungus , @JCA34F ;

Thanks for all of your input.

1- Yes, I can confirm they are ratiometric sensors, SENSOR .

2- My apologies, I went back and verified, I have 8V supplying the Arduino Mega barrel connector.

3- Ref GND connection: I had actually run the shield of the 4/22 sensor wires from the sensor ground to the Arduino GND, without connecting it. I now have it connected and ALL sensors and the 1k potentiometer read within 2 counts of 102 (0PSI). This, in both configurations, with DEFAULT Aref and EXTERNAL Aref…

4- @groundFungus: What size capacitor do you recommend to add to ARef?

When earlier in the post, I said that GNDs were in Star configuration, I must clarify that the center of the Star is on the power supply board and the Arduino is one branch of this… by adding the wire from the sensor board directly to the Arduino GND, I’m eliminating the stray currents in those two branches of the GND star…

I’ll have this run for a couple more days, recording data every 15mins and report back…

Cheers all!

0.1uF ceramic.

Connect your volt meter between VREF and each sensor’s analog in pin and record the voltage, if the zero pressure voltage drifts off again, compare voltage to the recorded.

Noted and done…

Bad recommendation to measure “voltage”.
“Voltage” has nothing to do with ratiometric pressure sensors and the default A/D of an Arduino.
It’s all about ratio.

Pressure sensors don’t output 0.5-4.5volt, as usually stated in poorly written datasheets.
They output 10%-90% of their supply voltage.

The ratiometric A/D of the Arduino compensates for supply and Aref variations.
That is, if you leave it on the default setting.
Leo…

Idea was to see if zero pressure voltage was shifting in relation to VREF, if not a good idea, I’ll shut up and go away.

Absolute voltage from the sensor is meaningless, but it’s ok if you calculate the relation to Aref.

But nothing can go wrong if you use default Aref.
If you have pressure readout drift, then there is a problem with the sensor.
Leo…

Please don’t go away @JCA34F

I understand what you are saying about having a reference point to monitor

I also understand Leo’s @Wawa point about radiometric measurements.

Voltage is the easiest thing to measure in-circuit, you can’t measure ratios easily. You just need to do the math with the voltage.

@wawa, I disagree with “something wrong with the sensor” Leo. When 4 sensors drift by the same amount at the same time and replacing one sensor with a potentiometer (also ratiometric) does the same, you start looking for a common denominator… In this case it was ARef, until @Koepel put us onto GND loops…

In any case, let’s give this a few days of testing and I report back to all of you…

You obviously haven’t read up on this. The Arduino ADC is ratiometric. It DOES NOT measure voltage. Instead, it measures the ratio of the input voltage to the reference voltage.

Hi J;

I obviously didn’t express myself for all to understand. A DVM, digital voltmeter, doesn’t easily measure ratiometrically - it uses its own reference… that’s why I we measure Vout and VDD, so we can do the ratiometric calculation. I understand that the Arduino ADC is ratiometric and so are the sensors.
Sorry for the confusion.

Sensor power/ground must of course be the same as Aref power/ground for this ratiometric behaviour to work. Therefore you should be careful with breadboards and/or wiring. Power/ground shouldn’t be shared with other users/devices.
Leo…

This sounds like a temperature effect - perhaps the sensors have poor thermal stability?
You need to post the datasheet for the sensors - the fact they are cheap is a warning sign - they may be too cheap.

Did you monitor the temperature over the same time period? Perhaps this drift can be
compensated for.

Hello Mark;

That was indeed one of my first thoughts. The temperature in my office doesn’t vary much, about 5C. But I did do a test: all 4 sensors are hooked up to a brass manifold attached to a water column. So I put the whole assembly in a pot of warm water, generating a deltaT about 20C. There was a slight drift, but nothing to account for 30 counts (3%).

The issue seems to have been a stray current in the ground. Since I fixed that, I see maximal fluctuations of 3 counts or less…

Case in point, as I mentioned earlier, when I replaced one of the sensors with a potentiometer, the drift remained the same… and disappeared once I fixed the ground loop.