Arduino Mega 2560 Analog input data changes by device?

Hello

I am taking the sensor data with analog input. It is just simple voltage data.

So the data is constant as about 90 bit +-5 bit (441mV +- 20mV).

I was using my desktop for this measurement.

However, I tried take the sensor data to my laptop with exactly same setup and same code.

What I did just plug out USB from the desktop and plug in to my laptop.

Than, the data is not consistence at all, the voltage fluctuate 100~200mV.

I just used INA129 instrumentation amplifier to get the voltage output.

INA is working fine but I have no idea why the signal is fluctuate

when I connect Arduino to laptop.

Does the analog input affected by power supply??

I was wondering laptop power is not enough, so I powered up Arduino with 2.1mm adapter

but the result was the same.

Does anyone know about this problem?

Thanks for your help.

It's all about reference. Read the reference of analogReference: analogReference() - Arduino Reference

Normally the 5V is the default reference for analogRead(). So if the 5V power changes to 4.8V, the analogRead will return a higher value. You can use a power supply of 7.5V or more to the DC barrel jack. That should result in the same analog values.

When the internal 1.1V or 2.56V reference is selected, it should be tuned for every ATmega2560 chip, since that value is never exactly 1.100 or 2.560V.

There is of course more to it. It could be ground currents, or mains noise, and so on.

If you're using the USB to power it in all cases it shouldn't make that amount of difference. What exactly is hanging on that analog input pin?

A different computer with different USB voltage could easily result into 100mV to 200mV change. The ATmega2560 is an older chip, and doesn't like lower voltages. So with an laptop and perhaps a cheap usb cable, a combination of things can be wrong.

Since the input voltage is only 400mV, try the internal reference of 1.1V. That will increase the accuracy a lot. The 1.1V reference is made to be independent of the fluctuations of the 5V.

Peter_n:
Since the input voltage is only 400mV, try the internal reference of 1.1V. That will increase the accuracy a lot. The 1.1V reference is made to be independent of the fluctuations of the 5V.

It depends how that analog input is being generated.

As a simple example. Consider a potentiometer connected to the 5v and Gnd, with the wiper going to an analog input. If you have it in it's half way position you'll get 2.5v from it. (ie 512ish as an analogRead).

If you now reduce 5v to 4.5v, the voltage at the wiper will go down but so does the reference for analog readings, so it's still half of the reference voltage. hence the reading will be consistent.

Yes, very true. Let's see what ckim96 has to tell about that magical number of 441mV.

KenF:
If you're using the USB to power it in all cases it shouldn't make that amount of difference. What exactly is hanging on that analog input pin?

The analog input is connected to the output of instrumentation amplifier.

The input of instrumentation amplifier is connected to the sensor output.

I just measured the output of the instrumentation amplifier and the value is about 525mV.

It's stable and does not change.

If I connect Arduino to my desktop than the results are below, First column is mV and second is bit. just 4.9 is multiplied.

499.80 102
499.80 102
494.90 101
499.80 102
499.80 102
470.40 96
455.70 93
460.60 94
485.10 99
490.00 100
494.90 101
494.90 101
494.90 101
494.90 101
490.00 100
450.80 92
450.80 92
475.30 97
499.80 102
494.90 101
494.90 101
499.80 102
499.80 102
494.90 101
455.70 93
450.80 92
480.20 98
490.00 100

After than, I have not changed anything and just take out USB from desktop and plug into my laptop

Than the results are shown below

122.50 25
504.70 103
215.60 44
627.20 128
352.80 72
308.70 63
147.00 30
230.30 47
671.30 137
553.70 113
343.00 70
911.40 186
249.90 51
578.20 118
0.00 0
725.20 148
289.10 59
847.70 173
833.00 170
225.40 46
499.80 102
573.30 117
460.60 94
681.10 139

Like you said Peter, there may be so many things to consider. like usb cable, power,, or something else.

Then, how can I correct this?

What is the method that you said, set internal reference of 1.1V?

One more thing, I need to connect several sensors to this Arduino and take the multiple data.

However, it seems like Arduino mega 2560 ADC is not stable much for my applications.

Like this, I just connect one sensor and has some problem.

Is there any other candidate for my application other than Mega2560?

Thanks for your help.

This is the analogReference : analogReference() - Arduino Reference
The Mega can select 1.1V. After that the input ADC voltage is no longer in the range of 0 to 5V, but 0 to 1.1V.
Anything above 1.1V will become 1023.

void setup() {
  ...
  analogReference(INTERNAL1V1);
}

void loop() {
  ...
  int rawADC = analogRead( A0);
  float voltage = (float) rawADC / 1023.0 * 1.1;
}

The Arduino 2560 ADC is very stable and accurate. Just as accurate as other Arduino boards with ATmel chips that have 10-bits ADC. But those values on the desktop computer change too much, and on the laptop way too much ! There is something wrong, but I don't know what it could be. Perhaps you have high frequency noise or oscillation. A multimeter filters that, but the Arduino takes a sample at that moment.

Can you try something else ? For example a test with an other voltage, like a potentiometer, or the forward voltage of a diode or a LDR, something simple. Measure that with a multimeter and with the Arduino. It should be the same.