How to include to read a Uv sensor ML8511 and more soil sensor through ADS1015 in my code

Hello
I have completed a projekt for my garten momentan with board Wemos D1 and i use Blynk App
I reads with my code momentan :
1 x Soil moisture
1 x Bme280 sensor pressure temperatur humidity
1 x relay 5v
1 x Watter pump

But now i want to connect another one soil sensor and one Uv sensor ml8511 …i have a wemos D1 r1 momentan and i want to connect all analog Pins from the sensor with board ADS1015 to read all analog pins… because my board wemos have only one A0 pins…It is possibile to do this one???

I started writing extra code to read the Uv sensor ML8511 with blynk togheter but i dint not succeed…

I dont understand how to include the board ADS1015 in my code the same?

This is my code and now how do i enter the other codes in my program ?

#define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
WidgetLED PUMP(V0); 
#define SEALEVELPRESSURE_HPA (309.25)
#define SOIL_MOIST_1_PIN A0 // pin A0 with A0
#define PUMP_PIN D2  // PUMP RELAY
#define DRY_SOIL      68
#define WET_SOIL      90
#define TIME_PUMP_ON  15
#define READ_SOIL_HUM_TM  10L 
#define READ_AIR_DATA_TM  2L  
#define SEND_UP_DATA_TM   10L 
#define AUTO_CTRL_TM      60L 
char auth[] = "blynk";
char ssid[] = "wifi";
char pass[] = "password";
float pressure;     //To store the barometric pressure (Pa)
float temperature;  //To store the temperature (oC)
int altimeter;      //To store the humidity (%) (you can also use it as a float variable)
int soilMoist = 0;
boolean pumpStatus = 0;
int timePumpOn = 1; 
long sampleTimingSeconds = 20; 
long startTiming = 0;
long elapsedTime = 0;
SimpleTimer timer;
Adafruit_BME280 bme;


void setup() {
  pinMode(PUMP_PIN, OUTPUT);
  bme.begin(0x76);    //Begin the sensor
 aplyCmd();
 Serial.begin(9600);
   Serial.println("Adafruit BME280 test:");
   
  Blynk.begin( auth, ssid , pass );
  PUMP.off();
 startTimers();
   timer.setInterval(2000L, ReadSensors);   // read sensor every 5s

}
void loop() {
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}
BLYNK_WRITE(4) 
{
  int i = param.asInt();
  if (i == 1)
  {
    pumpStatus = !pumpStatus;
    aplyCmd();
  }
}
void getSoilMoist(void)
{
  int i = 0;
  soilMoist = 0;
  for (i = 0; i < 10; i++)  //
  {
    soilMoist += analogRead(SOIL_MOIST_1_PIN); 
    delay(20);   
  }
  soilMoist = soilMoist / (i);
  soilMoist = map(soilMoist, 1023, 0, 0, 100); 

}
void ReadSensors(void) {
  //Read values from the sensor:
  pressure = bme.readPressure();
  temperature = bme.readTemperature();
  altimeter = bme.readHumidity ();

  //Print values to serial monitor:
  Serial.print(F("Pressure: "));
  Serial.print(pressure);
  Serial.print(" hPa");
  Serial.print("\t");
  Serial.print(("Temp: "));
  Serial.print(temperature);
  Serial.print(" °C");
  Serial.print("\t");
  Serial.print(" Altimeter: ");
  Serial.print( altimeter ); // this should be adjusted to your local forcase
  Serial.println(" % ");
  //delay(2000); //Update every 5 sec
}
void aplyCmd()
{
  if (pumpStatus == 1)
  {
    Blynk.notify("pump ON");
    digitalWrite(PUMP_PIN, LOW);
    PUMP.on();
  }

  else {
    digitalWrite(PUMP_PIN, HIGH);
    PUMP.off();
  }
}
void autoControlPlantation(void)
{
  if (soilMoist < DRY_SOIL)
  {
    turnPumpOn();
  }
}
void turnPumpOn()
{
  pumpStatus = 1;
  aplyCmd();
  delay (TIME_PUMP_ON * 1000);
  pumpStatus = 0;
  aplyCmd();
}
void startTimers(void)
{
  timer.setInterval(READ_SOIL_HUM_TM * 1000, getSoilMoist);
  timer.setInterval(SEND_UP_DATA_TM * 1000, sendUptime);
  timer.setInterval(AUTO_CTRL_TM * 1000, autoControlPlantation);
}
void sendUptime()
{

  Blynk.virtualWrite(V1, pressure / 100);   // write pressure to V1 value display widget
  Blynk.virtualWrite(V2, temperature);  // write temperature to V2 value display widget
  Blynk.virtualWrite(V3, altimeter);    // write altimeter to V3 value display widget
  Blynk.virtualWrite(V4, soilMoist);
}```

Have not used one of these myself, but a quick google search of the sensor yeilds quite a bit of results, along with many code examples.

For example:

You just need to put the stuff in a timed function instead of in the loop(). Oh, and make sure you have the proper libraries installed, and the wiring correct.

You can give me a example for second Soil moisture in my code ? Thnks

Also you have a few delays in you code. You should get rid of them as they will stop your code

But momentan the code work …i dont know how to put ADS1015 in my code to read another analog Soil Moisture

I will assume you have these things taken care of.

Also, I do not have one of these sensors or chips, so this is just where I would start if I was trying one of these out. Adjustments/tweaking may be necessary. I just cut and pasted some parts from the example I linked to above.

    #include <Wire.h>
    #include <Adafruit_ADS1015.h>
     
    Adafruit_ADS1015 ads1015;

   float soil1;
     
    void setup(void)
    {
      Serial.begin(9600);
      Serial.println("Hello!");
      
      Serial.println("Getting single-ended readings from AIN0..3");
      Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");
      ads1015.begin();

      Blynk.begin( auth, ssid , pass );

         timer.setInterval(30000L, soilSensors);   // read sensor every 30s
    }

void soilSensor()
{

     
      soil1 = ads1015.readADC_SingleEnded(0);
      
      Serial.print("soil1: "); Serial.println(soil1);

}
     
    void loop(void)
    {
   timer.run(); // Initiates SimpleTimer
  Blynk.run();
    }

OK , I tried but it doesn’t work…look for example this is my code for UV sensor Ml8511 and i can read with blynk…now my question is how do i read pin A0 through ads and unite it with my code above ???

This is my code for UV sensor :

    #include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
    #include <SimpleTimer.h>

    SimpleTimer timer;

    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
char auth[] = "ChEg9qcPCGHsyv5";
char ssid[] = "W6";
char pass[] = "6937";

int ReadUVintensityPin = A0; //Output from the sensor

void setup()
{
  pinMode(ReadUVintensityPin, INPUT);
  Serial.begin(9600); //open serial port, set the baud rate to 9600 bps
  Serial.println("Starting up...");
   Blynk.begin( auth, ssid , pass );
 timer.setInterval(1000L, ReadSensors);
}
  void ReadSensors()
    {
  int uvLevel = averageAnalogRead(ReadUVintensityPin);

  float outputVoltage = 5.0 * uvLevel/1024;
  float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);
Serial.print("UVAnalogOutput: ");
  Serial.print(uvLevel);
  
  
  Serial.print(" OutputVoltage: ");
  Serial.print(outputVoltage);

  Serial.print(" uvIntensity: ");
  Serial.print(uvIntensity);
  Serial.print(" mW/cm^2");
 

  Serial.println();
  
  Blynk.virtualWrite(V1, uvIntensity);
   Blynk.virtualWrite(V2, uvLevel);
    Blynk.virtualWrite(V3, outputVoltage);
 // delay(2000);
}
 void loop()
    {
    Blynk.run(); // Initiates Blynk
    timer.run(); // Initiates SimpleTimer
    }
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0;

  for(int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;

  return(runningValue);

}

//The Arduino Map function but for floats
//From: http://forum.arduino.cc/index.php?topic=3922.0
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

I tried to connect another one Soil Moisture sensor and UV sensor ML8511 but I have some code errors… 'mapfloat' was not declared in this scope
I still need a another command to connect ADS1015 ???
What is wrong in my code ?
Sorry but I’m not an expert in arduino, this is my 2nd project…

I would like to read with the following code:
-1 soil moisture with my board from A0

  • Another soil moisture with A0 from ADS1015
    -Bme280 i will conect with board
  • UV sensor with A1 from ADS1015
#define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
 #include <Adafruit_ADS1015.h>
WidgetLED PUMP(V0); 
#define SEALEVELPRESSURE_HPA (1015.25)
#define SOIL_MOIST_1_PIN A0 // pin A0 with A0
#define PUMP_PIN D2  // PUMP RELAY
#define DRY_SOIL      68
#define WET_SOIL      90
#define TIME_PUMP_ON  15
#define READ_SOIL_HUM_TM  10L 
#define READ_AIR_DATA_TM  2L  
#define SEND_UP_DATA_TM   10L 
#define AUTO_CTRL_TM      60L 
char auth[] = "edPlMAp1ZdrhY";
char ssid[] = "W866";
char pass[] = "6977";
float pressure;     //To store the barometric pressure (Pa)
float temperature;  //To store the temperature (oC)
int altimeter;      //To store the humidity (%) (you can also use it as a float variable)
int Absolutehumidity;     
int soilMoist = 0;
float soil1;
boolean pumpStatus = 0;
int timePumpOn = 1; 
long sampleTimingSeconds = 20; 
long startTiming = 0;
long elapsedTime = 0;

int ReadUVintensityPin;

SimpleTimer timer;
Adafruit_BME280 bme;
  Adafruit_ADS1015 ads1015;


void setup() {
  pinMode(PUMP_PIN, OUTPUT);
  bme.begin(0x76);    //Begin the sensor
 aplyCmd();
 Serial.begin(9600);
   Serial.println("Adafruit BME280 test:");
     Serial.println("Getting single-ended readings from AIN0..3");
      Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");
      ads1015.begin();
    pinMode(ReadUVintensityPin, INPUT);
  Blynk.begin( auth, ssid , pass );
  PUMP.off();
 startTimers();
   timer.setInterval(2000L, ReadSensors);   // read sensor every 5s
timer.setInterval(1000L, ReadUVintensity);
}
void loop() {
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}
void ReadUVintensity()
    {
      
  ReadUVintensityPin = ads1015.readADC_SingleEnded(1);
  int uvLevel = ads1015.readADC_SingleEnded(1);

  float outputVoltage = 5.0 * uvLevel/1024;
  float UVintensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);
Serial.print("UVAnalogOutput: ");
  Serial.print(uvLevel);
  
  
  Serial.print(" OutputVoltage: ");
  Serial.print(outputVoltage);

  Serial.print(" uvIntensity: ");
  Serial.print(uvIntensity);
  Serial.print(" mW/cm^2");
 Serial.println();
 int uvLevel(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0;

  for(int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;

  return(runningValue);

}

//The Arduino Map function but for floats
//From: http://forum.arduino.cc/index.php?topic=3922.0
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
}
  
BLYNK_WRITE(4) 
{
  int i = param.asInt();
  if (i == 1)
  {
    pumpStatus = !pumpStatus;
    aplyCmd();
  }
}
void soilSensor()
{

     
      soil1 = ads1015.readADC_SingleEnded(0);
      
      Serial.print("soil1: "); Serial.println(soil1);

}
void getSoilMoist(void)
{
  int i = 0;
  soilMoist = 0;
  for (i = 0; i < 10; i++)  //
  {
    soilMoist += analogRead(SOIL_MOIST_1_PIN); 
    delay(20);   
  }
  soilMoist = soilMoist / (i);
  soilMoist = map(soilMoist, 1023, 0, 0, 100); 
}
void ReadSensors(void) {
  //Read values from the sensor:
  pressure = bme.readPressure();
  temperature = bme.readTemperature();
 Absolutehumidity = bme.readHumidity ();
  altimeter = bme.readAltitude (SEALEVELPRESSURE_HPA);
  //Print values to serial monitor:
  Serial.print(F("Pressure: "));
  Serial.print(pressure);
  Serial.print(" hPa");
  Serial.print("\t");
  Serial.print(("Temp: "));
  Serial.print(temperature);
  Serial.print(" °C");
  Serial.print("\t");
 Serial.print(" Humidity: ");
  Serial.print( Absolutehumidity ); // this should be adjusted to your local forcase
  Serial.println(" % ");
  Serial.print(" Altimeter: ");
  Serial.print( altimeter ); // this should be adjusted to your local forcase
  Serial.println(" m ");
  //delay(2000); //Update every 5 sec
}
void aplyCmd()
{
  if (pumpStatus == 1)
  {
    Blynk.notify("pump ON");
    digitalWrite(PUMP_PIN, LOW);
    PUMP.on();
  }

  else {
    digitalWrite(PUMP_PIN, HIGH);
    PUMP.off();
  }
}
void autoControlPlantation(void)
{
  if (soilMoist < DRY_SOIL)
  {
    turnPumpOn();
  }
}
void turnPumpOn()
{
  pumpStatus = 1;
  aplyCmd();
  delay (TIME_PUMP_ON * 1000);
  pumpStatus = 0;
  aplyCmd();
}
void startTimers(void)
{
  timer.setInterval(READ_SOIL_HUM_TM * 1000, getSoilMoist);
  timer.setInterval(SEND_UP_DATA_TM * 1000, sendUptime);
  timer.setInterval(AUTO_CTRL_TM * 1000, autoControlPlantation);
}
void sendUptime()
{

  Blynk.virtualWrite(V1, pressure / 100);   // write pressure to V1 value display widget
  Blynk.virtualWrite(V2, temperature);  // write temperature to V2 value display widget
  Blynk.virtualWrite(V3, altimeter);    // write altimeter to V3 value display widget
  Blynk.virtualWrite(V4, soilMoist);
   Blynk.virtualWrite(V5, Absolutehumidity);
    Blynk.virtualWrite(V6, soil1);
     Blynk.virtualWrite(V7, uvIntensity);
}```

Try map UVintensity

I’m guessing mapfloat is a library specific command. (A library that you haven’t included)

Did you try

float UVintensity = map (outputVoltage, 0.99, 2.9, 0.0, 15.0);

I have never seen this C++ syntax before

averageAnalogRead

I modified but then I have another problem …i dont know what i need to change…

I delete averangeanalogread

Personally, I’d take a more structured and analytical approach to this problem.

Start by finding some ADS1015 sample code and use it - without Blynk - to get readings from your two sensors. Experiment with the code and pick it apart until you understand how it works. If the sketch has lots of code in the void loop then add a SimpleTimer and move the code out of the void loop and tweak this until it works.

Then look at the original Blynk sketch that you want to add to. Print it out and highlight the sections that relate to taking soil moisture readings. Study the code until you can see what needs to change to add-in the ADS1015 code and an additional soil moisture sensor.
When you add new variables follow the naming conventions established in the original sketch so that the code is structured and logical.

Add some debug messages using serial print statements so that you can follow the code execution and verify that it’s doing what you want it to.

Pete.

1 Like

That was going to be my next advice :+1:t3:

2 Likes

I understand but i am beginner … I don’t know how to arrange the code …if somebody want to help me I will appreciate.:+1::ok_hand:
I changed the code but I have other problems like simplytimer how said @PeteKnight .
I research in internet some simply code with ADS1015 but i don’t understand how to use …

Hello ,
I think I succeeded…
Look the code :
@PeteKnight you can check the code if it is written correctly …i have some questions about ads.setGain …ist corect my Gain ?

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <Wire.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_ADS1015.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

WidgetLED PUMP(V0);

#define SEALEVELPRESSURE_HPA (1015.25)
#define SOIL_MOIST_1_PIN A0 // pin A0 with A0
#define PUMP_PIN D2  // PUMP RELAY
#define DRY_SOIL      68
#define WET_SOIL      90
#define TIME_PUMP_ON  15
#define READ_SOIL_HUM_TM  10L
#define READ_AIR_DATA_TM  2L
#define SEND_UP_DATA_TM   10L
#define AUTO_CTRL_TM      60L

char auth[] = "ChEg9qcPK";
char ssid[] = "W6";
char pass[] = "6177";

float pressure;     //To store the barometric pressure (Pa)
float temperature;  //To store the temperature (oC)
int altimeter;
int Absolutehumidity;
int soil1;
int ReadUVintensity;
int soilMoist = 0;
boolean pumpStatus = 0;
int timePumpOn = 1;
long sampleTimingSeconds = 20;
long startTiming = 0;
long elapsedTime = 0;

Adafruit_ADS1115 ads(0x48);
Adafruit_BME280 bme;
SimpleTimer timer;

void setup() {
  pinMode(PUMP_PIN, OUTPUT);
  pinMode(ReadUVintensity, INPUT);
  bme.begin(0x76);    //Begin the sensor
  aplyCmd();
  Serial.begin(9600);
  Serial.println("Adafruit BME280 test:");
  Serial.println("Getting single-ended readings from AIN0..3");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");

  Blynk.begin( auth, ssid , pass );
  PUMP.off();

  // read sensor every 3s
  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful never to exceed VDD +0.3V max, or to
  // exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may destroy your ADC!
  //                                                                ADS1015  ADS1115
  //                                                                -------  -------
  // ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  // ads.setGain(GAIN_ONE);           // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
  ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
  // ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
  // ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
  // ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV
  ads.begin();
  startTimers();
  timer.setInterval(3000L, UVsensors);
  timer.setInterval(3000L, ReadSensors);
  timer.setInterval(3000L, soilSensor);
}
void UVsensors()
{
  int16_t ReadUVintensity;
  ReadUVintensity = ads.readADC_SingleEnded(1);

  int uvLevel = ReadUVintensity;

  float outputVoltage = 5.0 * uvLevel / 1024;
  float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);
  Serial.print("UVAnalogOutput: ");
  Serial.print(uvLevel);

  Serial.print(" OutputVoltage: ");
  Serial.print(outputVoltage);

  Serial.print(" uvIntensity: ");
  Serial.print(uvIntensity);
  Serial.println(" mW/cm^2");
  
  Blynk.virtualWrite(V6, uvLevel);
  Blynk.virtualWrite(V7, outputVoltage);
  Blynk.virtualWrite(V8, uvIntensity);

}
void soilSensor()
{
  int16_t soil1;

  soil1 = ads.readADC_SingleEnded(0);
   int i = 0;
  soil1 = 0;
  for (i = 0; i < 10; i++)  //
  {
    soil1 += analogRead(soil1); 
   // delay(20);   
  }
  soil1 = soil1 / (i);
  soil1 = map(soil1, 1023, 0, 0, 100);
  Serial.print("soil1: ");
  Serial.print(soil1);
  Serial.println(" % ");
  
  Blynk.virtualWrite(V9, soil1);

}
void ReadSensors(void)
{
  //Read values from the sensor:
  pressure = bme.readPressure();
  temperature = bme.readTemperature();
  Absolutehumidity = bme.readHumidity ();
  altimeter = bme.readAltitude (SEALEVELPRESSURE_HPA);
  //Print values to serial monitor:
  Serial.print(F("Pressure: "));
  Serial.print(pressure);
  Serial.print(" hPa");
  Serial.print("\t");
  Serial.print(("Temp: "));
  Serial.print(temperature);
  Serial.print(" °C");
  Serial.print("\t");
  Serial.print(" Humidity: ");
  Serial.print( Absolutehumidity ); // this should be adjusted to your local forcase
  Serial.println(" % ");
  Serial.print(" Altimeter: ");
  Serial.print( altimeter ); // this should be adjusted to your local forcase
  Serial.println(" m ");
  //delay(2000); //Update every 5 sec
}
BLYNK_WRITE(4)
{
  int i = param.asInt();
  if (i == 1)
  {
    pumpStatus = !pumpStatus;
    aplyCmd();
  }
}

void getSoilMoist(void)
{
  int i = 0;
  soilMoist = 0;
  for (i = 0; i < 10; i++)  //
  {
    soilMoist += analogRead(SOIL_MOIST_1_PIN);
    delay(20);
  }
  soilMoist = soilMoist / (i);
  soilMoist = map(soilMoist, 1023, 0, 0, 100);

}

void aplyCmd()
{
  if (pumpStatus == 1)
  {
    Blynk.notify("pump ON");
    digitalWrite(PUMP_PIN, LOW);
    PUMP.on();
  }

  else {
    digitalWrite(PUMP_PIN, HIGH);
    PUMP.off();
  }
}
void autoControlPlantation(void)
{
  if (soilMoist < DRY_SOIL)
  {
    turnPumpOn();
  }
}
void turnPumpOn()
{
  pumpStatus = 1;
  aplyCmd();
  delay (TIME_PUMP_ON * 1000);
  pumpStatus = 0;
  aplyCmd();
}
void startTimers(void)
{
  timer.setInterval(READ_SOIL_HUM_TM * 1000, getSoilMoist);
  timer.setInterval(SEND_UP_DATA_TM * 1000, sendUptime);
  timer.setInterval(AUTO_CTRL_TM * 1000, autoControlPlantation);
}
void sendUptime()
{

  Blynk.virtualWrite(V1, pressure / 100);   // write pressure to V1 value display widget
  Blynk.virtualWrite(V2, temperature);  // write temperature to V2 value display widget
  Blynk.virtualWrite(V3, altimeter);    // write altimeter to V3 value display widget
  Blynk.virtualWrite(V4, soilMoist);
  Blynk.virtualWrite(V5, Absolutehumidity);


}
void loop() {

  timer.run(); // Initiates SimpleTimer
  Blynk.run();

}
int averageAnalogRead(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0;

  for (int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;

  return (runningValue);


}
//The Arduino Map function but for floats
//From: http://forum.arduino.cc/index.php?topic=3922.0
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

What is the voltage range that your sensor(s) outputs?

@Toro_Blanco 3.3v i think …i have a soil sensor …and a UV sensor ML8511

You will want to confirm this. If the sensor can go as high as 3.3V then I would use ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV if it goes to 5V then I would use ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV

The range of your gain should include the range of your sensor