ADS1115/Getting a good number out of it/05. The gain is a range, not an amplifier
Getting a good number out of it · 05 of 11

The gain is a range, not an amplifier

Selecting ±6.144 V does not let the board measure 6.144 V. It sets what one count is worth and nothing else — the voltage a pin may actually see is still the supply, and going past that damages the chip rather than clipping the reading.

Two ceilings, and they are not the same one

The word gain is misleading, and the datasheet's own name for the setting is better: full-scale range. It decides how the 65536 counts are spread, and nothing else. It is not an amplifier in front of your signal, and it does not protect anything.

The other ceiling is the supply. TI rates the analog inputs from ground to VDD, with absolute maximums 0.3 V either side, and says plainly what happens past that: the protection diodes conduct, and the part can be permanently damaged.

The range and the supply are two different ceilings
±6.144 V · 3.3 V supply
Full-scale range
Supply
The biggest voltage your signal reaches1.65 V
One count
187.5 µV
Top you can reach
3.30 V
Counts in use
8,800
Too wide: you are paying for volts you cannot use. ±6.144 V is a legal setting on a 3.3 V board, but the pin can only reach 3.3 V, so every count above that is unreachable and one count still costs you 187.5 µV. This is the library’s starting setting, which is why a first sketch often reads coarser than people expect. Pick the tightest range your signal fits in.

Put it on ±6.144 V with a 3.3 V supply and watch the grey band appear. Those are codes the chip will never produce on this board, and you paid 187.5 µV a count for them.

Picking one

Take the biggest voltage your signal will ever reach — including the odd condition you have not thought about, like a battery on charge — and pick the narrowest range above it. Then check that number is also below your supply.

Your signal reachesRangeOne count
up to 3.3 V, board on 3.3 V±4.096 V125 µV
up to 5 V, board on 5 V±6.144 V187.5 µV
up to 2 V±2.048 V62.5 µV
up to 1 V±1.024 V31.25 µV
a few hundred millivolts±0.512 V15.625 µV
tens of millivolts±0.256 V7.8125 µV

The first two rows are the awkward ones: on a 3.3 V board the ±4.096 V range is the best available even though a quarter of it is unreachable, because the next one down would clip at 2.048 V.

Anything bigger needs a divider

There is no range setting that makes a 12 V battery safe on a 3.3 V board. Two resistors do, and they cost about ten cents. Measuring a 12 V battery works through one start to finish, including the two things a divider costs you that nobody mentions.

The library's starting point

Rob Tillaart's ADS1X15 library — the one most examples use — starts at gain 0, which is ±6.144 V. That is its own choice, not the chip's: the ADS1115 itself resets to ±2.048 V.

Which means a first sketch that never calls setGain gets the coarsest setting available, and on a 3.3 V board wastes nearly half of it. That is usually the whole explanation for "my ADS1115 is not as precise as I expected".

The code

ads1115_read_volts.ino

One channel, read once a second, printed as a count and as volts. The only interesting line is setGain — everything else is the same whatever range you pick.

// Wiring for this sketch.
//
//   ESP32 3V3  -> VCC
//   ESP32 GND  -> GND
//   ESP32 SDA  -> SDA
//   ESP32 SCL  -> SCL
//   what you are measuring -> A0, and its ground -> GND
//
// The voltage on A0 must stay below VCC. Divide it down first if it does not.
//
// Arduino IDE: any board. Library: "ADS1X15" by Rob Tillaart,
// installed from Tools > Manage Libraries.

#include <Wire.h>
#include <ADS1X15.h>

ADS1115 ADS(0x48);

void setup() {
  Serial.begin(115200);
  delay(500);
  Wire.begin();

  if (!ADS.begin()) {
    Serial.println("no ADS1115 at 0x48 - run the scan sketch first");
    while (true) delay(1000);
  }

  ADS.setGain(1);        // 1 = +/-4.096 V. 0 = 6.144, 2 = 2.048, 4 = 1.024,
                         // 8 = 0.512, 16 = 0.256
  ADS.setDataRate(4);    // 4 = 128 SPS, the default
}

void loop() {
  int16_t raw = ADS.readADC(0);
  float v = ADS.toVoltage(raw);
  Serial.printf("A0  raw %6d   %.4f V\n", raw, v);
  delay(1000);
}

The library starts at gain 0, which is ±6.144 V, so a sketch that never calls setGain is using the coarsest setting there is. On a 3.3 V board that also wastes half the range. Gain 1 — ±4.096 V — is the sensible default for a 3.3 V or 5 V supply, and narrower is better if your signal is smaller.

When it does not work

The reading sits at 32767 and will not move

The signal is above the selected range. If it is still below the supply nothing is damaged — open the range one step and the shape comes back. If it is above the supply, disconnect it now: the protection diodes are conducting and the chip is being harmed for as long as it stays connected.

My readings are much coarser than I expected

You are probably still on the library's starting range of ±6.144 V, where one count is 187.5 µV. Call setGain with the tightest range your signal fits in. On a 3.3 V board the widest two ranges cannot even reach their own full scale, so they give away resolution for nothing.

I selected ±6.144 V so why can I not measure 5 V on a 3.3 V board?

Because the range and the supply are two different limits and the smaller one wins. The range says how the counts are spaced. The supply says how high a pin may go before the chip is damaged — 0.3 V above VCC, and no further. A wider range never buys headroom.

Changing the gain does not seem to take effect

In the ADS1X15 library the setting is not written to the chip until the next read or request, so a setGain immediately followed by a print of the old value looks like nothing happened. Take a reading after changing it. It also means the first reading after a change is the one with the new range applied, not the one before.

Where this goes next

Four channels or two, and why the two-pin ones are quieter.

Single-ended and differential

Edit this page — content/books/ads1115/the-gain-is-a-range.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

This page covers several products. Choose yours to see the right discussions.

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum