Wiring diagram, images and data (Excel file) can be found here: https://drive.google.com/drive/folders/ ... sp=sharing:
The purpose of this lesson should be to show how the ADS1115 gain affects measurements (significant figures and standard deviation. In the present case it is a question of measuring the voltage applied to a UV LED.
An ADS1115 IC has been inserted into the measuring circuit, and the voltage to be measured is applied to pin A0.
THe power supply has been stabilized to 9 V with a L7809 IC.
The current to the LED has been limited by a LM317 IC.
Some series of measurements have been made by changing the set GAIN from time to time (see attached Excel file).
The expected voltage should be about 3 V, regardless of the GAIN set, but an unexpected problem has arisen.
The measurements carried out with GAIN_TWOTHIRDS and GAIN_ONE were as expected.
But starting from GAIN_TWO, the measured signal goes to full scale and remains constant on the value 32767 (half of the full scale of an unsigned int variable?).
At this point I tried to decrease the current on the LED, from about 12.4 mA to 4.88 mA, increasing the output resistance from the LM317 (see yellow column) but the result has not changed, and this is even weirder.
Can you help me figure out what the problem is?
Thanks
Paolo
-----------------------------------------------------------------------------------------------------------------------------------------
This is the code:
Code: Select all
int readings=36;
#include <Wire.h>
#include <Adafruit_ADS1X15.h> //ADS1115 library
Adafruit_ADS1115 ads; //initialize ADS1115
double adc0;
float Vadc0;
void setup() {
Serial.begin(9600);
// uncomment desired mode:
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x +/- 6.144 V 1bit = 0.1875mV default
//ads.setGain(GAIN_ONE); // 1x +/- 4.096 V 1bit = 0.125mV
//ads.setGain(GAIN_TWO); // 2x +/- 2.048 V 1bit = 0.0625mV
//ads.setGain(GAIN_FOUR); // 4x +/- 1.024 V 1bit = 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x +/- 0.512 V 1bit = 0.015625mV
//ads.setGain(GAIN_SIXTEEN); // 16x +/- 0.256 V 1bit = 0.0078125mV
ads.begin();
if (!ads.begin()) {
Serial.println(F("Failed to initialize ADS1115."));
while (1); //if ads.begin() failed, loop infinitely.
}
Serial.print("A1 analog input");Serial.print("\t");Serial.println("Voltage");
}
void loop() {
for(byte i=0;i<readings;i++){
adc0 = ads.readADC_SingleEnded(0);
Serial.print(adc0);
Serial.print("\t");
double Vadc0 = ads.computeVolts(adc0);
Serial.println(Vadc0,DEC);
delay(500);
}
while(1);
}