getMedianNum is Error! Can someone help me?s Can some one solve? I add code already

How do I solve?

I moved your topic to an appropriate forum category @gritsoonjun.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an essential part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

Hello gritsoonjun

We need some additional information.
Post your sketch, well formated, with well-tempered comments and in so called code tags "< code >" and a real schematic to see how we can help.

Have a nice day and enjoy coding in C++.

#include <PCF8563.h>
#include "GravityTDS.h"
#include <EEPROM.h>

PCF8563 pcf;

//TdsSensor#define TdsSensor A1
#define VREF 5.0
#define SCOUNT 30

#define TdsSensor A0
int analogBuffer[SCOUNT];
int analogBufferTemp[SCOUNT];
int analogBufferIndex = 0, copyIndex = 0;
float averageVoltage = 0, tdsValue = 0, temperature = 25;

//WaterPump
#define WaterPump1 2
#define WaterPump2 4

//OxygenPump
#define OxygenPump1 7
#define OxygenPump2 8

//MedicinePump
#define MedicinePump1 12
#define MedicinePump2 13

void setup() {
  Serial.begin(9600);
  Wire.begin();
  pinMode(WaterPump1,OUTPUT);
  pinMode(WaterPump2,OUTPUT);

  pinMode(OxygenPump1,OUTPUT);
  pinMode(OxygenPump2,OUTPUT);

  pinMode(MedicinePump1,OUTPUT);
  pinMode(MedicinePump2,OUTPUT);

  pinMode(TdsSensor,INPUT);

  pcf.setYear(0);
  pcf.setMonth(0);
  pcf.setDay(0);
  pcf.setHour(0);
  pcf.setMinut(0);
  pcf.setSecond(0);

  pcf.startClock();

}

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(TdsSensor);    //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 / 4096.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;

      if (tdsValue < 300) {
        Serial.print("Excellent; TDS Value:");
        Serial.print(tdsValue, 0);
        Serial.println("ppm");

        digitalWrite(WaterPump1, HIGH);
        digitalWrite(WaterPump2, LOW);

      }
      else if (tdsValue < 600) {
        Serial.print("Good; TDS Value:");
        Serial.print(tdsValue, 0);
        Serial.println("ppm");

        digitalWrite(WaterPump1, HIGH);
        digitalWrite(WaterPump2, LOW);

      }
      else if (tdsValue < 900) {
        Serial.print("Fair; TDS Value:");
        Serial.print(tdsValue, 0);
        Serial.println("ppm");

        digitalWrite(WaterPump1, HIGH);
        digitalWrite(WaterPump2, LOW);

      }
      else if (tdsValue < 1000) {
        Serial.print("Poor; TDS Value:");
        Serial.print(tdsValue, 0);
        Serial.println("ppm");

        digitalWrite(WaterPump1, HIGH);
        digitalWrite(WaterPump2, HIGH);
      
      }
      else if (tdsValue = 1000) {
        Serial.print("Unacceptable; TDS Value:");
        Serial.print(tdsValue, 0);
        Serial.println("ppm");
        
        digitalWrite(WaterPump1, HIGH);
        digitalWrite(WaterPump2, HIGH);

      }
      else {}

    }
  }
}

here

The function "getMedianNum()" is not defined in your sketch. You have to define the function or include a library that defines the function.

I have had good luck with the "MedianFilterLib" by Luis Llamas, available from the Library Manager.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.