so is it a 1115 or a 1015? This makes a big difference.
They both would be connected to the same pins as the BME, as they both use i2C communication.
It may be helpful for us if you provided a full wiring. diagram of your board and sensors.
so is it a 1115 or a 1015? This makes a big difference.
They both would be connected to the same pins as the BME, as they both use i2C communication.
It may be helpful for us if you provided a full wiring. diagram of your board and sensors.
ADS1115 i have , look in my code ā¦ i dont have any diagramā¦this projekt ist for my little garden in balkonā¦i will make tommorow some picturesā¦momentan the code work complete but the UV values are wrongā¦
however I want to connect the UV sensor through ads1115
Well title and following posts state ads1015.
It is hard to help when things constantly change, and the wrong information is given. I think I will step back for a bit until you get things straightened out.
yes I apologize.
Youāre right the first time I thought I had ADS1015 but then I looked better at the order on ebay and saw that it is ADS1115ā¦
I realized to late
Adafruit_ADS1115 ads(0x48);
ads.begin();
well without having the proper hardware to test, this may/may not work. I commented out the pump parts as they do not make sense to me. I would try it without them first, and then add them back in after you verify sensors are working.
Also, if things are not wired correctly (to sensors and ESP), none of it will work. As mentioned the BME and ADS are both use I2C communication, so I would expect them to be wired to the I2C pins on the ESP (SDA is pin D2, SLC is pin D1).
Also, take note of the warning before you set the gain for the ADS1115.
Good Luck!
/*
The ML8511 UV Sensor outputs an analog signal in relation to the amount of UV light it detects.
Connect the following ML8511:
3V3 = 3v3 pin on ESP and to A2 on ADS1115
OUT = A1 on ADS1115
GND = GND on ADS1115 or ESP
EN = 3v3 pin on ESP
On the ADS1115 the VDD Pin Should be connected to the 5V pin on ESP
This example uses a neat trick. Analog to digital conversions rely completely on VCC. We assume
this is 5V but if the board is powered from USB this may be as high as 5.25V or as low as 4.75V:
http://en.wikipedia.org/wiki/USB#Power Because of this unknown window it makes the ADC fairly inaccurate in most cases. To fix this, we use the very accurate onboard 3.3V reference (accurate within 1%). So by doing an ADC on the 3.3V pin (ADS1115 A2) and then comparing this against the reading from the sensor we can extrapolate
a true-to-life reading no matter what VIN is (as long as it's above 3.4V).
*/
#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 4 //D2 Pin is GPIO4 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 soil2;
int soilMoist = 0;
boolean pumpStatus = 0;
int timePumpOn = 1;
long sampleTimingSeconds = 20;
long startTiming = 0;
long elapsedTime = 0;
Adafruit_ADS1115 ads1115;
Adafruit_BME280 bme;
SimpleTimer timer;
void setup() {
pinMode(PUMP_PIN, OUTPUT);
pinMode(SOIL_MOIST_1_PIN, INPUT);
bme.begin(); //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)
ads1115.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
ads1115.begin();
//startTimers();
timer.setInterval(3000L, UVsensors);
timer.setInterval(3000L, ReadSensors);
timer.setInterval(3000L, soilSensor);
}
void UVsensors()
{
int uvLevel = averageAnalogReadUV();
int refLevel = averageAnalogReadREF();
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float outputVoltage = 3.3 / refLevel * uvLevel;
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
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()
{
int i = 0;
soil2 = 0;
for (i = 0; i < 10; i++) //
{
soil2 += ads1115.readADC_SingleEnded(0);
// delay(20);
}
soil2 = soil2 / (i);
soil2 = map(soil2, 32767, 0, 0, 100); //16 bit resolution is 65536 (2^16), ads1115 uses half for positive range and half for negative range
Serial.print("soil2: ");
Serial.print(soil2);
Serial.println(" % ");
Blynk.virtualWrite(V9, soil2);
}
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 ");
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(V5, Absolutehumidity);
//delay(2000); //Update every 5 sec
}
/*
BLYNK_WRITE(V15)
{
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);
Blynk.virtualWrite(V4, soilMoist);
}
/*
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()
{
}
*/
void loop() {
timer.run(); // Initiates SimpleTimer
Blynk.run();
}
//Takes an average of readings on a UV Pin
//Returns the average
int averageAnalogReadUV()
{
byte numberOfReadings = 8;
unsigned int runningValue = 0;
for(int x = 0 ; x < numberOfReadings ; x++)
runningValue += ads1115.readADC_SingleEnded(1);
runningValue /= numberOfReadings;
return(runningValue);
}
//Takes an average of readings on a REF Pin
//Returns the average
int averageAnalogReadREF()
{
byte numberOfReadings = 8;
unsigned int runningValue = 0;
for(int x = 0 ; x < numberOfReadings ; x++)
runningValue += ads1115.readADC_SingleEnded(2);
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;
}
You do realise that I2C is a bus, and that (at least in theory) you can have upto 127 devices connected to the two I2C pins?
The only caveat is that each device on the bus must have its own unique address and most I2C devices only allow a small range of addresses to be selected.
Pete.
So after a little reading/research. It appears the ADS1115 has a āPrecision Reference Voltageā built in. So, the whole taking a reference reading on the 3V3 pin is unnecessary.
Also, since it uses this āPrecision Reference Voltageā the reading are fairly stable as well. So we can do away with the averaging part as well. This is for both the UV Sensor and the Soil Sensor
Below is the code with these portions removed. See if one gives better results (although you do not really have a reference to calibrate/compare against for the UV Sensor).
/*
The ML8511 UV Sensor outputs an analog signal in relation to the amount of UV light it detects.
Connect the following ML8511:
3V3 = 3v3 pin on ESP OR (not Both) Vin = 5V on ESP
OUT = A1 on ADS1115
GND = GND on ADS1115 or ESP
EN = 3v3 pin on ESP
On the ADS1115 the VDD Pin Should be connected to the 5V pin on ESP
*/
#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 4 //D2 Pin is GPIO4 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 soil2;
int soilMoist = 0;
boolean pumpStatus = 0;
int timePumpOn = 1;
long sampleTimingSeconds = 20;
long startTiming = 0;
long elapsedTime = 0;
Adafruit_ADS1115 ads1115;
Adafruit_BME280 bme;
SimpleTimer timer;
void setup() {
pinMode(PUMP_PIN, OUTPUT);
pinMode(SOIL_MOIST_1_PIN, INPUT);
bme.begin(); //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)
ads1115.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
ads1115.begin();
//startTimers();
timer.setInterval(3000L, UVsensors);
timer.setInterval(3000L, ReadSensors);
timer.setInterval(3000L, soilSensor);
}
void UVsensors()
{
int uvLevel = ads1115.readADC_SingleEnded(1);
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float outputVoltage = (uvLevel * .125)/1000; //(Use 1 bit voltage referenced in the gain setting)
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
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()
{
int i = 0;
soil2 += ads1115.readADC_SingleEnded(0);
soil2 = map(soil2, 32767, 0, 0, 100); //16 bit resolution is 65536 (2^16), ads1115 uses half for positive range and half for negative range
Serial.print("soil2: ");
Serial.print(soil2);
Serial.println(" % ");
Blynk.virtualWrite(V9, soil2);
}
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 ");
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(V5, Absolutehumidity);
//delay(2000); //Update every 5 sec
}
/*
BLYNK_WRITE(V15)
{
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);
Blynk.virtualWrite(V4, soilMoist);
}
/*
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()
{
}
*/
void loop() {
timer.run(); // Initiates BlynkTimer
Blynk.run();
}
//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;
}
Thanks @Toro_Blanco the code work nowā¦the UV sensor have normal value now 0.08 mw/cm2 . thanks a lot . I will make some pictures and some video when is finish ā¦
@Toro_Blanco you know why i the soil moisture sensor read the same value 99% ā¦ I tried to write again the map Soil but the same resultā¦ i Research in internet but nothing to help me ā¦ my soil moisture ist conected with 3.3v and the result ist 99% ā¦when i conect the sensor with 5v i have 0%ā¦whyyy???
how to read the percentages from soil moisture ??? I have capacitive soil moisture v1.2 and i have connected to 3.3v ā¦ and the code ist :
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);
Blynk.virtualWrite(V4, soilMoist);
The values are 99% always inside and out the pot of the plant ā¦
whyyyyy? What i make wrong ???
Somebody can help me ???
@Mario_Alexandru Iāve merged your two topics together. Please keep the discussion on one place rather than spamming the forum with the same question in multiple topics.
I would start your debugging process by adding serial prints of the soilMoist
variable within your
for
loop , then before each operation to change its value after the for
loop has executed. You may also want to serial print the value of i
as well in the same locations.
Pete.
What you mind ? I must to delete i ??? Oder ?
@Mario_Alexandru Iām not sure if this question was directed at mke, but if it is then Iām afraid I donāt understand what it is that youāre asking.
Pete.
void getSoilMoist(void)
{
int i = 0;
soilMoist = 0;
for (i = 0; i < 10; i++) //
{
Serial.print("i = ");
Serial.println(i);
Serial.print("Location A - soilMoist = ");
Serial.println(soilMoist);
soilMoist += analogRead(SOIL_MOIST_1_PIN);
Serial.print("Location B - soilMoist = ");
Serial.println(soilMoist);
delay(20);
}
Serial.print("Loop ended, soilmoist = ");
Serial.print(soilMoist);
soilMoist = soilMoist / (i);
Serial.print("soilMoist/i = ");
Serial.println(soilMoist);
soilMoist = map(soilMoist, 1023, 0, 0, 100);
Serial.print("After mapping soilMoist = ");
Serial.println(soilMoist);
Blynk.virtualWrite(V4, soilMoist);
}
Pete.
something is wrong with my map i thinkā¦
The code wasnāt intended to change the values, simply to allow you to see what was happening to the values in the serial monitor.
Maybe copying and pasting your serial monitor output would be the sensible approach?
Pete.
this Read with my code
Pressure: 96560.12 hPa Temp: 23.17 Ā°C Humidity: 51 %
Altimeter: 420 m
soil1: 99 %
soilMoist: 99 %
and when i change with your cod look :
UVAnalogOutput: 7920 OutputVoltage: 0.99 uvIntensity: 0.00 mW/cm^2
Pressure: 96562.68 hPa Temp: 23.36 Ā°C Humidity: 50 %
Altimeter: 420 m
soil1: 99 %
i = 0
Location A - soilMoist = 0
Location B - soilMoist = 9
i = 1
Location A - soilMoist = 9
Location B - soilMoist = 21
i = 2
Location A - soilMoist = 21
Location B - soilMoist = 33
i = 3
Location A - soilMoist = 33
Location B - soilMoist = 36
i = 4
Location A - soilMoist = 36
Location B - soilMoist = 45
i = 5
Location A - soilMoist = 45
Location B - soilMoist = 57
i = 6
Location A - soilMoist = 57
Location B - soilMoist = 60
i = 7
Location A - soilMoist = 60
Location B - soilMoist = 69
i = 8
Location A - soilMoist = 69
Location B - soilMoist = 81
i = 9
Location A - soilMoist = 81
Location B - soilMoist = 84
Loop ended, soilmoist = 84soilMoist/i = 8
After mapping soilMoist = 99
Now i will put in water and he read :
Pressure: 96585.75 hPa Temp: 23.24 Ā°C Humidity: 51 %
Altimeter: 418 m
i = 0
Location A - soilMoist = 0
Location B - soilMoist = 3
i = 1
Location A - soilMoist = 3
Location B - soilMoist = 6
i = 2
Location A - soilMoist = 6
Location B - soilMoist = 16
i = 3
Location A - soilMoist = 16
Location B - soilMoist = 19
i = 4
Location A - soilMoist = 19
Location B - soilMoist = 24
i = 5
Location A - soilMoist = 24
Location B - soilMoist = 27
i = 6
Location A - soilMoist = 27
Location B - soilMoist = 36
i = 7
Location A - soilMoist = 36
Location B - soilMoist = 48
i = 8
Location A - soilMoist = 48
Location B - soilMoist = 60
i = 9
Location A - soilMoist = 60
Location B - soilMoist = 63
Loop ended, soilmoist = 63soilMoist/i = 6
After mapping soilMoist = 99
UVAnalogOutput: 7920 OutputVoltage: 0.99 uvIntensity: 0.00 mW/cm^2
Pressure: 96586.42 hPa Temp: 23.24 Ā°C Humidity: 51 %
Altimeter: 418 m
soil1: 99 %
i = 0
Location A - soilMoist = 0
Location B - soilMoist = 3
i = 1
Location A - soilMoist = 3
Location B - soilMoist = 7
i = 2
Location A - soilMoist = 7
Location B - soilMoist = 11
i = 3
Location A - soilMoist = 11
Location B - soilMoist = 14
i = 4
Location A - soilMoist = 14
Location B - soilMoist = 18
i = 5
Location A - soilMoist = 18
Location B - soilMoist = 21
i = 6
Location A - soilMoist = 21
Location B - soilMoist = 24
i = 7
Location A - soilMoist = 24
Location B - soilMoist = 28
i = 8
Location A - soilMoist = 28
Location B - soilMoist = 32
i = 9
Location A - soilMoist = 32
Location B - soilMoist = 35
Loop ended, soilmoist = 35soilMoist/i = 3
After mapping soilMoist = 99```