Hello Blynkers I’m makin an IOT based Water Quality Monitoring System for which I’m using an ESP-32,I’ve pasted my code below I’m using BlynkSimpleESP32.h library version 1.3.2, and using my laptop for connectivity. I’m getting this error message again and again. Can anyone please help me out.(attaching the error message after the code).
Code:
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "**************" //Paste your credentials here
#define BLYNK_DEVICE_NAME "*****************************" //Paste your credentials here
char auth[] = "*************************5m8a";//Paste auth token you copied
char ssid[] = "******************";///Enter your wifi name
char pass[] = "******************";// Enter wifi password
#define TdsSensorPin 32 // Analog pin for the TDS sensor
#define oneWireBus 4 // GPIO pin for DS18B20 temperature sensor
#define turbiditySensorPin 33 // GPIO pin for Turbidity sensor
#define VREF 3.3
#define SCOUNT 30 // sum of sample point
int analogBuffer[SCOUNT]; // store the analog value in the array, read from ADC
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0;
int copyIndex = 0;
float averageVoltage = 0;
float tdsValue = 0;
float ec = 0;
float temperature = 0;
OneWire oneWire(oneWireBus); // Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature sensor
float calibration_value = 21.34 + 4.5;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10], temp;
float ph_act;
const int EC_Isolator = 2; // EC isolator GPIO pin
const int EC_GND_Wire = 15; // EC ground wire GPIO pin
// LCD Configuration
LiquidCrystal_I2C lcd(0x27, 20, 4); // Set the LCD I2C address and dimensions
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Blynk.begin(auth, ssid, pass);
pinMode(34, INPUT); // GPIO pin for pH sensor (Adjust pin if needed)
pinMode(TdsSensorPin, INPUT);
pinMode(turbiditySensorPin, INPUT);
pinMode(EC_Isolator, OUTPUT); // Set EC isolator pin as output
pinMode(EC_GND_Wire, OUTPUT); // Set EC ground wire pin as output
sensors.begin();
// LCD Initialization
lcd.begin();
lcd.backlight();
lcd.setCursor(4, 0);
lcd.print("Water Quality");
lcd.setCursor(6, 1);
lcd.print("Monitoring");
delay(2000); // Show for 2 seconds
lcd.clear();
Serial.println("Water Quality Monitoring"); // Display "Water Quality Monitoring" in Serial Monitor
}
void loop() {
Blynk.run();
// EC Isolator
digitalWrite(EC_Isolator, HIGH); // Turn on EC isolator
digitalWrite(EC_GND_Wire, LOW); // Ensure EC ground wire is LOW
ph_sensor();
// Turn off EC Isolator and switch to EC ground wire
digitalWrite(EC_Isolator, LOW); // Turn off EC isolator
digitalWrite(EC_GND_Wire, HIGH); // Switch to EC ground wire
delay(1000);
// TDS and DS18B20 Sensor Reading
sensors.requestTemperatures();
temperature = sensors.getTempCByIndex(0);
static unsigned long analogSampleTimepoint = millis();
if (millis() - analogSampleTimepoint > 40U) { // Every 40 milliseconds, read the analog value from the ADC
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(TdsSensorPin); // Read the analog value and store it into the buffer
analogBufferIndex++;
if (analogBufferIndex == SCOUNT)
analogBufferIndex = 0;
}
static unsigned long printTimepoint = millis();
if (millis() - printTimepoint > 800U) {
printTimepoint = millis();
for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++)
analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
averageVoltage = getMedianNum(analogBufferTemp, SCOUNT) * (float)VREF / 4096.0; // Read the analog value more stable by the median filtering algorithm, and convert to voltage value
float compensationCoefficient = 1.0 + 0.02 * (temperature - 25.0); // Temperature compensation formula
float compensationVolatge = averageVoltage / compensationCoefficient; // Temperature compensation
tdsValue = (133.42 * compensationVolatge * compensationVolatge * compensationVolatge - 255.86 * compensationVolatge * compensationVolatge + 857.39 * compensationVolatge) * 0.5; // Convert voltage value to TDS value
ec= ((tdsValue*2)/1000);
Serial.print("TDS:");
Serial.print(tdsValue, 0);
Serial.println("ppm");
Serial.print("EC:");
Serial.print(ec, 0);
Serial.println("ms/cm");
Serial.print("Temperature:");
Serial.print(temperature);
Serial.println("ºC");
// Turbidity Sensor Reading
int turbidity = analogRead(turbiditySensorPin);
float turbidityVoltage = turbidity * (3.3 / 4096.0) * 3;
Serial.print("Turbidity Voltage: ");
Serial.println(turbidityVoltage);
// Displaying on LCD
lcd.setCursor(0, 0);
lcd.print("pH:");
lcd.print(ph_act);
lcd.setCursor(0, 1);
lcd.print("TDS:");
lcd.print(tdsValue, 0);
lcd.print(" ppm");
lcd.setCursor(10, 1);
lcd.print("EC:");
lcd.print(ec, 0);
lcd.print("ms/cm");
lcd.setCursor(0, 2);
lcd.print("Temp:");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 3);
lcd.print("Turbidity:");
lcd.print(turbidityVoltage);
lcd.print(" V");
Blynk.virtualWrite(V0, ph_act);
Blynk.virtualWrite(V1, tdsValue);
Blynk.virtualWrite(V2, ec);
Blynk.virtualWrite(V3, temperature);
Blynk.virtualWrite(V4, turbidityVoltage);
}
}
int getMedianNum(int bArray[], int iFilterLen) {
int bTab[iFilterLen];
for (byte i = 0; i < iFilterLen; i++)
bTab[i] = bArray[i];
int i, j, bTemp;
for (j = 0; j < iFilterLen - 1; j++) {
for (i = 0; i < iFilterLen - j - 1; i++) {
if (bTab[i] > bTab[i + 1]) {
bTemp = bTab[i];
bTab[i] = bTab[i + 1];
bTab[i + 1] = bTemp;
}
}
}
if ((iFilterLen & 1) > 0)
bTemp = bTab[(iFilterLen - 1) / 2];
else
bTemp = (bTab[iFilterLen / 2] + bTab[iFilterLen / 2 - 1]) / 2;
return bTemp;
}
void ph_sensor()
{
// pH Sensor Reading
for (int i = 0; i < 10; i++) {
buffer_arr[i] = analogRead(34); // Use GPIO34 for pH sensor
delay(30);
}
for (int i = 0; i < 9; i++) {
for (int j = i + 1; j < 10; j++) {
if (buffer_arr[i] > buffer_arr[j]) {
temp = buffer_arr[i];
buffer_arr[i] = buffer_arr[j];
buffer_arr[j] = temp;
}
}
}
avgval = 0;
for (int i = 2; i < 8; i++) {
avgval += buffer_arr[i];
}
float volt = (float)avgval * 3.3 / 4096.0 / 6;
ph_act = -5.70 * volt + calibration_value;
Serial.print("pH Val: ");
Serial.println(ph_act);
delay(1000);
}
Error Message:
In file included from C:\Users\DELL\Desktop\Water_Quality_Monitoring\Water_Quality_Monitoring.ino:7:
c:\Users\DELL\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h: In member function 'void BlynkWifi::connectWiFi(const char*, const char*)':
c:\Users\DELL\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:39:14: error: 'class WiFiClass' has no member named 'mode'
WiFi.mode(WIFI_STA);
^~~~
c:\Users\DELL\Documents\Arduino\libraries\Blynk\src/BlynkSimpleEsp32.h:39:19: error: 'WIFI_STA' was not declared in this scope
WiFi.mode(WIFI_STA);
^~~~~~~~
exit status 1
Compilation error: exit status 1