What is adc raw,? How do it calculate

I want to measure an input voltage using the ADS1115, and I am uploading the code as well. My question is: what exactly is this "raw ADC" value, and how is it calculated? Since I am applying a voltage of 0.008V, the module should read that value, but what does the "raw ADC" reading of 128 represent?

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;

unsigned long startTime;
unsigned long currentSeconds;
float referenceVoltage = 2.0;
bool collecting = true;

void setup(void) {
  Serial.begin(9600);
  Serial.println("Time(s),Raw ADC,Voltage(V)");  // CSV Header
  Serial.println("Press any key to stop data collection");

  if (!ads.begin()) {
    Serial.println("Failed to initialize ADS1115.");
    while (1);
  }

  ads.setGain(GAIN_TWO);

  startTime = millis();
}

void loop(void) {
  if (Serial.available() > 0) {
    char key = Serial.read();
    if (collecting) {
      collecting = false;
      Serial.println("\n*** Data collection stopped! ***");
      Serial.println("Press any key again to resume...");
    } else {
      collecting = true;
      startTime = millis();
      Serial.println("\n*** Data collection resumed! ***");
      Serial.println("Time(s),Raw ADC,Voltage(V)");  // Print header again when resuming
    }
    while (Serial.available() > 0) {
      Serial.read();
    }
  }

  if (collecting) {
    int16_t adc_raw;
    float voltage;

    currentSeconds = (millis() - startTime) / 1000;

    adc_raw = ads.readADC_SingleEnded(0);
    voltage = (adc_raw / 32768.0) * 2.048;

    // CSV format: Time(s),Raw ADC,Voltage(V)
    Serial.print(currentSeconds);
    Serial.print(",");
    Serial.print(adc_raw);
    Serial.print(",");
    Serial.println(voltage, 3);
  }

  delay(1000);
}

"Raw" values typically refer the the ADC's internal binary representation of the converted value, without regard to the reference voltage, scaling, or engineering units.

Depends on the settings. Have a look at the Adafruit ADS1115 Learning Guide.

The device data sheet is the very best resource.

@mdsk

Please edit your post and correct your attempt to use code tags

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

adc_raw = ads.readADC_SingleEnded(0);
voltage = (adc_raw / 32768.0) * 2.048;

While the ADS1115 is a 16 bit A/D one bit is used for sign leaving a 15 bit conversion. This is 2^15 or 32,767 bits full scale. This is your ADC Raw, between 0 and 32767 which is actually 32, 768 quantization steps since 0 counts. The raw count is converted to a voltage as seen in the code snippet.

Ron

1. Your Gain Setting is GAIN_TWO which means you can measure an input voltage of range: -2.048 V to +2.048 V.

2. You are performing a single-ended operation on A0-pin of the ADS1115 ADC. So, your actual measurable input voltage is: 0 V to +2.048 V.

3. The ADS1115 ADC is a 16-bit ADC which gives two's complement output for negative voltage. It means bit-15 is the sign bit with positional weight.

4. In your single-ended case, if you apply to the A0 pin --

(1) 2.048 V, the ADC will deliver 0111 1111 1111 1111 (32767)
(2) 0.008 V, the ADC will deliver 0000 0000 1000 0000 (32767/2.048)*0.008 ~= 128

5. The figure 128 or 1000 0000 of Step-4(2) is known as raw ADC.

6. Code to show on Serial Monitor the raw ADC and ADC input when the input voltage is 0.008 V.

int rawADC = ads.readADC_SingleEnded(0);
Serial.println(rawADC, BIN);   //shows raw ADC as: 1000 0000 (bit)
Serial.println(rawADC, DEC); //shows raw ADC as: 128 (decimal)
Serial.println ((2.048/32767.0)*rawADC, 3); //shows ADC input: 0.008

@mdsk ,

I have deleted your other post on the same subject .

Crossposting is against the Arduino Forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated crossposting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Raw value changes as the reference voltage changes. For example:

1. with FSR = +/-2.048 V, the raw value for input voltage of 0.008 V is 128.
2. with FSR = +/-1.024 V, the raw vlaue for input voltage of 0.008 V is 256.

Hello, please help me. I want to record voltage fluctuations from an oxygen sensor using an ADS1115 module connected to an Arduino Mega 2560 board. Here is my code. My first question is: when a substance enters the test environment, the data readings become negative; are these negative values ​​valid? Given that the measurement range defined in the code is 0 to 32,768, what do these negative values ​​signify? I have provided my data below. Also, regarding the "ADC raw" value—how is it obtained, and shouldn't it match the analog reading?

#include <Wire.h>
#include <Adafruit_ADS1X15.h>

Adafruit_ADS1115 ads;

unsigned long startTime;
unsigned long currentSeconds;
float referenceVoltage = 2.0;
bool collecting = true;

void setup(void) {
  Serial.begin(9600);
  Serial.println("Time(s),Raw ADC,Voltage(V)");  // CSV Header
  Serial.println("Press any key to stop data collection");

  if (!ads.begin()) {
    Serial.println("Failed to initialize ADS1115.");
    while (1);
  }

  ads.setGain(GAIN_TWO);

  startTime = millis();
}

void loop(void) {
  if (Serial.available() > 0) {
    char key = Serial.read();
    if (collecting) {
      collecting = false;
      Serial.println("\n*** Data collection stopped! ***");
      Serial.println("Press any key again to resume...");
    } else {
      collecting = true;
      startTime = millis();
      Serial.println("\n*** Data collection resumed! ***");
      Serial.println("Time(s),Raw ADC,Voltage(V)");  // Print header again when resuming
    }
    while (Serial.available() > 0) {
      Serial.read();
    }
  }

  if (collecting) {
    int16_t adc_raw;
    float voltage;

    currentSeconds = (millis() - startTime) / 1000;

    adc_raw = ads.readADC_SingleEnded(0);
    voltage = (adc_raw / 32768.0) * 2.048;

    // CSV format: Time(s),Raw ADC,Voltage(V)
    Serial.print(currentSeconds);
    Serial.print(",");
    Serial.print(adc_raw);
    Serial.print(",");
    Serial.println(voltage, 3);
  }

  delay(1000);
}

Ok, please go read the forum guide, and then amend your post so that it follows the guide.

You joined the forum in May and you have had plenty of time to do this.

Yes

See your other topic

please take more explanation

Please follow @PaulRB 's advice first.

In the IDE click on Edit then Copy for Forum, that will copy your code for posting on this Forum. Then come back here and just do a simple paste (or insert).

Looking at your schematic it's hard to tell. Oh wait, there is no schematic. Looking at your properly formatted code using code tags it's hard to tell, Oh wait no properly formatted code using code tags.

This was all explained to you in detail on your previous post. Who wrote this code? There has to be a dozen examples of using the ADS1115 with Arduino using a simple Google.

This is the ADS1115 data sheet, I suggest you read it and understand it.

Ron

If the ADS1115 is setup for differential mode (instead of single ended), a positive voltage on a negative input will produce a negative number.
Read the datasheet and post a drawing of your wiring.

https://cdn-learn.adafruit.com/downloads/pdf/adafruit-4-channel-adc-breakouts.pdf

I am measuring the sensor output with a voltmeter and getting 0.008 V, but this value differs from the raw ADC reading of the ADS1115 module. Shouldn't these values ​​be the same?

Welcome!
I believe you may be misunderstanding what the A/D converter is returning.

The value returned by the A/D converter is a count representing the ratio of the input voltage to the ADC reference voltage. It is not a voltage measurement by itself.

For example, assuming a 10-bit ADC such as the classic Arduino UNO, the result is approximately:

ADC count = 1023 * (Vin / Vref)

Therefore, a reading of 512 means the input is approximately one-half of the reference voltage. If the reference is 5.0V, that would be about 2.5V. If the reference voltage changes, the voltage represented by the same ADC count also changes.

You have not told us exactly which Arduino or processor you are using, so we should not assume a 10-bit ADC, a count of 0 to 1023, or a particular reference voltage.

Please tell us the exact board you are using and how it is powered.

no, the raw value is not the voltage

ADS1115 is a 16 bit analog to digital converter

For a voltage it returns a number. This number is the raw value and it depends not only on the input voltage but also on the configured gain.

there is a function in the library that computes the volts from the raw value

/**************************************************************************/
/*!
    @brief  Compute volts for the given raw counts.

    @param counts the ADC reading in raw counts

    @return the ADC reading in volts
*/
/**************************************************************************/
float Adafruit_ADS1X15::computeVolts(int16_t counts) {
  return counts * (getFsRange() / (32768 >> m_bitShift));
}

You have asked this same question several times and gotten as many explanations. Learn how to use the ASD1115 module. The raw ADC is the bit count. Over and over again. No they should not be the same.

Ron

When measuring mV levels, great care must be taken regarding power and ground connections. A ground loop can easily drown out that 8mV.
Show us a picture of your setup.

And then there is the problem of fake ADS1115 chips from China.
An ADS set to single-ended should not output a negative value.
You usually get what you pay for.

As others have said, connecting a voltage to an ADS1115 returns a (15-bit sinle-ended) A/D value. The code translates that A/D value in a human understandable voltage.