#define TdsSensorPin A1 #define VREF 5.0 // 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,copyIndex = 0; float averageVoltage = 0,tdsValue = 0,temperature = 25; int waterbomb =D0; const int ledPin = 25; void setup() { Serial.begin(115200); pinMode(TdsSensorPin,INPUT); pinMode(waterbomb,OUTPUT); pinMode(ledPin,OUTPUT); } void loop() { calidad(); } int getMedianNum(int bArray[], int iFilterLen) { int bTab[iFilterLen]; for (byte i = 0; 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; } ////////////////////////////CALIDAD DE AGUA void calidad(){ 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 into the buffer analogBufferIndex++; if(analogBufferIndex == SCOUNT) analogBufferIndex = 0; } static unsigned long printTimepoint = millis(); if(millis()-printTimepoint > 800U) { printTimepoint = millis(); for(copyIndex=0;copyIndex