#include <Adafruit_ADS1X15.h>
Adafruit_ADS1015 ads;
void setup() {
// initialize serial communication at 115200 bits per second:
Serial.begin(115200);
//set the resolution to 12 bits (0-4096)
analogReadResolution(12);
ads.begin();
}
void loop() {
int16_t adcValue;
float voltage;
// read the analog / millivolts value for pin 2:
int analogValue = analogRead(2);
int analogVolts = analogReadMilliVolts(2);
delay(100); // delay in between reads for clear read from serial
// Read from AIN0 (assuming your sensor is connected to A0)
adcValue = ads.readADC_SingleEnded(0);
// Convert ADC value to voltage
voltage = ads.computeVolts(adcValue);
// Print the result
Serial.print("ADC Value: "); Serial.print(adcValue);
//Serial.print(" Voltage: "); Serial.print(voltage); Serial.print(" V");
Serial.print(" Analog Value: "); Serial.print(analogValue);
//Serial.print("ADC millivolts value = %d\n",analogVolts);
Serial.println(" ");
delay(100); // Delay for readability, adjust as needed
}