measuring the salinity
Dependencies: LinearAnalogSensors mbed
Fork of mbed_measuring_temperature by
main.cpp
- Committer:
- ekasinambela
- Date:
- 2016-06-02
- Revision:
- 4:49b028845be4
- Parent:
- 3:5baf5ad00c1c
- Child:
- 5:d2b58a5771d7
File content as of revision 4:49b028845be4:
#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"; void salinityMeasurement(); void temperatureMeasurement(); int main() { while(1){ wait(5); salinityMeasurement(); temperatureMeasurement(); } } //salinity function void salinityMeasurement(){ float f = pin_1.read(); float vin = f * 3.3; float divider = (float)5/ (float)3; float vout = vin * divider; //measure the salinity float salt = 16.3 * vout; pc.printf("f: %f, vin: %f, vin2: %f, salt: %f \n\r", f, vin, vout, salt); } //temperature function void temperatureMeasurement(){ //measure the temperature double f2 = pin_2.read(); double vin = f2 * 4.85; double divider = (double)5/ (double)3; double vout = vin * divider; double RT = (vout * (double)15000) / (4.85 - 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); double Celcius = (TKelvin - 273.15)+5.0; pc.printf("K0: %f, K1: %f, K2: %f \n\r", K0, K1, K2); pc.printf("vin: %f, vout: %f, temperature: %f \n\r", vin, vout, Celcius); pc.printf("f2: %f, vin: %f, vout: %f, RT: %f, TKelvin: %f, temperature: %f \n\r",f2, vin, vout, RT, TKelvin, Celcius); }