Hi guys, I have buy this product on Aliexpress :
EC Meter Analog Conductivity Meter
And i have utilized the code present in description in product ( I attached the code ). I see the value of analog is not stabiled ![]()
const byte numReadings = 20; // the number of sample times
byte ECsensorPin = A7; // EC Meter analog output, pin on analog 1
unsigned int AnalogSampleInterval = 25, printInterval = 700; // analog sample interval; serial print interval
unsigned int readings[numReadings]; // the readings from the analog input
byte indexEC = 0; // the index of the current reading
unsigned long AnalogValueTotal = 0; // the running total
unsigned int AnalogAverage = 0, averageVoltage = 0; // the average
unsigned long AnalogSampleTime, printTime;
float temperature = 23.0; // Fixed temperature
float ECcurrent;
void setup() {
// initialize serial communication with computer:
Serial.begin(115200);
pinMode(ECsensorPin,INPUT); //per il sensore TDS
// initialize all the readings to 0:
for (byte thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
AnalogSampleTime = millis();
printTime = millis();
}
void loop() {
if (millis() - AnalogSampleTime > 40U) {
AnalogSampleTime = millis();
// subtract the last reading:
AnalogValueTotal = AnalogValueTotal - readings[indexEC];
// read from the sensor:
readings[indexEC] = analogRead(ECsensorPin);
// add the reading to the total:
AnalogValueTotal = AnalogValueTotal + readings[indexEC];
// advance to the next position in the array:
indexEC = indexEC + 1;
// if we're at the end of the array...
if (indexEC >= numReadings)
// ...wrap around to the beginning:
indexEC = 0;
// calculate the average:
AnalogAverage = AnalogValueTotal / numReadings;
}
/*
Every once in a while, print the information on the serial monitor.
*/
if (millis() - printTime >= printInterval) {
printTime = millis();
averageVoltage = AnalogAverage * (float)5000 / 1024;
// Serial.print("Analog value:");
// Serial.print(AnalogAverage); // analog average, from 0 to 1023
// Serial.print(" Voltage:");
// Serial.print(averageVoltage); // millivolt average, from 0mv to 4995mV
// Serial.print("mV ");
// Serial.print("temp:");
// Serial.print(temperature); // fixed temperature
// Serial.print("^C EC:");
float TempCoefficient = 1.0 + 0.0185 * (temperature - 25.0); // temperature compensation formula: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.0185*(fTP-25.0));
float CoefficientVolatge = (float)averageVoltage / TempCoefficient;
// Serial.print("Coefficient Voltage: ");
// Serial.println(CoefficientVolatge);
if (CoefficientVolatge < 150) Serial.println("No solution!"); // 25^C 1413us/cm<-->about 216mv if the voltage(compensate)<150, that is <1ms/cm, out of the range
else if (CoefficientVolatge > 3300) Serial.println("Out of the range!"); // >20ms/cm, out of the range
else {
if (CoefficientVolatge <= 448) ECcurrent = 6.84 * CoefficientVolatge - 64.32; // 1ms/cm<EC<=3ms/cm
else if (CoefficientVolatge <= 1457) ECcurrent = 6.98 * CoefficientVolatge - 127; // 3ms/cm<EC<=10ms/cm
else ECcurrent = 5.3 * CoefficientVolatge + 2278; // 10ms/cm<EC<20ms/cm
ECcurrent /= 1000; // convert us/cm to ms/cm
Serial.print(ECcurrent, 2); // two decimal
Serial.println("ms/cm");
}
}
}
23:28:13.666 -> ECsensorPin: 589
23:28:13.666 -> ECsensorPin: 1010
23:28:13.712 -> ECsensorPin: 1018
23:28:13.712 -> ECsensorPin: 804
23:28:13.746 -> ECsensorPin: 0
23:28:13.746 -> ECsensorPin: 869
23:28:13.790 -> ECsensorPin: 982
23:28:13.836 -> ECsensorPin: 780
23:28:13.836 -> ECsensorPin: 0
23:28:13.871 -> ECsensorPin: 920
23:28:13.871 -> ECsensorPin: 342
this is Instead the value EC :
23:50:28.444 -> 17.89ms/cm
23:50:29.142 -> 17.75ms/cm
23:50:29.841 -> 18.18ms/cm
23:50:30.542 -> 15.71ms/cm
the value is same if the sensor is in water or in not water.
I not understand why...
I have try the sketch with the sensor disconnected end the value is this:
23:04:26.165 -> Analog value:101 Voltage:493mV Coefficient Voltage: 511.94
23:04:26.201 -> EC: 3.45ms/cm
23:04:26.900 -> Analog value:101 Voltage:493mV Coefficient Voltage: 511.94
23:04:26.900 -> EC:3.45ms/cm
I thank you in advance for your help.





