Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.19 KB | None | 0 0
  1. Readable, who the fuck needs a black background.
  2.  
  3.  
  4. Hack a Day
  5.  
  6. Projects
  7. Lists
  8. Contests
  9. Stack
  10. More
  11.  
  12. Sign up
  13. Log In
  14.  
  15. Three Dollar EC - PPM Meter [Arduino]
  16.  
  17. A project log for Fly Wars : A Hackers Solution To World Hunger
  18.  
  19. Using Technology And A Hackers Mindset To Increase Food Security For The Coming Billions Last Updated [21/9/2015]
  20. Michael RatcliffeMichael Ratcliffe • 09/04/2015 at 13:56•108 Comments
  21.  
  22. This Blog will Cover How to build a cheap EC meter for your aquaponics/Hydroponics or water quality related projects. We are not going to get into what the ideal value of PPM or EC is, Just cover how to measure and quantify a fluid.
  23.  
  24. We will be using this for the Urine based aquaponics unit, we need to be able to control the strength of the growing fluid in the system but for the person on a budget a EC meter is just to much money. the Solution a $3 EC Meter for any Arduino.
  25.  
  26. You can use this to measure drinking water quality to with a small change to the code and changing R1 [see below].
  27.  
  28. Parts:
  29.  
  30. -MCU of your choice with ADC
  31.  
  32. -DS18B20 waterproof temperature sensor
  33.  
  34. -500 ohm [or 1kohm resistor]
  35.  
  36. -Type A Two Prong american plug to Figure 8
  37.  
  38. -Female Socket for Figure 8 connector
  39.  
  40. So why are we using a plug:
  41.  
  42. -Cheap
  43.  
  44. -Available worldwide
  45.  
  46. -Standard size [makes calibration easy]
  47.  
  48. Use the solid prong one like below and not the one with holes:
  49.  
  50. images.jpg
  51.  
  52. Wiring it up:
  53.  
  54. Note: You want the Solid Prong type plug
  55.  
  56. Do not Plug the pronged plug into the mains
  57.  
  58. Pinout.png
  59.  
  60. Operating Principal
  61.  
  62. PPM is calculated from the EC of a fluid, EC is the inverse of the electrical resistance of the fluid. We are estimating the EC or PPM of a fluid by measuring the resistance between two probes [The plug pins] when the plug is submerged in the liquid of interest.
  63.  
  64. Ec measurement needs to be done using AC or the liquid of interest is polarised and will give bad readings. This has got to be a great example of asking why instead of just accepting a statement as fact, it turns out we can take a very fast DC reading without suffering polarisation. meaning we can make a really cheap EC sensor.
  65.  
  66. Want to use it and dont care how it works? Skip to the main EC code and using the wiring diagram it will work.
  67.  
  68. Temperature Compensation
  69.  
  70. Temperature has an effect on the conductivity of fluids so it is essential that we compensate for this.
  71.  
  72. It is common to use a liner approximation for small temperature changes[1] to convert them to their equivelant EC at 25*C:
  73.  
  74. EC25 = EC /( 1 + a (T - 25) )
  75.  
  76. EC25- Equivelant EC at 25'C
  77.  
  78. EC - Measured EC
  79.  
  80. T- Temperature [Decgrees C] of Measurment
  81.  
  82. a = 0.019 °C [Commonly used for nutrient solutions]
  83.  
  84. Deciding on Value of R1
  85.  
  86. //##################################################################################
  87.  
  88. //----------- Do not Replace R1 with a resistor lower than 300 ohms ------------
  89.  
  90. //##################################################################################
  91.  
  92. We can change the Value of R1 in the voltage divider to change the range of EC we want to measure. Below is the Equivalent Voltage divider circuit.
  93.  
  94. Voltage Divider.png
  95.  
  96. Ra
  97.  
  98. Ra the resistance of the digital pins is not stated in the data sheet instead we need to pull it out from a graph.
  99.  
  100. Going off the graph on page [387] of the atmel 2560 Data Sheet “Figure 32-25. I/O Pin Output Voltage vs. Source Current (VCC = 5V)”
  101.  
  102. V=IR
  103.  
  104. Ra= V/I [From Figure] V=0.4 I=1.5e-4 R=25 ohms estimated
  105.  
  106. Rc
  107.  
  108.  
  109. Rc will change with EC [PPM] of the measured fluid. we will calculate the maximum and minimum values we expect to see for the range of fluids we wish to measure taking into account temperature changes and the cell constant K. [We will estimate K to be 3 for the plug probe, estimate from previous tests]
  110.  
  111. EC = EC25*( 1 + a (T - 25))
  112.  
  113. R=(1000/(EC*K)) +Ra
  114.  
  115. Min temp=0 [we arnt going to care about EC if the pond is frozen]
  116.  
  117. Max Temp = 40 *C [I doubt a pond should be above this]
  118.  
  119. Minimum EC 25=0.3 EC= 0.3*(1+0.019*(0-25) Min EC= 0.16 S/sm
  120.  
  121. Maximum EC 25= 3 EC= 0.3*(1+0.019*(40-25) Max EC = 3.9 S/cm
  122.  
  123. Min Resistance = 1000/(MaxEC*K)+25 = 1000(3.9*2.88) =114 ohms
  124.  
  125. Max Resitance = 1000/(MinEC*K)+25 = 1000/(0.16*2.88) = 2195 ohms
  126.  
  127. R1
  128.  
  129. Now we have enough information to calculate a good value for R1 to get the best resolution over our intended measuring range. We could sum it all up mathematically and differentiate to find the peak, but that hurts my head so I just did a quick excel spreadsheet for the Voltage divider for the EC I expect to see:
  130.  
  131. Exel.png
  132.  
  133.  
  134. As we can see we get the largest difference using a value for R1 of 500 ohm, I only had 1Kohm to hand so I will have to live with a little less range.
  135.  
  136. So we chose a 500 ohm resistor
  137.  
  138. EC – Range /Voltage Range * (5/ADC steps)
  139.  
  140. (3.9-0.16)/3.14 * 5/1024 = 5.8e-3 resolution so that is a resolution of 0.0058
  141.  
  142. To put this is PPM [Tranchen [Australia] PPMconversion: 0.7] this is a resolution of 4ppm.
  143.  
  144. Much more than we need for aquaponics or hydroponics.
  145.  
  146. If you want to measure the quality of drinking water you will need to calculate the expected Ec values and increase R1 accordingly.
  147.  
  148.  
  149. Calibration Code
  150.  
  151. If you want the best readings from your system it is advisable to calibrate your sensor with some known fluid. But If you dont need to if you use the plug probe shown above, it will still work well.
  152.  
  153. >Add your EC in S/cm into the definitions
  154.  
  155. >Plug your K value from the terminal window into the main EC code
  156.  
  157. you will need to use the modified one wire and Dallas library [download from www.michaelratcliffe.com] or add a pull up for the temperature probe data line [google it]
  158.  
  159. /*
  160. ElCheapo Arduino EC-PPM measurments Calibration
  161.  
  162. This Script is used for calibration of the sensor and fine tuning of the Cell Constant K
  163. Submerge the sensor and temperature probe in the calibration solution and leave for a while so the temperature probe can settle
  164. Change the value of the calibration solution to suit the solutiton strength
  165. Stir the probe to make sure the solution is well mixed and upload the code to the arduino
  166. Open the terminal for an update of the estimated Cell Constant K [should be around 3] and use this new value in the main EC code.
  167.  
  168.  
  169. 28/8/2015 Michael Ratcliffe Mike@MichaelRatcliffe.com
  170.  
  171.  
  172. This program is free software: you can redistribute it and/or modify
  173. it under the terms of the GNU General Public License as published by
  174. the Free Software Foundation, either version 3 of the License, or
  175. (at your option) any later version.
  176.  
  177.  
  178. This program is distributed in the hope that it will be useful,
  179. but WITHOUT ANY WARRANTY; without even the implied warranty of
  180. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  181. GNU General Public License for more details.
  182.  
  183.  
  184. You should have received a copy of the GNU General Public License
  185. along with this program. If not, see .
  186.  
  187. Parts:
  188. -Arduino - Uno/Mega
  189. -Standard American two prong plug
  190. -1 kohm resistor
  191. -DS18B20 Waterproof Temperature Sensor
  192.  
  193.  
  194. See www.MichaelRatcliffe.com/Projects for a Pinout and user guide or consult the Zip you got this code from
  195.  
  196. */
  197.  
  198.  
  199. //************************** Libraries Needed To Compile The Script [See Read me In Download] ***************//
  200. // Both below Library are custom ones [ SEE READ ME In Downloaded Zip If You Dont Know how To install Use them or add a pull up resistor to the temp probe
  201.  
  202.  
  203. #include <OneWire.h>
  204. #include <DallasTemperature.h>
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211. //************************* User Defined Variables ********************************************************//
  212.  
  213.  
  214. float CalibrationEC=1.38; //EC value of Calibration solution is s/cm
  215.  
  216.  
  217.  
  218.  
  219. //##################################################################################
  220. //----------- Do not Replace R1 with a resistor lower than 300 ohms ------------
  221. //##################################################################################
  222.  
  223.  
  224. int R1= 1000;
  225. int Ra=25; //Resistance of powering Pins
  226. int ECPin= A0;
  227. int ECGround=A1;
  228. int ECPower =A4;
  229.  
  230.  
  231. //*************Compensating for temperature ************************************//
  232. //The value below will change depending on what chemical solution we are measuring
  233. //0.019 is generaly considered the standard for plant nutrients [google "Temperature compensation EC" for more info
  234. float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring
  235.  
  236.  
  237.  
  238.  
  239. //************ Temp Probe Related *********************************************//
  240. #define ONE_WIRE_BUS 10 // Data wire For Temp Probe is plugged into pin 10 on the Arduino
  241. const int TempProbePossitive =8; //Temp Probe power connected to pin 9
  242. const int TempProbeNegative=9; //Temp Probe Negative connected to pin 8
  243.  
  244.  
  245.  
  246.  
  247. //***************************** END Of Recomended User Inputs *****************************************************************//
  248.  
  249.  
  250. OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
  251. DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.
  252.  
  253.  
  254. float TemperatureFinish=0;
  255. float TemperatureStart=0;
  256. float EC=0;
  257. int ppm =0;
  258.  
  259.  
  260. float raw= 0;
  261. float Vin= 5;
  262. float Vdrop= 0;
  263. float Rc= 0;
  264. float K=0;
  265.  
  266.  
  267.  
  268.  
  269. int i=0;
  270. float buffer=0;
  271.  
  272.  
  273. //*********************************Setup - runs Once and sets pins etc ******************************************************//
  274. void setup()
  275. {
  276. Serial.begin(9600);
  277. pinMode(TempProbeNegative , OUTPUT ); //seting ground pin as output for tmp probe
  278. digitalWrite(TempProbeNegative , LOW );//Seting it to ground so it can sink current
  279. pinMode(TempProbePossitive , OUTPUT );//ditto but for positive
  280. digitalWrite(TempProbePossitive , HIGH );
  281. pinMode(ECPin,INPUT);
  282. pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
  283. pinMode(ECGround,OUTPUT);//setting pin for sinking current
  284. digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly
  285.  
  286. delay(100);// gives sensor time to settle
  287. sensors.begin();
  288. delay(100);
  289. //** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
  290. // Consule Read-Me for Why, or just accept it as true
  291. R1=(R1+Ra);
  292.  
  293. Serial.println("ElCheapo Arduino EC-PPM measurments Calibration");
  294. Serial.println("By: Michael Ratcliffe Mike@MichaelRatcliffe.com");
  295. Serial.println("Free software: you can redistribute it and/or modify it under GNU ");
  296. Serial.println("");
  297. Serial.println("Make sure Probe and Temp Sensor are in Solution and solution is well mixed");
  298. Serial.println("");
  299. Serial.println("Starting Calibration: Estimated Time 60 Seconds:");
  300.  
  301.  
  302.  
  303. };
  304. //******************************************* End of Setup **********************************************************************//
  305.  
  306.  
  307.  
  308.  
  309. //************************************* Main Loop - Runs Forever ***************************************************************//
  310. //Moved Heavy Work To subroutines so you can call them from main loop without cluttering the main loop
  311. void loop()
  312. {
  313.  
  314.  
  315. i=1;
  316. buffer=0;
  317. sensors.requestTemperatures();// Send the command to get temperatures
  318. TemperatureStart=sensors.getTempCByIndex(0); //Stores Value in Variable
  319.  
  320.  
  321. //************Estimates Resistance of Liquid ****************//
  322. while(i<=10){
  323.  
  324.  
  325.  
  326. digitalWrite(ECPower,HIGH);
  327. raw= analogRead(ECPin);
  328. raw= analogRead(ECPin);// This is not a mistake, First reading will be low
  329. digitalWrite(ECPower,LOW);
  330. buffer=buffer+raw;
  331. i++;
  332. delay(5000);
  333. };
  334. raw=(buffer/10);
  335.  
  336.  
  337.  
  338.  
  339. sensors.requestTemperatures();// Send the command to get temperatures
  340. TemperatureFinish=sensors.getTempCByIndex(0); //Stores Value in Variable
  341.  
  342.  
  343. //*************Compensating For Temperaure********************//
  344. EC =CalibrationEC*(1+(TemperatureCoef*(TemperatureFinish-25.0))) ;
  345.  
  346. //***************** Calculates R relating to Calibration fluid **************************//
  347. Vdrop= (((Vin)*(raw))/1024.0);
  348. Rc=(Vdrop*R1)/(Vin-Vdrop);
  349. Rc=Rc-Ra;
  350. K= 1000/(Rc*EC);
  351.  
  352.  
  353.  
  354.  
  355. Serial.print("Calibration Fluid EC: ");
  356. Serial.print(CalibrationEC);
  357. Serial.print(" S "); //add units here
  358. Serial.print("Cell Constant K");
  359. Serial.print(K);
  360.  
  361.  
  362. if (TemperatureStart==TemperatureFinish){
  363. Serial.println(" Results are Trustworthy");
  364. Serial.println(" Safe To Use Above Cell Constant in Main EC code");
  365.  
  366. }
  367. else{
  368. Serial.println(" Error -Wait For Temperature To settle");
  369.  
  370. }
  371.  
  372.  
  373. }
  374. //************************************** End Of Main Loop **********************************************************************//
  375.  
  376. EC PPM Measurement Code
  377.  
  378. >If you are using PPM and not EC make sure you note what conversion factor you are using [it isnt universal]
  379.  
  380. >Dont call the read function more than once every 5 seconds or you will get bad readings and a damaged probe
  381.  
  382. I tested this code in a solution for 48 hours reading at 5 second intervals without any polarisation or probe damage, the longer you leave between readings the longer your probe will last. 5 seconds is the minimum wait between readings not the maximum.
  383.  
  384. you will need to use the modified one wire and Dallas library [download from www.michaelratcliffe.com] or add a pull up for the temperature probe data line [google it]
  385.  
  386. /*
  387. ElCheapo Arduino EC-PPM measurments
  388.  
  389. This scrip uses a common USA two prong plug and a 47Kohm Resistor to measure the EC/PPM of a Aquaponics/Hydroponics Sytem.
  390. You could modift this code to Measure other liquids if you change the resitor and values at the top of the code.
  391.  
  392. This Program will give you a temperature based feed controller. See Read me in download file for more info.
  393.  
  394. 28/8/2015 Michael Ratcliffe Mike@MichaelRatcliffe.com
  395.  
  396.  
  397. This program is free software: you can redistribute it and/or modify
  398. it under the terms of the GNU General Public License as published by
  399. the Free Software Foundation, either version 3 of the License, or
  400. (at your option) any later version.
  401.  
  402.  
  403. This program is distributed in the hope that it will be useful,
  404. but WITHOUT ANY WARRANTY; without even the implied warranty of
  405. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  406. GNU General Public License for more details.
  407.  
  408.  
  409. You should have received a copy of the GNU General Public License
  410. along with this program. If not, see .
  411.  
  412. Parts:
  413. -Arduino - Uno/Mega
  414. -Standard American two prong plug
  415. -1 kohm resistor
  416. -DS18B20 Waterproof Temperature Sensor
  417.  
  418. Limitations:
  419. -
  420. -
  421.  
  422. See www.MichaelRatcliffe.com/Projects for a Pinout and user guide or consult the Zip you got this code from
  423.  
  424. */
  425.  
  426.  
  427. //************************** Libraries Needed To Compile The Script [See Read me In Download] ***************//
  428. // Both below Library are custom ones [ SEE READ ME In Downloaded Zip If You Dont Know how To install] Use them or add a pull up resistor to the temp probe
  429.  
  430.  
  431. #include <OneWire.h>
  432. #include <DallasTemperature.h>
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439. //************************* User Defined Variables ********************************************************//
  440.  
  441.  
  442. //##################################################################################
  443. //----------- Do not Replace R1 with a resistor lower than 300 ohms ------------
  444. //##################################################################################
  445.  
  446.  
  447. int R1= 1000;
  448. int Ra=25; //Resistance of powering Pins
  449. int ECPin= A0;
  450. int ECGround=A1;
  451. int ECPower =A4;
  452.  
  453.  
  454. //*********** Converting to ppm [Learn to use EC it is much better**************//
  455. // Hana [USA] PPMconverion: 0.5
  456. // Eutech [EU] PPMconversion: 0.64
  457. //Tranchen [Australia] PPMconversion: 0.7
  458. // Why didnt anyone standardise this?
  459.  
  460.  
  461. float PPMconversion=0.7;
  462.  
  463.  
  464. //*************Compensating for temperature ************************************//
  465. //The value below will change depending on what chemical solution we are measuring
  466. //0.019 is generaly considered the standard for plant nutrients [google "Temperature compensation EC" for more info
  467. float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring
  468.  
  469.  
  470.  
  471.  
  472. //********************** Cell Constant For Ec Measurements *********************//
  473. //Mine was around 2.9 with plugs being a standard size they should all be around the same
  474. //But If you get bad readings you can use the calibration script and fluid to get a better estimate for K
  475. float K=2.88;
  476.  
  477.  
  478.  
  479.  
  480. //************ Temp Probe Related *********************************************//
  481. #define ONE_WIRE_BUS 10 // Data wire For Temp Probe is plugged into pin 10 on the Arduino
  482. const int TempProbePossitive =8; //Temp Probe power connected to pin 9
  483. const int TempProbeNegative=9; //Temp Probe Negative connected to pin 8
  484.  
  485.  
  486.  
  487.  
  488. //***************************** END Of Recomended User Inputs *****************************************************************//
  489.  
  490.  
  491. OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
  492. DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.
  493.  
  494.  
  495. float Temperature=10;
  496. float EC=0;
  497. float EC25 =0;
  498. int ppm =0;
  499.  
  500.  
  501. float raw= 0;
  502. float Vin= 5;
  503. float Vdrop= 0;
  504. float Rc= 0;
  505. float buffer=0;
  506.  
  507.  
  508.  
  509.  
  510. //*********************************Setup - runs Once and sets pins etc ******************************************************//
  511. void setup()
  512. {
  513. Serial.begin(9600);
  514. pinMode(TempProbeNegative , OUTPUT ); //seting ground pin as output for tmp probe
  515. digitalWrite(TempProbeNegative , LOW );//Seting it to ground so it can sink current
  516. pinMode(TempProbePossitive , OUTPUT );//ditto but for positive
  517. digitalWrite(TempProbePossitive , HIGH );
  518. pinMode(ECPin,INPUT);
  519. pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
  520. pinMode(ECGround,OUTPUT);//setting pin for sinking current
  521. digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly
  522.  
  523. delay(100);// gives sensor time to settle
  524. sensors.begin();
  525. delay(100);
  526. //** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
  527. // Consule Read-Me for Why, or just accept it as true
  528. R1=(R1+Ra);// Taking into acount Powering Pin Resitance
  529.  
  530. Serial.println("ElCheapo Arduino EC-PPM measurments");
  531. Serial.println("By: Michael Ratcliffe Mike@MichaelRatcliffe.com");
  532. Serial.println("Free software: you can redistribute it and/or modify it under GNU ");
  533. Serial.println("");
  534. Serial.println("Make sure Probe and Temp Sensor are in Solution and solution is well mixed");
  535. Serial.println("");
  536. Serial.println("Measurments at 5's Second intervals [Dont read Ec morre than once every 5 seconds]:");
  537.  
  538.  
  539. };
  540. //******************************************* End of Setup **********************************************************************//
  541.  
  542.  
  543.  
  544.  
  545. //************************************* Main Loop - Runs Forever ***************************************************************//
  546. //Moved Heavy Work To subroutines so you can call them from main loop without cluttering the main loop
  547. void loop()
  548. {
  549.  
  550.  
  551.  
  552.  
  553. GetEC(); //Calls Code to Go into GetEC() Loop [Below Main Loop] dont call this more that 1/5 hhz [once every five seconds] or you will polarise the water
  554. PrintReadings(); // Cals Print routine [below main loop]
  555.  
  556.  
  557. delay(5000);
  558.  
  559.  
  560. }
  561. //************************************** End Of Main Loop **********************************************************************//
  562.  
  563.  
  564.  
  565.  
  566. //************ This Loop Is called From Main Loop************************//
  567. void GetEC(){
  568.  
  569.  
  570. //*********Reading Temperature Of Solution *******************//
  571. sensors.requestTemperatures();// Send the command to get temperatures
  572. Temperature=sensors.getTempCByIndex(0); //Stores Value in Variable
  573.  
  574.  
  575.  
  576.  
  577. //************Estimates Resistance of Liquid ****************//
  578. digitalWrite(ECPower,HIGH);
  579. raw= analogRead(ECPin);
  580. raw= analogRead(ECPin);// This is not a mistake, First reading will be low beause if charged a capacitor
  581. digitalWrite(ECPower,LOW);
  582.  
  583.  
  584.  
  585.  
  586. //***************** Converts to EC **************************//
  587. Vdrop= (Vin*raw)/1024.0;
  588. Rc=(Vdrop*R1)/(Vin-Vdrop);
  589. Rc=Rc-Ra; //acounting for Digital Pin Resitance
  590. EC = 1000/(Rc*K);
  591.  
  592.  
  593. //*************Compensating For Temperaure********************//
  594. EC25 = EC/ (1+ TemperatureCoef*(Temperature-25.0));
  595. ppm=(EC25)*(PPMconversion*1000);
  596.  
  597.  
  598. ;}
  599. //************************** End OF EC Function ***************************//
  600.  
  601.  
  602.  
  603.  
  604. //***This Loop Is called From Main Loop- Prints to serial usefull info ***//
  605. void PrintReadings(){
  606. Serial.print("Rc: ");
  607. Serial.print(Rc);
  608. Serial.print(" EC: ");
  609. Serial.print(EC25);
  610. Serial.print(" Simens ");
  611. Serial.print(ppm);
  612. Serial.print(" ppm ");
  613. Serial.print(Temperature);
  614. Serial.println(" *C ");
  615.  
  616.  
  617. /*
  618. //********** Usued for Debugging ************
  619. Serial.print("Vdrop: ");
  620. Serial.println(Vdrop);
  621. Serial.print("Rc: ");
  622. Serial.println(Rc);
  623. Serial.print(EC);
  624. Serial.println("Siemens");
  625. //********** end of Debugging Prints *********
  626. */
  627. };
  628.  
  629. Got any questions let me know.
  630.  
  631. The next tutorial will be on coding a self learning nutrient doser.
  632.  
  633. References:
  634.  
  635. [1]
  636.  
  637. John J. Barron & Colin Ashton "The Effect of Temperature on Conductivity Measurement" Technical Services Department, Reagecon Diagnostics Ltd
  638.  
  639. http://www.reagecon.com/pdf/technicalpapers/Effect_of_Temperature_TSP-07_Issue3.pdf
  640. Previous Log
  641. Arduino Hall Effect Water Flow Meter
  642. 08/28/2015 at 00:12 • 2 comments
  643. Next Log
  644. Updated Uptime Counter
  645. 09/12/2015 at 16:28 • 5 comments
  646. Discussions
  647.  
  648. Log In/Sign up to comment
  649.  
  650. vikash kumar wrote 12/04/2018 at 10:10
  651.  
  652. I'm not able to get the code of the modified onewire dallas library. Kindly help me to get the modified onewire dallas library installed as soon as possible.
  653.  
  654.  
  655. charlie bart wrote 07/20/2018 at 12:54
  656.  
  657. Hi everybody.
  658.  
  659. I've been successfully reading EC with your code and my arduino UNO & Mega.
  660.  
  661. But the thing is, when i try with my ESP32 on an ADC port, i get incoherent voltages. Same thing with an arduino + ADS1115.
  662.  
  663. For example :
  664.  
  665. Arduino+EC sensor+ 1.55mS calibration solution : Value read : 403 (so 1.96v)
  666.  
  667. Arduino+EC sensor+ 2.8mS calibration solution : Value read : 277 (so 1.35v)
  668.  
  669. Arduino without sensor plugged : Value read : 1023 (so 5v)
  670.  
  671. Arduino+ADS1115@15bits+EC sensor+ 1.55mS calibration solution : Value read : 24560 (so 4.6v)
  672.  
  673. Arduino+ADS1115@15bits+EC sensor+ 2.8mS calibration solution : Value read : 25520 (so 4.79v)
  674.  
  675. Arduino+ADS1115@15bits without sensor plugged : Value read : 27000 (so 5v under 15bits)
  676.  
  677. I'm always using a 1kohms resistor for those tests (between +5v and analog signal).
  678.  
  679. I don't have the numbers now for the ESP32+sensor@3.3v but it's the same than with the ADS (voltages read higher than on arduino).
  680.  
  681. Do someone have an idea about what is happening here?
  682.  
  683. I'm reaching the limit of my basic knowledge here :-(
  684.  
  685.  
  686. 466 wrote 04/10/2018 at 16:29
  687.  
  688. Nice project you got here!
  689.  
  690.  
  691. Looking forward, creating an EC meter myself :)
  692.  
  693. Would you mind explaining:
  694.  
  695. Minimum EC 25=0.3 EC
  696.  
  697. and
  698.  
  699. Maximum EC 25= 3 EC
  700.  
  701. ?
  702.  
  703. Where do those values come from?
  704.  
  705. (Ok, 3 EC: 3 could be cell constant? but 0.3? did not find any info about it)
  706.  
  707. Thanks!
  708.  
  709.  
  710. Cedric wrote 03/03/2018 at 12:39
  711.  
  712. Hi Michael, instead of a plug, I'm planning on using pin headers as the probe. However, I'm not sure what should the K constant would be. How did you get the K constant of the plug?
  713.  
  714.  
  715. Zaidan Alif Muttaqin wrote 02/02/2018 at 10:05
  716.  
  717. Hi Mike, can you solve my problem? the temperature is always -127 C.
  718.  
  719.  
  720. Cody Lawson wrote 02/28/2018 at 03:36
  721.  
  722. Kind of late reply but -127 reading means bad probe or bad connection. If you have another probe try using that. If only one probe try resoldering the contacts or making a new plug depending on how it connects. That error likes to randomly pop up with these probes.
  723.  
  724.  
  725. carlos.bruckner wrote 01/28/2018 at 14:48
  726.  
  727. Hi there. I've been playing with a similar project for a few days and fighting some distortion on my readings as the conductivity goes up. My guess is that it is due to polarization.
  728. I'd like to add a few notes and questions:
  729.  
  730. a) When you say "You want the Solid Prong type plug" you meant the right end of the cable or to not use plugs with those little holes on the side? I changed one with the little holes to to another one (solid, round, little smaller area) and I think I got better readings.
  731.  
  732. b) The first reading gets discarded. Can I do that before setting the power pin, to high?, ie:
  733.  
  734. analogRead(ECPin);// first reading discarded, outside "HIGH zone"
  735. digitalWrite(ECPower,HIGH); // or PORTA = B00000010; (for digital pin 23)
  736. sensorValue = analogRead(ECPin);
  737. digitalWrite(ECPower,LOW);
  738.  
  739. That way we spend less time with ECPower "on", so less polarization.
  740.  
  741. d) By my calculations, the resolution at a given water resisitance Rw is:
  742.  
  743. Res = R1 / (R1+Rw)^2 - which means that you should use R1 as close to Rw as possible.
  744.  
  745. However, while having the water at around 974uS (and my system reading it as 530~550ohm), to improve resolution, I used a 520ohm resistor, but the readings were more accurate when I used 1500ohm. My guess is that bigger resistance R1 means less voltage on the water, and thus, less polarization. If that makes sense, I think it is worth noticing.
  746.  
  747. Oh, and my K is currently 1.965.
  748.  
  749. Anyways, great project and great description, it was exactly what I was looking for.
  750.  
  751.  
  752. Cody Lawson wrote 01/23/2018 at 22:36
  753.  
  754. Have you experimented with the ESP32 at all? My RO system already runs on one and it actually has multiple analog inputs compared to the ESP8266. I started to dive into it but the coding looked beyond my level. It appears a lot of the ADC stuff is still in development.
  755.  
  756. Some more helpful info. I called HM Digital and found out their inline probe K value is 0.67. Not sure if HM Digital is very big in the UK but in the US they seem to be the standard with RO units. Unfortunately their monitors do not have a data out but doesn't mean you can't recycle the probe! Also no data on the internal thermister (said they would have to call Korea) so an external temp probe is still needed.
  757.  
  758. If using their probes (or similar inline push fitting style) make sure you calibrate them INSIDE their T-fitting. The prongs are compressed together slightly while in the fitting and it appears the calibration point takes that into account. Results still weren't perfect using the 0.67 and 10,000K resistor but they were significantly better compared to measuring a naked probe. At ~100ppm I read 105, ~13-14 I read 15.46, and at ~3-4 I read around 6 ppm. My other probe from China I calculated K to be around 0.565. I would say a K range of 0.4-0.8 would be good for these smaller probes.
  759.  
  760.  
  761. Cody Lawson wrote 01/22/2018 at 03:42
  762.  
  763. Great project! I ended up making a few interactive graphs with your equations for both the Arduino and ESP8266 boards. Both the K value and R1 have sliders so you can see how each will change the curve. Apparently if you double the R1 value but halve the K value you get roughly the same curve. That was one of a few different "OOOOOHHHHHHH, that's how that works!" moments. At least this felt better than plugging random numbers in and hoping for the best haha.
  764.  
  765. Arduino: https://www.desmos.com/calculator/qzbszykkbj
  766.  
  767. ESP8266: https://www.desmos.com/calculator/moptex4ufc
  768.  
  769. Feel free to reuse these if you want. Figured someone out there would appreciate the little extra help :)
  770.  
  771. Graph Instructions:
  772.  
  773. The X axis is the "Raw" variable, so 1 - 1024. The Y axis is PPM (Hana 0.5). The adjustable equation is the Red line. Sliders can be found at the bottom of the menu on the left. It starts off with what you chose in the tutorial. The next 4 lines can be used for comparison. They are set near my calibration point with Purple = R 10000, K 0.5; Orange = R 10000, K 1; Blue = 20000, K 0.5; Green = R 20000, K 1. Both Orange and Blue should basically be on top of each other (what I referenced earlier).
  774.  
  775. If you want to convert back to EC just delete the *500 at the very end of the equation. To change to a different PPM just change 500 to 640 or 700. To change the range or step of K or R1 click on either the min or max number found on either side of the slide. Everything else I am going to assume you guys can figure it out.
  776.  
  777.  
  778. frozenfritz wrote 12/12/2017 at 17:32
  779.  
  780. Hi Michael, I have a question for you: why do you use A8 as a power source? could I also youse a "normal" digital pin from an arduino? Really nice project btw!
  781.  
  782.  
  783. Michael Ratcliffe wrote 12/14/2017 at 19:24
  784.  
  785. Yep, for a driving pin you can use a digital pin.
  786.  
  787.  
  788. cyberdevil001 wrote 12/10/2017 at 00:30
  789.  
  790. Hi Michael,
  791.  
  792. I'm using your code to measure and log the TDS that comes out of my RO system to replace the existing TDS meter. I only noticed that it seems to have issues with the low value measuring of the output water. This is currently 0 while before the DI resin this is between 1 and 7. Currently using the following probe: https://www.aliexpress.com/item/New-G1-4-0-8MPA-Water-quality-probe-TDS-conductivity-test-water-quality-testing-probe/32630094172.html?spm=2114.01010208.3.226.RCrLgm&ws_ab_test=searchweb0_0 . Calibrated this on 342ppm calibration water and when measuring 0 ppm water (demineralised water), it actually shows a few ppm instead:
  793.  
  794. Rc: 261350.00 EC: 0.00 Simens 2 ppm 21.69 *C
  795. Rc: 261350.00 EC: 0.00 Simens 2 ppm 21.75 *C
  796. Rc: 261350.00 EC: 0.00 Simens 2 ppm 21.75 *C
  797. Rc: 348816.65 EC: 0.00 Simens 1 ppm 21.75 *C
  798. Rc: 261350.00 EC: 0.00 Simens 2 ppm 21.75 *C
  799. Rc: 208870.00 EC: 0.01 Simens 3 ppm 21.75 *C
  800. Rc: 261350.00 EC: 0.00 Simens 2 ppm 21.75 *C
  801.  
  802. Is there a way that I can tweak it so it will be able to measure these low values? Currently using the 1kOhm resistor as I'm still in the process to understand the R1 calculation you did in combination with my probe.
  803.  
  804. Thanks!
  805.  
  806.  
  807. cyberdevil001 wrote 12/10/2017 at 02:28
  808.  
  809. I did try replacing the 1kOhm resistor with 2 in parallel (=500Ohm) and this seems to provide a bit more stable value, but still off, even with a new sample of 0ppm. (Higher value was spot on the calibration point) Also increased the resolution on the output of EC:
  810.  
  811. Rc: 268250.00 EC: 0.0050 Simens 2 ppm 16.56 *C
  812. Rc: 268250.00 EC: 0.0050 Simens 2 ppm 16.62 *C
  813. Rc: 178650.00 EC: 0.0075 Simens 3 ppm 16.62 *C
  814. Rc: 268250.00 EC: 0.0050 Simens 2 ppm 16.62 *C
  815. Rc: 268250.00 EC: 0.0050 Simens 2 ppm 16.69 *C
  816.  
  817. So it is close, but for what I need to use it, the 2ppm off is still to much. Maybe 2 spot calibration could solve it?
  818.  
  819.  
  820. cyberdevil001 wrote 12/11/2017 at 12:07
  821.  
  822. Trying to see if a 16-bit ADC will solve my issue. Will update in a few days.
  823.  
  824.  
  825. Michael Ratcliffe wrote 12/14/2017 at 19:31
  826.  
  827. Hey, I made this with higher ppm in mind.
  828.  
  829. Some advice to make it work better for low EC Start with the ones at the top:
  830.  
  831. >Increase the Value of R1 [ google voltage dividers and resistance of fluid vs ppm for your probe constant] I would imagine a 5-10K reistor would work better for you but I haven't done the maths.
  832.  
  833. > Potentially increase the delay after powering the probe up and taking a reading [LOW EC water shouldn't polarise easily]
  834.  
  835. Also you will need to look for a data sheet on temperature correction for low EC water, the one I use in the sketch is a estimate for hydroponics solutions]. Distilled water will absorb CO2 and this means distilled water does have a very small ppm.
  836.  
  837.  
  838. yuyouliang wrote 11/09/2017 at 05:09
  839.  
  840. Dear Michael, thank you for sharing this project. It's wonderful. I have some questions. Could you explain
  841. why EC = 1000/(Rc*K)? Why the number is 1000? And the unit is S/cm? not ms/cm? Thanks.
  842.  
  843.  
  844. denysafari wrote 10/29/2017 at 09:16
  845.  
  846. HI michael , i built this one, but i had a problem. the temperature result is negative (-127). could you help me please?
  847.  
  848.  
  849. kutlutug wrote 11/13/2017 at 08:43
  850.  
  851. I have the same problem. My temperature is -127 and my ec numbers dont change in different liquids even wiring the plugs polars with a wire. Is this problem about my hardware?
  852.  
  853.  
  854. wootten91 wrote 09/17/2017 at 18:32
  855.  
  856. Hi Michael, Great project. We are a robotics team of students. We are trying to make a remote probe for water quality measurements using the Particle Electron device. This differs from Arduino in that it runs on 3.3 Volts (compared to 5 Volts for Arduino). How can we adapt the wiring to make this work with the Particle? Thanks for the help.
  857.  
  858.  
  859. raychajahanvi21 wrote 08/26/2017 at 06:55
  860.  
  861. hey , Micheal I was trying to download zip file but it is showing me error !!!
  862.  
  863. can you please help me with that!!
  864.  
  865.  
  866. rleyden310 wrote 08/07/2017 at 19:57
  867.  
  868. I added at pH meter ( http://www.ebay.com/itm/Analog-PH-Probe-Sensor-Shield-and-PH-Probe-Kit-For-Arduino-R3-Water-Detect/331878771777?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649 ) and get interference on the pH readings. I even tried using a separate Arduino for the pH reading and the problem persists although as an offset (~ -2 pH) rather than wildly swinging readings. Any ideas how to fix this? Correcting the pH offset caused by the EC probe seems an "OK" solution but I worry that it may not be stable.
  869.  
  870.  
  871. Michael Ratcliffe wrote 08/07/2017 at 20:25
  872.  
  873. Sure, its a grounding loop problem. you can solve/fix it mechanically or electrically.
  874.  
  875. mechanically: make sure the ph meter and Ec probe are as far away from each other as possible
  876.  
  877. Electronically: Turn the EC meter pin's into a high impedance state when not in use. By setting both pins to inputs using pinmode, you will need to reset them as outputs before taking a reading.
  878.  
  879. ie pinmode output --> delay(20) --> Read EC -->> pimode input.
  880.  
  881. Also this is not the most recent code, just the proof of concept. Check out the main blog for a more recent one with calibration routine etc
  882.  
  883.  
  884. rleyden310 wrote 08/07/2017 at 21:13
  885.  
  886. Thanks Michael,
  887.  
  888. Setting power and ground pins to input between measurements seems to have corrected the offset. I figured it was a ground problem but tried to fix it by setting the EC pin to output, low - wrong direction. My current hydroponic tank is small so I can only get the probes about 10" apart.
  889.  
  890. So where is your main blog? "http://www.michaelratcliffe.com/" seems to be mostly coming soon pages.
  891.  
  892.  
  893. Michael Ratcliffe wrote 08/07/2017 at 21:36
  894.  
  895. Glad it solved the issue, if your dosing the pH make sure to keep an eye on the system because the probes dont last long.
  896.  
  897. Most of the blogs can be found here:
  898.  
  899. https://www.element14.com/community/community/design-challenges/vertical-farming/blog/2015/09/13/automated-green-house-blogs-main-page
  900.  
  901.  
  902. Nuno Silva wrote 05/09/2017 at 12:58
  903.  
  904. Hi Michael,
  905.  
  906. I am trying to use your hardware and software to test portable water.
  907.  
  908. In my case I am calibrating the system for 0,01288 S/cm and I would like to ask you what do you think the R1 should be for this project.
  909.  
  910. If I follow your methodology Vdrop and Vout Range I should use a 30K ohms resistor.
  911.  
  912. This is the way?
  913.  
  914. Thanks
  915.  
  916. Nuno
  917.  
  918.  
  919. Michael Ratcliffe wrote 08/07/2017 at 21:41
  920.  
  921. I havent tested at such a low EC, you might need to use a larger probe surface area to get it to work.
  922.  
  923. But hey give it a shot and see if a 30k works?
  924.  
  925.  
  926. daniele bordignon wrote 03/17/2017 at 09:12
  927.  
  928. Hi Michael. Great post, i'm going to build one of these. I was guessing.. The sensor can stay into water 24/24 7/7?
  929. Is it durable (after 3 or 6 months, one year..)?
  930.  
  931.  
  932. ctsai2 wrote 03/16/2017 at 13:35
  933.  
  934. Hi Michael,
  935.  
  936. Can I use this code on DUE instead?
  937.  
  938.  
  939. Michael Ratcliffe wrote 08/07/2017 at 21:42
  940.  
  941. Sorry for the late reply,
  942.  
  943. I havent tested on a DUO, it may have different v drop for digital pins [can work it out from data sheet]. this would be possible, but if it has extra circutry on the analog pins to reduce noise etc it wont work.
  944.  
  945.  
  946. ctsai2 wrote 02/07/2017 at 17:35
  947.  
  948. Dear Michael,
  949.  
  950. Thanks for sharing this thread.
  951. I need to make a salinity/EC meter for 35ppt/50000EC. Can I use your setup? And what is the reason R1 should be greater than 300ohm?
  952.  
  953.  
  954. Michael Ratcliffe wrote 02/08/2017 at 10:09
  955.  
  956. An EC of 50? That is going to be challenging, I cannot confirm 100%.
  957.  
  958. But the bet way may be to reduce the probe area [cut them shorter?] to keep the current reqirments down.
  959.  
  960. R1: this limits the current drawn by the probe, the arduino digital pin can only supply 20ma.
  961.  
  962.  
  963. ctsai2 wrote 02/15/2017 at 18:57
  964.  
  965. Yes, EC of 50 mS/cm. Right now I have it set up the same as yours. Have not shorten the probes yet. calculated using 1000ohms resistor. Is there anything else I should be concern and change? Because I don't want to burnt any pin. And yes, the conductivity is very high, it's seawater that I am measuring.
  966.  
  967. Thank you.
  968.  
  969.  
  970. ctsai2 wrote 03/15/2017 at 18:41
  971.  
  972. Michael,
  973.  
  974. I cut the probe short, change the Calibration value, but my best R1 for resistor is below 300ohms. Since the seawater resistance is so low compare to fresh/drinking water, can I use R1<300 ohm?
  975. Or is this reversed, that I can only use R1 > than like 500 ohms?
  976.  
  977. Instead of using analog i/o pins, the ECpower is connect directly to the 5V on the board, since we will have constant flowing water so not worrying about polarized the fluid. Does that also up my current drawn to 500mA?
  978.  
  979. Trying hard to make this work. Following your direction I already build one to measure 400-1000ppm and it works. Now moving onto measuring 32,000ppm to 40,000ppm
  980.  
  981. Thanks for any of your help
  982.  
  983.  
  984. geert2 wrote 02/05/2017 at 13:20
  985.  
  986. Dear Michael,
  987.  
  988. More respect every day. One remark and a cry for help.
  989.  
  990. The Electric conductivity is an indicator for ammonia. Meaning that if you have a dead fish in the system, or algae that start dying, , you will notice the EC going thourgh the roof. This means the EC probe is one of the most telling indicators if something is going very wrong.
  991.  
  992. I started to work on the system with a NODECMU Kit, and got quite far.
  993.  
  994. However the readings are defenitely not right (see below).
  995.  
  996. This could be because of the way the analog port reacts in a NODEMCU, or for any other reeason I don't understand, such as using digital pins for delivering the current.
  997.  
  998. I am definitely out of my depth. Could you please help me?
  999.  
  1000. For water:
  1001.  
  1002. Rc: 32808.05 EC: 0.01 Simens 6 ppm 25.50 *C
  1003. raw993.00
  1004. Vdrop: 3.20
  1005. Rc: 32808.05
  1006. 0.01Siemens
  1007.  
  1008. Salt water:
  1009. Rc: 2752.90 EC: 0.12 Simens 79 ppm 25.50 *C
  1010. raw748.00
  1011. Vdrop: 2.41
  1012. Rc: 2752.90
  1013. 0.13Siemens
  1014.  
  1015. My code:
  1016.  
  1017. //************************** Libraries Needed To Compile The Script [See Read me In Download] ***************//
  1018. // Both below Library are custom ones [ SEE READ ME In Downloaded Zip If You Dont Know how To install] Use them or add a pull up resistor to the temp probe
  1019.  
  1020.  
  1021. #include <Onewire.h>
  1022. #include <Dallastemperature.h>
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030. //************************* User Defined Variables ********************************************************//
  1031.  
  1032.  
  1033. //##################################################################################
  1034. //----------- Do not Replace R1 with a resistor lower than 300 ohms ------------
  1035. //##################################################################################
  1036.  
  1037.  
  1038. int R1= 1000;
  1039. int Ra=25; //Resistance of powering Pins
  1040. int ECPin= A0;
  1041. int ECGround=D7;
  1042. int ECPower =D8; // originally A4 is used by air pressure measurement
  1043.  
  1044.  
  1045. //*********** Converting to ppm [Learn to use EC it is much better**************//
  1046. // Hana [USA] PPMconverion: 0.5
  1047. // Eutech [EU] PPMconversion: 0.64
  1048. //Tranchen [Australia] PPMconversion: 0.7
  1049. // Why didnt anyone standardise this?
  1050.  
  1051.  
  1052. float PPMconversion=0.64;
  1053.  
  1054.  
  1055. //*************Compensating for temperature ************************************//
  1056. //The value below will change depending on what chemical solution we are measuring
  1057. //0.019 is generaly considered the standard for plant nutrients [google "Temperature compensation EC" for more info
  1058. float TemperatureCoef = 0.019; //this changes depending on what chemical we are measuring
  1059.  
  1060.  
  1061.  
  1062.  
  1063. //********************** Cell Constant For Ec Measurements *********************//
  1064. //Mine was around 2.9 with plugs being a standard size they should all be around the same
  1065. //But If you get bad readings you can use the calibration script and fluid to get a better estimate for K
  1066. float K=2.88;
  1067.  
  1068.  
  1069.  
  1070.  
  1071. //************ Temp Probe Related *********************************************//
  1072. #define ONE_WIRE_BUS D2 // Data wire For Temp Probe is plugged into pin 10 on the Arduino // with me on 2
  1073. //const int TempProbePossitive =8; //Temp Probe power connected to pin 9 // I don' have that?
  1074. //const int TempProbeNegative=9; //Temp Probe Negative connected to pin 8 //should I do that?
  1075. //
  1076.  
  1077.  
  1078.  
  1079. //***************************** END Of Recomended User Inputs *****************************************************************//
  1080.  
  1081. OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
  1082. DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.
  1083. //
  1084.  
  1085. float Temperature=10;
  1086. float EC=0;
  1087. float EC25 =0;
  1088. int ppm =0;
  1089.  
  1090.  
  1091. float raw= 0;
  1092. float Vin= 3.3; // is only 3.3 v with esp was 5
  1093. float Vdrop= 0;
  1094. float Rc= 0;
  1095. float buffer=0;
  1096.  
  1097.  
  1098.  
  1099.  
  1100. //*********************************Setup - runs Once and sets pins etc ******************************************************//
  1101. void setup()
  1102. {
  1103. Serial.begin(9600);
  1104. // pinMode(TempProbeNegative , OUTPUT ); //seting ground pin as output for tmp probe
  1105. // digitalWrite(TempProbeNegative , LOW );//Seting it to ground so it can sink current
  1106. // pinMode(TempProbePossitive , OUTPUT );//ditto but for positive
  1107. // digitalWrite(TempProbePossitive , HIGH );
  1108. pinMode(ECPin,INPUT);
  1109. pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
  1110. pinMode(ECGround,OUTPUT);//setting pin for sinking current
  1111. digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly
  1112.  
  1113. delay(100);// gives sensor time to settle
  1114. // sensors.begin();
  1115. delay(100);
  1116. //** Adding Digital Pin Resistance to [25 ohm] to the static Resistor *********//
  1117. // Consule Read-Me for Why, or just accept it as true
  1118. R1=(R1+Ra);// Taking into acount Powering Pin Resitance
  1119.  
  1120. Serial.println("ElCheapo Arduino EC-PPM measurments");
  1121. Serial.println("By: Michael Ratcliffe Mike@MichaelRatcliffe.com");
  1122. Serial.println("Free software: you can redistribute it and/or modify it under GNU ");
  1123. Serial.println("");
  1124. Serial.println("Make sure Probe and Temp Sensor are in Solution and solution is well mixed");
  1125. Serial.println("");
  1126. Serial.println("Measurments at 5's Second intervals [Dont read Ec morre than once every 5 seconds]:");
  1127.  
  1128.  
  1129. };
  1130. //******************************************* End of Setup **********************************************************************//
  1131.  
  1132.  
  1133.  
  1134.  
  1135. //************************************* Main Loop - Runs Forever ***************************************************************//
  1136. //Moved Heavy Work To subroutines so you can call them from main loop without cluttering the main loop
  1137. void loop()
  1138. {
  1139.  
  1140.  
  1141.  
  1142.  
  1143. GetEC(); //Calls Code to Go into GetEC() Loop [Below Main Loop] dont call this more that 1/5 hhz [once every five seconds] or you will polarise the water
  1144. PrintReadings(); // Cals Print routine [below main loop]
  1145.  
  1146.  
  1147. delay(10000);// original is 5000
  1148.  
  1149.  
  1150. }
  1151. //************************************** End Of Main Loop **********************************************************************//
  1152.  
  1153.  
  1154.  
  1155.  
  1156. //************ This Loop Is called From Main Loop************************//
  1157. void GetEC(){
  1158.  
  1159.  
  1160. //*********Reading Temperature Of Solution *******************//
  1161. sensors.requestTemperatures();// Send the command to get temperatures
  1162. Temperature=sensors.getTempCByIndex(0); //Stores Value in Variable
  1163.  
  1164.  
  1165.  
  1166.  
  1167. //************Estimates Resistance of Liquid ****************//
  1168. digitalWrite(ECPower,HIGH);
  1169. raw= analogRead(ECPin);
  1170. raw= analogRead(ECPin);// This is not a mistake, First reading will be low beause if charged a capacitor
  1171. digitalWrite(ECPower,LOW);
  1172.  
  1173.  
  1174.  
  1175.  
  1176. //***************** Converts to EC **************************//
  1177. Vdrop= (Vin*raw)/1024.0;
  1178. Rc=(Vdrop*R1)/(Vin-Vdrop);
  1179. Rc=Rc-Ra; //acounting for Digital Pin Resitance
  1180. EC = 1000/(Rc*K);
  1181.  
  1182.  
  1183. //*************Compensating For Temperaure********************//
  1184. EC25 = EC/ (1+ TemperatureCoef*(Temperature-25.0));
  1185. //EC25 = EC;
  1186. ppm=(EC25)*(PPMconversion*1000);
  1187.  
  1188.  
  1189. ;}
  1190. //************************** End OF EC Function ***************************//
  1191.  
  1192.  
  1193.  
  1194.  
  1195. //***This Loop Is called From Main Loop- Prints to serial usefull info ***//
  1196. void PrintReadings(){
  1197. Serial.print("Rc: ");
  1198. Serial.print(Rc);
  1199. Serial.print(" EC: ");
  1200. Serial.print(EC25);
  1201. Serial.print(" Simens ");
  1202. Serial.print(ppm);
  1203. Serial.print(" ppm ");
  1204. Serial.print(Temperature);
  1205. Serial.println(" *C ");
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212. //********** Usued for Debugging ************
  1213. Serial.print("raw");
  1214. Serial.println(raw);
  1215. Serial.print("Vdrop: ");
  1216. Serial.println(Vdrop);
  1217. Serial.print("Rc: ");
  1218. Serial.println(Rc);
  1219. Serial.print(EC);
  1220. Serial.println("Siemens");
  1221. //********** end of Debugging Prints *********
  1222.  
  1223.  
  1224.  
  1225.  
  1226. };
  1227.  
  1228.  
  1229. Michael Ratcliffe wrote 02/06/2017 at 00:28
  1230.  
  1231. Replied to the second post :)
  1232.  
  1233.  
  1234. Next
  1235. Going up?
  1236.  
  1237. About Us Contact Hackaday.io Give Feedback Terms of Use Privacy Policy Hackaday API
  1238.  
  1239. © 2018 Hackaday
  1240.  
  1241. By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement