measuring the salinity

Dependencies:   LinearAnalogSensors mbed

Fork of mbed_measuring_temperature by Mario Simaremare

main.cpp

Committer:
ekasinambela
Date:
2016-06-02
Revision:
3:5baf5ad00c1c
Parent:
2:1aab63839dba
Child:
4:49b028845be4

File content as of revision 3:5baf5ad00c1c:

#include "mbed.h"
#include <cmath>
//#include <LinearTemp.h>


Serial pc(USBTX, USBRX);
DigitalOut myled1(LED1), myled2(LED2);
AnalogIn pin_1(p16), pin_2(p15), pin_3(p17) ;
//LinearTemp mysensor(p15, 0.0050354, -273.15); 
 
char program_name[128] = "Serial IO";

int main()
{
    /*pc.printf("run: %s\n", program_name);
    float temp, tempC, tempF;
    while(1) {
        //temp = LM61;
        tempC = ((pin_1.read()*3.3)-0.600)*100.0;
        printf("%5.4F\n",(pin_1.read()*3.3));
        //convert to degrees F
        tempF = (9.0*tempC)/5.0 + 32.0;
        //print current temp
        printf("%5.4F : %5.2F C %5.2F F\n\r", pin_1.read(), tempC, tempF);
        wait(2);

    }*/
    /*while(1) {
         // Light LED if filtered temperature is greater than 45 degrees Celsius
         mysensor.readTemp();
         printf("%5.4F : (%f) \n\r", pin_1.read(), mysensor.getTemp());
         if (mysensor.getTemp() > 10) myled1 = 1;
         else myled1 = 0;
         wait(2);
     }*/
     
     
     while(1){
        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);
        
    }
}