2987| 1
|
[项目] 看水质 |
本帖最后由 gada888 于 2019-7-17 16:00 编辑 有时候想检测一下水质,可是不想通过串口来看,想更加便携一点,于是通过一个Nokia5110显示屏来看。5100的特点是屏大。显示行数多。================================ 项目使用模块如下: TDS(Total Dissolved Solids),中文名总溶解固体,又称溶解性固体总量,表明1升水中溶有多少毫克溶解性固体。一般来说,TDS值越高,表示水中含有的 溶解物越多,水就越不洁净。因此,TDS值的大小,可作为反映水的洁净程度的依据之一。 常用的TDS检测设备为TDS笔,虽然价格低廉,简单易用,但不能把数据传给控制系统,做长时间的在线监测,并做水质状况分析。使用专门的仪器,虽然能 传数据,精度也高,但价格很贵。为此,我们专门推出了这款Arduino兼容的TDS传感器,连接至arduino控制器后,就可用于测量水的TDS值。 该产品专为arduino设计,即插即用,使用简单方便。3.3~5.5V的宽电压供电,0~2.3V的模拟信号输出,使得这款产品兼容5V、3.3V控制系统,能非常方便 的接到现成的控制系统中使用。测量用的激励源采用交流信号,可有效防止探头极化,延长探头寿命的同时,也增加了输出信号的稳定性。TDS探头为防水探 头,可长期浸入水中测量。 该产品可应用于生活用水、水培等领域的水质检测。有了这个传感器,就可轻松DIY一套TDS检测仪了,轻松检测水的洁净程度,为你的水质把好关。 输入电压:3.3~5.5V 输出信号:0~2.3V 工作电流: 3~6mA TDS测量范围:0~1000ppm TDS测量精度:±10% F.S.(25℃) 写的测试代码 [mw_shl_code=applescript,true]// made by gada888 #include <SPI.h> #include <Adafruit_GFX.h> #include <Adafruit_PCD8544.h> #define TdsSensorPin A0 #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; /////////////////////////////////////////////////////////// Adafruit_PCD8544 display = Adafruit_PCD8544(13, 11, 5, 4, 3); void setup() { Serial.begin(9600); pinMode(TdsSensorPin,INPUT); // Display initialisieren display.begin(); display.setContrast(60); display.clearDisplay(); // clears the screen and buffer } void loop() { display.setTextSize(1); set_text(11,0,"gada888!",BLACK); delay(500); display.setTextSize(1); set_text(1,20,"TDS:",BLACK); delay(500); display.setCursor(20,20); display.print(""); //this will be written on the LCD display.println(tdsValue); display.display(); delay(1000); // Ein kleines bisschen Scroll-Text-Magie int x=0; for(int i=0;i<(5.6*8);i++){ set_text(x,40,"gada888@msn.com",BLACK); delay(i==0?1000:100); if(i<(5.6*8)-1)set_text(x,40,"gada888@msn.com",WHITE); if((i)<(2.74*8))x-=1;else x+=1; } delay(250); display.clearDisplay(); // Display wieder löschen 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<SCOUNT;copyIndex++) analogBufferTemp[copyIndex]= analogBuffer[copyIndex]; averageVoltage = getMedianNum(analogBufferTemp,SCOUNT) * (float)VREF / 1024.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: fFinalResult(25^C) = fFinalResult(current)/(1.0+0.02*(fTP-25.0)); 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 //Serial.print("voltage:"); //Serial.print(averageVoltage,2); //Serial.print("V "); Serial.print("TDS Value:"); Serial.print(tdsValue,0); Serial.println("ppm"); } } int getMedianNum(int bArray[], int iFilterLen) { int bTab[iFilterLen]; for (byte i = 0; i<iFilterLen; i++) bTab = bArray; int i, j, bTemp; for (j = 0; j < iFilterLen - 1; j++) { for (i = 0; i < iFilterLen - j - 1; i++) { if (bTab > bTab[i + 1]) { bTemp = bTab; bTab = 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 set_text(int x,int y,String text,int color){ display.setTextColor(color); display.setCursor(x,y); display.println(text); display.display(); } [/mw_shl_code] 连线图 |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed