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.
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.
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.
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);
}
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.
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.
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.
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.
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.