measuring the salinity
Dependencies: LinearAnalogSensors mbed
Fork of mbed_measuring_temperature by
main.cpp@4:49b028845be4, 2016-06-02 (annotated)
- Committer:
- ekasinambela
- Date:
- Thu Jun 02 16:07:55 2016 +0000
- Revision:
- 4:49b028845be4
- Parent:
- 3:5baf5ad00c1c
- Child:
- 5:d2b58a5771d7
the salinity and temperature measurement program write in the separate functions
Who changed what in which revision?
User | Revision | Line number | New 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 | Serial pc(USBTX, USBRX); |
ekasinambela | 0:da915495c7fc | 6 | DigitalOut myled1(LED1), myled2(LED2); |
ekasinambela | 3:5baf5ad00c1c | 7 | AnalogIn pin_1(p16), pin_2(p15), pin_3(p17) ; |
ekasinambela | 2:1aab63839dba | 8 | //LinearTemp mysensor(p15, 0.0050354, -273.15); |
ekasinambela | 2:1aab63839dba | 9 | |
mariosimaremare | 1:6476db5e52e8 | 10 | char program_name[128] = "Serial IO"; |
mariosimaremare | 1:6476db5e52e8 | 11 | |
ekasinambela | 4:49b028845be4 | 12 | void salinityMeasurement(); |
ekasinambela | 4:49b028845be4 | 13 | void temperatureMeasurement(); |
ekasinambela | 4:49b028845be4 | 14 | |
mariosimaremare | 1:6476db5e52e8 | 15 | int main() |
mariosimaremare | 1:6476db5e52e8 | 16 | { |
ekasinambela | 2:1aab63839dba | 17 | while(1){ |
ekasinambela | 3:5baf5ad00c1c | 18 | wait(5); |
ekasinambela | 4:49b028845be4 | 19 | salinityMeasurement(); |
ekasinambela | 4:49b028845be4 | 20 | temperatureMeasurement(); |
ekasinambela | 0:da915495c7fc | 21 | } |
ekasinambela | 0:da915495c7fc | 22 | } |
ekasinambela | 4:49b028845be4 | 23 | |
ekasinambela | 4:49b028845be4 | 24 | //salinity function |
ekasinambela | 4:49b028845be4 | 25 | void salinityMeasurement(){ |
ekasinambela | 4:49b028845be4 | 26 | float f = pin_1.read(); |
ekasinambela | 4:49b028845be4 | 27 | |
ekasinambela | 4:49b028845be4 | 28 | float vin = f * 3.3; |
ekasinambela | 4:49b028845be4 | 29 | float divider = (float)5/ (float)3; |
ekasinambela | 4:49b028845be4 | 30 | float vout = vin * divider; |
ekasinambela | 4:49b028845be4 | 31 | |
ekasinambela | 4:49b028845be4 | 32 | //measure the salinity |
ekasinambela | 4:49b028845be4 | 33 | float salt = 16.3 * vout; |
ekasinambela | 4:49b028845be4 | 34 | pc.printf("f: %f, vin: %f, vin2: %f, salt: %f \n\r", f, vin, vout, salt); |
ekasinambela | 4:49b028845be4 | 35 | } |
ekasinambela | 4:49b028845be4 | 36 | |
ekasinambela | 4:49b028845be4 | 37 | //temperature function |
ekasinambela | 4:49b028845be4 | 38 | void temperatureMeasurement(){ |
ekasinambela | 4:49b028845be4 | 39 | //measure the temperature |
ekasinambela | 4:49b028845be4 | 40 | double f2 = pin_2.read(); |
ekasinambela | 4:49b028845be4 | 41 | double vin = f2 * 4.85; |
ekasinambela | 4:49b028845be4 | 42 | double divider = (double)5/ (double)3; |
ekasinambela | 4:49b028845be4 | 43 | double vout = vin * divider; |
ekasinambela | 4:49b028845be4 | 44 | |
ekasinambela | 4:49b028845be4 | 45 | double RT = (vout * (double)15000) / (4.85 - vout); |
ekasinambela | 4:49b028845be4 | 46 | double K0 = 0.00102119; |
ekasinambela | 4:49b028845be4 | 47 | double K1 = 0.000222468 * (log(RT)); |
ekasinambela | 4:49b028845be4 | 48 | double K2 = double (1.33342 * pow (10.0, -7.0)) * pow ((double)log(RT), 3.0); |
ekasinambela | 4:49b028845be4 | 49 | double TKelvin = 1.0 / (K0 + K1 + K2); |
ekasinambela | 4:49b028845be4 | 50 | double Celcius = (TKelvin - 273.15)+5.0; |
ekasinambela | 4:49b028845be4 | 51 | |
ekasinambela | 4:49b028845be4 | 52 | pc.printf("K0: %f, K1: %f, K2: %f \n\r", K0, K1, K2); |
ekasinambela | 4:49b028845be4 | 53 | pc.printf("vin: %f, vout: %f, temperature: %f \n\r", vin, vout, Celcius); |
ekasinambela | 4:49b028845be4 | 54 | pc.printf("f2: %f, vin: %f, vout: %f, RT: %f, TKelvin: %f, temperature: %f \n\r",f2, vin, vout, RT, TKelvin, Celcius); |
ekasinambela | 4:49b028845be4 | 55 | } |
ekasinambela | 4:49b028845be4 | 56 | |
ekasinambela | 4:49b028845be4 | 57 |