Soil moisture sensor fails to get a data whenever Bluetooth Low Energy in ESP32 is integrated

Hello Everyone, I am developing a smart farming system where I am using ESP32 Board and a Capacitive Soil Moisture sensor v1.2 in order to get Soil moisture data and send the it  to a Raspberry Pi 3 via Bluetooth Low Energy (BLE). I am able to get other data from other sensors like temperature and humidity sensors and successfuly send them to RPi3 through BLE technology. However, whenever I try to run the Soil Moisture moisture sensor together with the BLE I get a constant value of 0%. As I try to investigate the issue, using the code for Soil Moisture by itself the code works smoothly however, whenever I add the line SerialBT.begin(“ESP32test”) the result will be 0%. I am using ESP32-WROOM-32 and attached here are my codes and the outputs. Thank you in advance guys!

----------------------------------------------------------------------

This is the code for the Soil Moisture Sensor with BLE integrated:

#include “BluetoothSerial.h”
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run make menuconfig to and enable it
#endif
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BluetoothSerial SerialBT;

int btdata; // the data given from the computer
int sensorPin = 2;
int limit=1000;
const int AirValue = 1070; //you need to replace this value with Value_1
const int WaterValue =890; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent=0;

float Celcius=0;
float Fahrenheit=0;

void setup() {
Serial.begin(115200);
SerialBT.begin(“ESP32test”); //Bluetooth device name
Serial.println(“The device started, now you can pair it with bluetooth!”);

sensors.begin();

}

void loop() {
int btdata; // the data given from the computer
//use the functions which are supplied by library.

soilMoistureValue = analogRead(sensorPin);
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue,WaterValue, 0, 100);

sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);

if(soilMoistureValue< limit)
{
Serial.println("Soil Moisture= 100% " “Temperature=”+String(Celcius)+"C "+ “Temperature=” +String(Fahrenheit)+“F”);
SerialBT.print("Soil Moisture= 100% " “Temperature=”+String(Celcius)+"C "+ “Temperature=” +String(Fahrenheit)+“F”);
}
else if(soilMoistureValue >AirValue)
{
Serial.println("Soil Moisture= 0% " “Temperature=”+String(Celcius)+"C "+ “Temperature=” +String(Fahrenheit)+“F” );
SerialBT.print("Soil Moisture= 0% " “Temperature=”+String(Celcius)+"C “+ “Temperature=” +String(Fahrenheit)+“F” );
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.println(“Soil Moisture=”+ String(soilmoisturepercent) +”% " “Temperature=”+String(Celcius)+"C “+ “Temperature=” +String(Fahrenheit)+“F” );
Serial.println(” “);
SerialBT.print(“Soil Moisture=”+ String(soilmoisturepercent) +”% " “Temperature=”+String(Celcius)+"C “+ “Temperature=” +String(Fahrenheit)+“F” );
SerialBT.print(” ");

}

//
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(2000);

}

//----------------------------------------------------------------------

This is the code for the Soil Moisture and Temp Sensor without BLE integrated*

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int sensorPin = 4;
int limit=1000;
const int AirValue = 1070; //you need to replace this value with Value_1
const int WaterValue =890; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent=0;
float Celcius=0;
float Fahrenheit=0;

void setup() {
Serial.begin(115200);

sensors.begin();
}

void loop() {

soilMoistureValue = analogRead(sensorPin);
//Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue,WaterValue, 0, 100);

sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);

if(soilMoistureValue< limit)
{
Serial.println("Soil Moisture= 100% " “Temperature=”+String(Celcius)+"C "+ “Temperature=” +String(Fahrenheit)+“F”);
}
else if(soilMoistureValue >AirValue)
{
Serial.println("Soil Moisture= 0% " “Temperature=”+String(Celcius)+"C “+ “Temperature=” +String(Fahrenheit)+“F” );
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(“Soil Moisture=”+ String(soilmoisturepercent) +”% " “Temperature=”+String(Celcius)+"C “+ “Temperature=” +String(Fahrenheit)+“F” );
Serial.println(” ");

}
delay(1000);
}

The result when BLE is not integrated in the system

Integrating BLE, the soil moisture don’t have the data

Hi @engineerphxjp,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our community organized so users can more easily find information.

As you’ll notice, your topic is now here in the Project Development Help and Advice board. No action is needed on your part; you can continue the conversation as normal here.

Cheers!