本帖最后由 王大富 于 2021-2-23 14:12 编辑
1.首先得到测试仪器的校正系数,机械校正系数=已知校正溶液的电导率/实际测试得到的电导率, 两种标准溶液
compECsolution = 1.413*(1.0+0.0185*(temperature-25.0)); kvalueLow = compECsolution/(1000.0*voltage/820.0/200.0);
compECsolution = 12.88*(1.0+0.0185*(temperature-25.0)); kvalueHigh = compECsolution//(1000.0*voltage/820.0/200.0); 反过来,溶液真实电导率值=机械校正系数*溶液实测电导率值;
2.其次,通过Arduino模拟串口读取电导率传感器的电压值
voltage=analogRead(EC_PIN) / 1024.0 * 5000,单位为mV,
然后通过已知的电压值和电导率的关系计算T温度下的溶液实测电导率值
rawEC = 1000 * voltage / 820.0 / 200.0,
再然后根据第一步中得到的机械校正系数计算T温度下测试溶液真实电导率值
value = rawEC * (1, kvalueLow 或 kvalueHigh);
3.最后通过温度修正将T温度下的真实电导率标准化为25摄氏度下的溶液真实电导率
temperature = dht.getTemperature();ecValue = value / (1.0 + 0.0185 * (temperature - 25.0)); - #include "Arduino.h"
- #include "DHTesp.h" //温度DHT11模块函数库
- #define EC_PIN A0
- float voltage, ecValue, temperature = 25.0;
- float _kvalueLow = 1, _kvalueHigh = 1, _kvalue = 1, rawEC, valueTemp, value;
- DHTesp dht; //温度
- void setup()
- {
- pinMode(A0, INPUT);
- Serial.begin(115200);
- dht.setup(3, DHTesp::DHT11); //温湿度模块DHT11初始化,D4脚位
- }
- void loop()
- {
- _kvalue = 1;
- static unsigned long timepoint = millis();
- if (millis() - timepoint > 1000U)
- { timepoint = millis();
- Serial.print("A0="); Serial.print(analogRead(EC_PIN));
- voltage = analogRead(EC_PIN) / 1024.0 * 5000;//电压毫伏
- Serial.print(" voltage="); Serial.print(voltage);
- rawEC = 1000 * voltage / 820.0 / 200.0;//原始电导率,电压与电导率的线性比列关系,有先前实验得到
- Serial.print(" rawEC="); Serial.print(rawEC);
- value = rawEC * _kvalue;//初始不计算仪器引起的误差
- if (valueTemp > 2.5) {
- _kvalue = _kvalueHigh;//高校正值
- }
- else if (valueTemp < 2.0) {
- _kvalue = _kvalueLow;//低校正值
- }
- value = rawEC * _kvalue;//校正机械误差后的电导率,_kvalueLow和_kvalueHigh由实际的电导率比上测试得到的电导率
- temperature = dht.getTemperature();//校正后的电导率
- ecValue = value / (1.0 + 0.0185 * (temperature - 25.0));//修正后的电导率,修正完以后都是25摄氏度下的数据,因此用除
- Serial.print(" temperature:");Serial.print(temperature, 1);Serial.print("^C EC:");
- Serial.print(ecValue, 2);Serial.println("ms/cm");
- }
- }
- float readTemperature()
- {
- //add your code here to get the temperature from your temperature sensor
- }
- //用于计算机械误差
- // if()
- // {if (rawEC>0.9 && rawEC<1.9)
- // {compECsolution = 1.413*(1.0+0.0185*(temperature-25.0));//通过温度校正后的到的真实值
- // kvalueLow = compECsolution/(1000.0*voltage/820.0/200.0);//机械校正系数为已知校正溶液的电导率比上实际测试得到的电导率
- // round(kvalueLow,2);}
- // else if (rawEC>9 && rawEC<16.8)
- // {compECsolution = 12.88*(1.0+0.0185*(temperature-25.0));
- // kvalueHigh = compECsolution//(1000.0*voltage/820.0/200.0);//反过来如果已知了测试值想要得到真实值则应该乘以机械修正系数
- // round(kvalueHigh,2);}
- // }
复制代码
|