I am having trouble with adding EC sensor codes to PH sensor codes. I don’t know have enough knowledge to code these two sensors. I need help on how to include the EC sensor code to PH sensor code. And also what should not be included in these codes. This EC sensor code does not include temperature sensor and it does not have blynk codes. The PH sensor code has the blynk codes.
This is the code of EC sensor:
#define TdsSensorPin
#define VREF 3.3 // analog reference voltage(Volt) of the ADC
#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 temperature = 25; // current temperature for compensation
// median filtering algorithm
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 setup(){
Serial.begin(115200);
pinMode(TdsSensorPin,INPUT);
}
void loop(){
static unsigned long analogSampleTimepoint = millis();
if(millis()-analogSampleTimepoint > 40U){ //every 40 milliseconds,read the analog value from the ADC
analogSampleTimepoint = millis();
analogBuffer[analogBufferIndex] = analogRead(35); //read the analog value and store 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];
// read the analog value more stable by the median filtering algorithm, and convert to voltage value
averageVoltage = getMedianNum(analogBufferTemp,SCOUNT) * (float)VREF / 1024.0;
//temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0));
float compensationCoefficient = 1.0+0.02*(temperature-25.0);
//temperature compensation
float compensationVoltage=averageVoltage/compensationCoefficient;
//convert voltage value to tds value
tdsValue=(133.42*compensationVoltage*compensationVoltage*compensationVoltage - 255.86*compensationVoltage*compensationVoltage + 857.39*compensationVoltage)*0.5;
//Serial.print("voltage:");
//Serial.print(averageVoltage,2);
//Serial.print("V ");
Serial.print("TDS Value:");
Serial.print(tdsValue,0);
Serial.println("ppm");
}
}
}
This is the code of PH sensor with blynk:
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#include "BlynkEdgent.h"
// ph sensor
#define pHSensorPin 34 //pH meter Analog output to Arduino Analog Input
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
int f; // for float value to string converstion
float val; // also works with double.
char buff2[10];
String valueString = "";
String Value = "";
// ph sensor
void PH_Value()
{
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(34);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*3.3/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Value = dtostrf(phValue, 4, 2, buff2); //4 is mininum width, 6 is precision
Serial.print(Value);
valueString = "";
delay(1000);
Blynk.virtualWrite(V0, 7.06);
}
void setup()
{
Serial.begin(9600);
BlynkEdgent.begin();
delay(2000);
}
void loop()
{
BlynkEdgent.run();
PH_Value();
}
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"
BlynkTimer timer;
void PH_Value()
{
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(GPIO34);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*3.3/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Value = dtostrf(phValue, 4, 2, buff2); //4 is mininum width, 6 is precision
valueString = valueString + Value +",";
Serial.print(Value);
Serial.print(" ");
Serial.println(valueString);
valueString = "";
Blynk.virtualWrite(V0, sensorValue1);
}
void setup() {
Serial.begin(115200);
BlynkEdgent.begin();
}
void loop() {
BlynkEdgent.run;
Blynk.run();
timer.run();
PH_Value();
}
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#include "BlynkEdgent.h"
BlynkTimer timer;
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
int f; // for float value to string converstion
float val; // also works with double.
char buff2[10];
String valueString = "";
String Value = "";
void sensorDataSend()
{
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(GPIO34);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*3.3/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Value = dtostrf(phValue, 4, 2, buff2); //4 is mininum width, 6 is precision
valueString = valueString + Value +",";
Serial.print(Value);
Serial.print(" ");
Serial.println(valueString);
valueString = "";
Blynk.virtualWrite(V0, );
}
void setup() {
Serial.begin(115200);
BlynkEdgent.begin();
timer.setInterval(1000L, sensorDataSend); //timer will run every sec
}
void loop() {
BlynkEdgent.run;
timer.run();
}
C:\Users\ADDESSA\Documents\Arduino\Edgent_ESP32\Edgent_ESP32.ino: In function 'void loop()':
Edgent_ESP32:63:15: error: invalid use of non-static member function 'void Edgent::run()'
BlynkEdgent.run;
~~~~~~~~~~~~^~~
In file included from C:\Users\ADDESSA\Documents\Arduino\Edgent_ESP32\Edgent_ESP32.ino:7:
C:\Users\ADDESSA\Documents\Arduino\Edgent_ESP32\BlynkEdgent.h:97:8: note: declared here
void run() {
^~~
Multiple libraries were found for "WiFi.h"
Used: C:\Users\ADDESSA\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.5\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
invalid use of non-static member function 'void Edgent::run()'
This is the code that I uploaded to my board ESP32-WROOM-DA-Module
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#include "BlynkEdgent.h"
BlynkTimer timer;
unsigned long int avgValue; //Store the average value of the sensor feedback
float b;
int buf[10],temp;
int f; // for float value to string converstion
float val; // also works with double.
char buff2[10];
String valueString = "";
String Value = "";
void sensorDataSend()
{
for(int i=0;i<10;i++) //Get 10 sample value from the sensor for smooth the value
{
buf[i]=analogRead(34);
delay(10);
}
for(int i=0;i<9;i++) //sort the analog from small to large
{
for(int j=i+1;j<10;j++)
{
if(buf[i]>buf[j])
{
temp=buf[i];
buf[i]=buf[j];
buf[j]=temp;
}
}
}
avgValue=0;
for(int i=2;i<8;i++) //take the average value of 6 center sample
avgValue+=buf[i];
float phValue=(float)avgValue*3.3/1024/6; //convert the analog into millivolt
phValue=3.5*phValue; //convert the millivolt into pH value
Value = dtostrf(phValue, 4, 2, buff2); //4 is mininum width, 6 is precision
valueString = valueString + Value +",";
Serial.print(Value);
Serial.print(" ");
Serial.println(valueString);
valueString = "";
Blynk.virtualWrite(V0, 7.06);
}
void setup() {
Serial.begin(115200);
BlynkEdgent.begin();
timer.setInterval(1000L, sensorDataSend); //timer will run every sec
}
void loop() {
BlynkEdgent.run;
timer.run();
}