measuring the salinity

Dependencies:   LinearAnalogSensors mbed

Fork of mbed_measuring_temperature by Mario Simaremare

Revision:
3:5baf5ad00c1c
Parent:
2:1aab63839dba
Child:
4:49b028845be4
--- a/main.cpp	Thu Jun 02 12:10:27 2016 +0000
+++ b/main.cpp	Thu Jun 02 14:44:09 2016 +0000
@@ -1,10 +1,11 @@
 #include "mbed.h"
+#include <cmath>
 //#include <LinearTemp.h>
 
 
 Serial pc(USBTX, USBRX);
 DigitalOut myled1(LED1), myled2(LED2);
-AnalogIn pin_1(p16);
+AnalogIn pin_1(p16), pin_2(p15), pin_3(p17) ;
 //LinearTemp mysensor(p15, 0.0050354, -273.15); 
  
 char program_name[128] = "Serial IO";
@@ -35,12 +36,35 @@
      
      
      while(1){
-        wait(2); 
-        float f = pin_1.read();
-        float vin = f * 3.3;
-        float divider = (float)5/ (float)3;
-        float vout = vin * divider;
-        float salt = 16.3 * vout;
+        wait(5); 
+        double f = pin_1.read();
+        double f2 = pin_2.read();
+        double f3 = pin_3.read();
+    
+        double vin = f * 3.3;
+        double divider = (double)5/ (double)3;
+        double vout = vin * divider;
+        //float e = 2.7182818284;
+        
+        //measure the salinity
+        double salt = 16.3 * vout;
         pc.printf("vin: %f, vin2: %f, salt: %f \n\r", vin, vout, salt);
+        
+        //measure the temperature
+        vin = f2 * 5.0;
+        vout = vin * divider;
+        double vout2 = f3 * 4.85;
+        
+        double RT = (vout * (double)15000) / (vout2 - vout);
+        double K0 = 0.00102119;
+        double K1 = 0.000222468 * (log(RT));
+        double K2 = double (1.33342 * pow (10.0, -7.0)) * pow ((double)log(RT), 3.0);
+        double TKelvin = 1.0 / (K0 + K1 + K2);
+        pc.printf("K0: %f, K1: %f, K2: %f \n\r", K0, K1, K2); 
+        //float TKelvin = 1.0 / (0.00102119 + 0.000222468 * (log(RT)/log(2.71828182846)) +  (1.33342 * pow (10.0, 7.0)) * pow (log(RT)/log(2.71828182846), 3.0));
+        double Celcius = TKelvin - 273.15;
+        pc.printf("vin: %f, vout: %f, temperature: %f \n\r", vin, vout, Celcius);
+        pc.printf("f3: %f, f2: %f, vin: %f, vout: %f, RT: %f, TKelvin: %f, temperature: %f \n\r", f3, f2, vin, vout, RT, TKelvin, Celcius);
+        
     }
 }