measuring the salinity

Dependencies:   LinearAnalogSensors mbed

Fork of mbed_measuring_temperature by Mario Simaremare

Committer:
ekasinambela
Date:
Thu Jun 02 14:44:09 2016 +0000
Revision:
3:5baf5ad00c1c
Parent:
2:1aab63839dba
Child:
4:49b028845be4
initiate program of the temperature and salinity measurement

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ekasinambela 0:da915495c7fc 1 #include "mbed.h"
ekasinambela 3:5baf5ad00c1c 2 #include <cmath>
ekasinambela 2:1aab63839dba 3 //#include <LinearTemp.h>
ekasinambela 2:1aab63839dba 4
ekasinambela 0:da915495c7fc 5
ekasinambela 0:da915495c7fc 6 Serial pc(USBTX, USBRX);
ekasinambela 0:da915495c7fc 7 DigitalOut myled1(LED1), myled2(LED2);
ekasinambela 3:5baf5ad00c1c 8 AnalogIn pin_1(p16), pin_2(p15), pin_3(p17) ;
ekasinambela 2:1aab63839dba 9 //LinearTemp mysensor(p15, 0.0050354, -273.15);
ekasinambela 2:1aab63839dba 10
mariosimaremare 1:6476db5e52e8 11 char program_name[128] = "Serial IO";
mariosimaremare 1:6476db5e52e8 12
mariosimaremare 1:6476db5e52e8 13 int main()
mariosimaremare 1:6476db5e52e8 14 {
ekasinambela 2:1aab63839dba 15 /*pc.printf("run: %s\n", program_name);
mariosimaremare 1:6476db5e52e8 16 float temp, tempC, tempF;
ekasinambela 0:da915495c7fc 17 while(1) {
ekasinambela 2:1aab63839dba 18 //temp = LM61;
ekasinambela 2:1aab63839dba 19 tempC = ((pin_1.read()*3.3)-0.600)*100.0;
ekasinambela 2:1aab63839dba 20 printf("%5.4F\n",(pin_1.read()*3.3));
mariosimaremare 1:6476db5e52e8 21 //convert to degrees F
mariosimaremare 1:6476db5e52e8 22 tempF = (9.0*tempC)/5.0 + 32.0;
mariosimaremare 1:6476db5e52e8 23 //print current temp
ekasinambela 2:1aab63839dba 24 printf("%5.4F : %5.2F C %5.2F F\n\r", pin_1.read(), tempC, tempF);
mariosimaremare 1:6476db5e52e8 25 wait(2);
mariosimaremare 1:6476db5e52e8 26
ekasinambela 2:1aab63839dba 27 }*/
ekasinambela 2:1aab63839dba 28 /*while(1) {
ekasinambela 2:1aab63839dba 29 // Light LED if filtered temperature is greater than 45 degrees Celsius
ekasinambela 2:1aab63839dba 30 mysensor.readTemp();
ekasinambela 2:1aab63839dba 31 printf("%5.4F : (%f) \n\r", pin_1.read(), mysensor.getTemp());
ekasinambela 2:1aab63839dba 32 if (mysensor.getTemp() > 10) myled1 = 1;
ekasinambela 2:1aab63839dba 33 else myled1 = 0;
ekasinambela 2:1aab63839dba 34 wait(2);
ekasinambela 2:1aab63839dba 35 }*/
ekasinambela 2:1aab63839dba 36
ekasinambela 2:1aab63839dba 37
ekasinambela 2:1aab63839dba 38 while(1){
ekasinambela 3:5baf5ad00c1c 39 wait(5);
ekasinambela 3:5baf5ad00c1c 40 double f = pin_1.read();
ekasinambela 3:5baf5ad00c1c 41 double f2 = pin_2.read();
ekasinambela 3:5baf5ad00c1c 42 double f3 = pin_3.read();
ekasinambela 3:5baf5ad00c1c 43
ekasinambela 3:5baf5ad00c1c 44 double vin = f * 3.3;
ekasinambela 3:5baf5ad00c1c 45 double divider = (double)5/ (double)3;
ekasinambela 3:5baf5ad00c1c 46 double vout = vin * divider;
ekasinambela 3:5baf5ad00c1c 47 //float e = 2.7182818284;
ekasinambela 3:5baf5ad00c1c 48
ekasinambela 3:5baf5ad00c1c 49 //measure the salinity
ekasinambela 3:5baf5ad00c1c 50 double salt = 16.3 * vout;
ekasinambela 2:1aab63839dba 51 pc.printf("vin: %f, vin2: %f, salt: %f \n\r", vin, vout, salt);
ekasinambela 3:5baf5ad00c1c 52
ekasinambela 3:5baf5ad00c1c 53 //measure the temperature
ekasinambela 3:5baf5ad00c1c 54 vin = f2 * 5.0;
ekasinambela 3:5baf5ad00c1c 55 vout = vin * divider;
ekasinambela 3:5baf5ad00c1c 56 double vout2 = f3 * 4.85;
ekasinambela 3:5baf5ad00c1c 57
ekasinambela 3:5baf5ad00c1c 58 double RT = (vout * (double)15000) / (vout2 - vout);
ekasinambela 3:5baf5ad00c1c 59 double K0 = 0.00102119;
ekasinambela 3:5baf5ad00c1c 60 double K1 = 0.000222468 * (log(RT));
ekasinambela 3:5baf5ad00c1c 61 double K2 = double (1.33342 * pow (10.0, -7.0)) * pow ((double)log(RT), 3.0);
ekasinambela 3:5baf5ad00c1c 62 double TKelvin = 1.0 / (K0 + K1 + K2);
ekasinambela 3:5baf5ad00c1c 63 pc.printf("K0: %f, K1: %f, K2: %f \n\r", K0, K1, K2);
ekasinambela 3:5baf5ad00c1c 64 //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));
ekasinambela 3:5baf5ad00c1c 65 double Celcius = TKelvin - 273.15;
ekasinambela 3:5baf5ad00c1c 66 pc.printf("vin: %f, vout: %f, temperature: %f \n\r", vin, vout, Celcius);
ekasinambela 3:5baf5ad00c1c 67 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);
ekasinambela 3:5baf5ad00c1c 68
ekasinambela 0:da915495c7fc 69 }
ekasinambela 0:da915495c7fc 70 }