Try Embedded

Precision voltmeter (ADS1115)

Measure voltages to a fraction of a millivolt with a 16-bit ADS1115 and compare it with the board's 10-bit ADC.

Sensors · Intermediate

In a real product: Battery tester (Energy): A 16-bit converter resolves each cell's voltage to a fraction of a millivolt.

The Uno's ADC has 10 bits: 1024 steps of about 4.9 mV. An ADS1115 has 16 bits and a programmable gain amplifier, so the same signal resolves to 125 µV, and small signals far finer than that.

What you'll learn

  • Resolution, full-scale range and gain
  • Single-ended and differential measurements
  • Reading an I²C ADC with a library, and what the library does with the registers

How it works

The board's 3.3 V pin feeds both the ADS1115's AIN1 and the Uno's A1. With GAIN_ONE the ADS1115's full scale is ±4.096 V, so one count is 4.096 V / 32768 = 125 µV. readADC_SingleEnded(1) writes the configuration register (input, gain, single-shot start), waits for the conversion to finish and reads the result; computeVolts() scales it.

The ADS1115 reads 3.3000 V. The Uno can only land on a multiple of 4.9 mV: its nearest step is 675, which is 3.2991 V. The potentiometer on AIN0 is measured differentially against AIN3 (on GND here, but it could be any other point in the circuit): the voltage between two inputs, neither of them necessarily GND.

Try this

  • Turn the knob while it runs and watch the differential reading.
  • Change the gain to GAIN_SIXTEEN (±0.256 V): small signals get 16 times the resolution, and 3.3 V clips at 0.256 V.
  • Average 16 Uno readings of the 3.3 V pin: does it get closer?

sketch.ino

// ADS1115 at 0x48 against the Uno's own ADC: 3.3 V on AIN1 and A1, a knob on AIN0, AIN3 to GND.
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;

void setup() {
  Serial.begin(9600);
  if (!ads.begin(0x48)) {
    Serial.println("No ADS1115 at 0x48");
    while (true) {}
  }
  ads.setGain(GAIN_ONE);   // +/-4.096 V, 125 uV a count
  Serial.println("3.3 V pin: ADS1115    Uno A1      Knob: AIN0-AIN3");
}

void loop() {
  float precise = ads.computeVolts(ads.readADC_SingleEnded(1));
  float coarse = analogRead(A1) * 5.0 / 1023.0;
  float knob = ads.computeVolts(ads.readADC_Differential_0_3());
  Serial.print("           ");
  Serial.print(precise, 4);
  Serial.print(" V   ");
  Serial.print(coarse, 4);
  Serial.print(" V    ");
  Serial.print(knob, 4);
  Serial.println(" V");
  delay(500);
}

Lessons behind it