Analog read different with external and usb power

Hi

I am using Arduino nano with the Atmega 328p.

VRef is internal (1.1V)

When the board is powered via the usb the supply voltage is 4.5V from my pc.

When I use an external 12v power supply ,connected to Vin ,(build in 5V regulator)the voltage is 4,96.

Changing between the pc and the external power source the reading differs with +- 0.3V.

I used a 12V batt to eliminate possible power supply noise,but the result still varies.

If the internal reference is fixed on 1.1V,why does the result varies when using internal or external power source.

Thanks.

Sounds like your not using the internal Vref. Post your code and a circuit diagram, how is the voltage you are measuring created.

Mark

Changing between the pc and the external power source the reading differs with +- 0.3V.

What do you mean by this. The range is 0 to 1023 for reading an analog pin. You are using the internal ~1.1 volt reference. What are you measuring with the analog pin ? Another stable voltage reference of less that 1.1 volts which is independent of the Arduino power supply, or are your measuing a voltage which is dependent on the Arduino Vcc (say a potential divider between Vcc and ground) ?

Hi

The analogRead is from an external source (variable psu)with 1.2M ohm and 100K ohm as voltage divider.

The external psu negative is connected with the GND pin on the Arduino.

The 0 to 1023 10 bit value is then converted to give a voltage reading.

Value1 = ((1.1/1023)*analogread)*13 ;

where 13 is the divider factor of the resistors.

I did add this line-- analogReference(INTERNAL) and use 1.1 for my calculation.

What is the default setting of the reference voltage in Arduino?

As in the analogInput example in the Arduino Analog example.

Thanks.

What is the default setting of the reference voltage in Arduino?

Vcc

Mark

First of all: I don't know your code, but if reading is not in a fast loop, for a correct value you have to do two readings:

analogRead(Ain); value=analogRead(Ain);

First of all: I don't know your code, but if reading is not in a fast loop, for a correct value you have to do two readings:

There did that stupid idea come from - not the data sheet that's for sure. Provide a reputable cite!

Mark

holmes4:
There did that stupid idea come from - not the data sheet that's for sure. Provide a reputable cite!

Mark

I think that the poster was thinking about reading from different analog pins.

I don't answer to a stupid dispute you haven't inquired about.

http://www.radioactivityforum.it/forum/viewtopic.php?f=19&t=2052&start=175#p13515
http://www.radioactivityforum.it/forum/viewtopic.php?f=19&t=2052&start=175#p13545

Hi,

Can you please post your code.
What is your conversion equation?
Are you doing the conversion in int or float precision?
If you say +/- 0.3V difference, you have to use float.

Can I suggest you drop the divider values to 12K and 1K, as the input impedance of the analog input may be having an influence.

Tom... :slight_smile:

I think that the poster was thinking about reading from different analog pins.

Only (according to the datasheet) for a high impedance source where the sample and hold circuit may not have time to settle.

Contatore Geiger: in attesa dei tubi... Ovvero: Geigerino 1.9i, il mio contatore Geiger con Arduino - Pagina 18 - New Radioactivity Forum
http://www.radioactivityforum.it/forum/viewtopic.php?f=19&t=2052&start=175#p13545

Not a good cite. Only the datasheet should be believed.

Mark

Only (according to the datasheet) for a high impedance source where the sample and hold circuit may not have time to settle.

Does the datasheet indicate how long that takes?

int vals[6];

for(byte b=0; b<6; b++)
{
   vals[b] = analogRead(b);
}

will switch analog pins pretty quickly. What characteristics of the circuit indicate that each reading will be valid, and which characteristics indicate that there would not be time for the sample and hold circuit to settle?

I genuinely want to know this so I don’t (again) counsel people to read the pin twice and ignore the first value, when it may not be necessary.

Mark: >> Not a good cite. Only the datasheet should be believed.

That's my experience, confirmed by other people.
If you don't believe me, it's not a problem for me!
If you believe blindly to datasheets, again it's not a problem for me!

The ATmega328p datasheet says

The ADC is optimized for analog signals with an output impedance of approximately 10 kOhms or less. If such a source is used, the sampling time will be negligible. If a source with higher impedance is used, the sampling time will depend on how long time the source needs to charge the S/H capacitor, with can vary widely. The user is recommended to only use low impedance sources with slowly varying signals, since this minimizes the required charge transfer to the S/H capacitor.

The OP is using a 1.2M:100k divider. I'm guessing this has an impedance greater than 10kOhms. Switching between analog inputs will require extra time for the sample/hold capacitor to charge. Reading from the same input a second time allows for more settling time and is helpful with higher impedance inputs.

That's another problem. You can lower dynamic impedance using a capacitor, i.e. 100nF. It gives energy for charging fastly the input capacitance.

The problem I encountered can't be solved using a capacitor. I don't know exactly why, but also with a low impedance source if I make a reading every 10 sec. values are not stable. If I do a fast loop, i.e. until I exit pressing a pushbutton, values are exactly the same. If I read two times every 10 sec., the second readings are exactly the same. It works...

If you search, you can find someone making many readings, more than two. I've found that the second reading is already good.

I also looked at the Arduino analogRead() code: it doesn't do anything strange. It's the processor. It could be that they made the reading very fast, too fast for a stable value.

johnwasser:
The ATmega328p datasheet says

The OP is using a 1.2M:100k divider. I’m guessing this has an impedance greater than 10kOhms. Switching between analog inputs will require extra time for the sample/hold capacitor to charge. Reading from the same input a second time allows for more settling time and is helpful with higher impedance inputs.

I concur (So does my experience with this chip).

Regards.

More again: I wouldn't use sources (sensors, resistor dividers, ...) with more than 10 kOhm output resistance.

Regards.

What is the difference in noise levels between the 2 supplies? Lets have a wiring diagram.

Hi

Regarding the 1.2M ohm/100k ohm...just a matter of choice..also what lies around in the shack.

I did the following readAnalog and display the value on a lcd.

With USB power ,external 12.7V battery as source to A1 the value is 913.

With external battery 12.7V as source to A1.
Also supply to Vin to on board 5V regulator the value is 929.

((1.1/1023)*913)*13 = 12.76V

((1.1/1023)*929)*13 = 12.98V

#include "SPI.h"
#include "Adafruit_GFX_AS.h"
#include "Adafruit_ILI9341_AS.h"

#define sclk 13  // Don't change
#define mosi 11  // Don't change
#define cs   10
#define dc   9
#define rst  7  //

Adafruit_ILI9341_AS tft = Adafruit_ILI9341_AS(cs, dc, rst);       // Invoke custom library

void setup()
{
  analogReference(INTERNAL);
  tft.init();// Setup the LCD
  tft.fillScreen(LBLUE); 
  tft.setTextColor(GREEN,BLACK);//fore ground,back ground===removes flicker when update 
}

void loop()
{
 delay(1000);
 
 Analog_1 = analogRead(A1);
 tft.drawNumber(Analog_1,0,0,2);
}