measuring the salinity
Dependencies: LinearAnalogSensors mbed
Fork of mbed_measuring_temperature by
main.cpp
- Committer:
- ekasinambela
- Date:
- 2016-06-07
- Revision:
- 6:9de0807e2855
- Parent:
- 5:d2b58a5771d7
- Child:
- 7:b0d12907493f
File content as of revision 6:9de0807e2855:
#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) ; AnalogOut pin_18 (p18); //LinearTemp mysensor(p15, 0.0050354, -273.15); char program_name[128] = "G3-Waterplay Project"; void salinityMeasurement(); void temperatureMeasurement(); int main() { while(1){ wait(2); 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("vin: %f, vout: %f, salt: %f \n\r", 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("vin: %f, vout: %f, temperature: %f \n\r",vin, vout, Celcius); if (Celcius < 26){ pin_18 = 1; myled1 = 1; }else{ pin_18 = 0; myled1 = 0; } }