ADC in Arduino Due not reading accurate value

Hi,

I'm using the Arduino Board and I', trying to find the accurate ADC reading. The following is my code:

int analogPin = A1; // set the ADC pin for Battery voltage
  

void setup() 
{
  Serial.begin(9600);
  analogReadResolution(12);
}

void loop() 
{
  Detect_Volts();
}

void Detect_Solar_Volts (void)
{
 Serial.println(analogRead(A1));
}

I'm setting the voltage of the power supply at 3.3v and passing the voltage through a voltage divider of 10K resistors. The output voltage is 1.8v and that corresponds to an ADC value of 2234. But the serial monitor is giving an ADC value between 2000 and 2500. What is going wrong?

As a first step in debugging this issue, I would start by increasing the baudrate (e.g. Serial.begin(115200)) to minimize the time to output data samples and use the Serial Plotter feature of the Arduino IDE to plot the data. The resultant plot will help diagnose the problem.

Please post a hand drawn circuit diagram. Beware long wires that pick up AC interference, or a possible bad connection and floating input.

I'm setting the voltage of the power supply at 3.3v and passing the voltage through a voltage divider of 10K resistors. The output voltage is 1.8v and that corresponds to an ADC value of 2234. But the serial monitor is giving an ADC value between 2000 and 2500. What is going wrong?

Using 12 bit resolution as you are doing your analog in of 0 to 3.3 volts should result in 0 to 4096 bits. Using two 10K resistors as a divider and applying 3.3 volts the divided output of 2:1 should yield 2048 bits give or take. This is about 0.8057 mV/Bit or 1.65 volts. This assumes a decent divider using quality resistors. I have no idea why your output voltage is 1.8 volts? With a 3.3 volt reference and 4096 quantization levels you have 0.8057 mV per step.

If you want to actually read your analog input as a voltage the code loop would look a little like this:

 void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 4096) to a voltage (0 - 3.3V):
  float voltage = sensorValue * (3.3 / 4096.0);
  // print out the value you read:
  Serial.println(voltage);
}

Best I can tell you is check your connections and post a drawing of what you have.

Ron

Thank You everyone for your replies.

I was trying different ways to solve this and just connected the Arduino ground with the ground of the power supply and now the ADC value is ranging between 2224 and 2226. That is acceptable considering the resistors have a 5% tolerance and there might be some noise in between the signals.

I am attaching the diagram here. The line highlighted in yellow is the line that I added.

Arduino Due ADC test

The problem was a floating input.

Whole thread devoted to Common Ground and why you need one. :slight_smile: Glad it worked out for you.

https://forum.arduino.cc/index.php?topic=653831.0

Ron

If only you'd noticed the sticky thread at the top of this section of the forum (!)

The formal term for a voltage, namely "potential difference", is also a give-away than you must
connect to two points in a circuit to define a voltage.

Glad its working now.

Note that the analog side of the Due isn't brilliant (especially in the official Due board which has a
switch-mode regulator), I'd be surprized if you get all 12 bits being meaningful (from what I remember
the DAC is worse than the ADC).