内容介绍
内容介绍
- 任务:水质监控系统
用FireBeetle ESP32-E开发板作为控制单元,观察养殖水质参数(温度/浊度/tds/pH值/电位/溶解氧中两项指标以上)的变化,并能把数据上传到IoT网站上,可实时动态显示监测水质的变化情况。
我设计的基于FireBeetle ESP32-E的水质检测系统,使用TDS和浊度两款传感器。并把数据上传到IoT网站上,可实时动态显示监测水质的变化情况。还可以通过IIC的一块小屏幕看到水质的数据和水质的变化。 - 各个功能说明 先介绍一下tds传感器,TDS(Total Dissolved Solids),中文名总溶解固体,又称溶解性固体总量,表明1升水中溶有多少毫克溶解性固体。一般来说,TDS值越高,表示水中含有的溶解物越多,水就越不洁净。因此,TDS值的大小,可作为反映水的洁净程度的依据之一。详细代码:
/*************************************************** DFRobot Gravity: Analog TDS Sensor / Meter For Arduino <https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244> Created 2017-8-22 By Jason <jason.ling@dfrobot.com@dfrobot.com> GNU Lesser General Public License. See <https://www.gnu.org/licenses/> for details. All above must be included in any redistribution /***********Notice and Trouble shooting*************** 1. This code is tested on Arduino Uno and Leonardo with Arduino IDE 1.0.5 r2 and 1.8.2. 2. More details, please click this link: <https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244> ****************************************************/ #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; 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(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[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(9600); //Baud rate: 9600 } void loop() { int sensorValue = analogRead(A0);// read the input on analog pin 0: float voltage = sensorValue * (5.0 / 1024.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): Serial.println(voltage); // print out the value you read: delay(500); }
使用一个0.96的IIC小屏幕进行显示。
主控采用的是FireBeetle ESP32-E深度支持ArduinoIDE,还可以使用MicroPython、Mind+图形化等编程环境来操控板载硬件资源。FireBeetle ESP32-E 最多有 22 个物理 GPIO,其中 34-39 号管脚仅作为输入管脚,其他的可以作为输入和输出管脚。所有逻辑电压均为 3.3V。 - 效果展示
将TDS传感器放到水中,将浊度传感器用纸挡住。通过屏幕可以显示TDS的数值和浊度的数值。通过手机APP可以看到水质的情况。
附件下载
funpack2-3.ino
团队介绍
个人
评论
0 / 100
查看更多