Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of mbed_pH225 by
main.cpp@4:bc63632c6808, 2015-04-02 (annotated)
- Committer:
- sitakumar
- Date:
- Thu Apr 02 04:53:05 2015 +0000
- Revision:
- 4:bc63632c6808
- Parent:
- 3:98adc27dc82d
- Child:
- 5:8ec4c03f4079
huzaifa
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sitakumar | 0:f610f2c606a8 | 1 | #include "mbed.h" |
| sitakumar | 0:f610f2c606a8 | 2 | #include "time.h" |
| sitakumar | 0:f610f2c606a8 | 3 | |
| sitakumar | 0:f610f2c606a8 | 4 | DigitalOut myled(LED1); |
| sitakumar | 0:f610f2c606a8 | 5 | //serial connection via USB |
| sitakumar | 0:f610f2c606a8 | 6 | Serial pc(USBTX, USBRX); |
| sitakumar | 0:f610f2c606a8 | 7 | AnalogIn pH_sensor(A0); |
| sitakumar | 3:98adc27dc82d | 8 | AnalogIn temp_sensor(A1); |
| sitakumar | 2:46161d8200a2 | 9 | |
| sitakumar | 0:f610f2c606a8 | 10 | |
| sitakumar | 0:f610f2c606a8 | 11 | int main() |
| sitakumar | 0:f610f2c606a8 | 12 | { |
| sitakumar | 3:98adc27dc82d | 13 | pc.baud(115200); |
| sitakumar | 0:f610f2c606a8 | 14 | float voltage, pH, tempC, tempF; |
| sitakumar | 2:46161d8200a2 | 15 | //Power temperature sensor |
| sitakumar | 0:f610f2c606a8 | 16 | while(1) { |
| sitakumar | 1:843151144560 | 17 | //Take average of readings over 10 seconds |
| sitakumar | 0:f610f2c606a8 | 18 | double totalVal = 0.0; |
| sitakumar | 0:f610f2c606a8 | 19 | double pH_sensor_read = 0.0; |
| sitakumar | 3:98adc27dc82d | 20 | double totalValtemp = 0.0; |
| sitakumar | 3:98adc27dc82d | 21 | double temp_sensor_read = 0.0; |
| sitakumar | 0:f610f2c606a8 | 22 | int totalReadings = 0; |
| sitakumar | 0:f610f2c606a8 | 23 | time_t start = time(NULL); |
| sitakumar | 3:98adc27dc82d | 24 | time_t seconds = 5; |
| sitakumar | 0:f610f2c606a8 | 25 | time_t end = start + seconds; |
| sitakumar | 0:f610f2c606a8 | 26 | while(time(NULL) < end){ |
| sitakumar | 0:f610f2c606a8 | 27 | pH_sensor_read = pH_sensor.read(); |
| sitakumar | 0:f610f2c606a8 | 28 | totalVal = totalVal + pH_sensor_read; |
| sitakumar | 3:98adc27dc82d | 29 | temp_sensor_read = temp_sensor.read(); |
| sitakumar | 3:98adc27dc82d | 30 | totalValtemp = totalValtemp + temp_sensor_read; |
| sitakumar | 0:f610f2c606a8 | 31 | totalReadings++; |
| sitakumar | 3:98adc27dc82d | 32 | |
| sitakumar | 0:f610f2c606a8 | 33 | } |
| sitakumar | 0:f610f2c606a8 | 34 | double avgSensor = totalVal/(double)totalReadings; |
| sitakumar | 3:98adc27dc82d | 35 | double avgTemp = totalValtemp/(totalReadings); |
| sitakumar | 1:843151144560 | 36 | //Hard coded calibration values taken at pH 4 solution to return voltage in mV |
| sitakumar | 3:98adc27dc82d | 37 | //.24 is the pin read out at pH4 |
| sitakumar | 3:98adc27dc82d | 38 | //800 is mV at ph4 |
| sitakumar | 3:98adc27dc82d | 39 | //look at the documentation to figure out what readout correlates to what voltage |
| sitakumar | 3:98adc27dc82d | 40 | voltage = avgSensor*(3.3); |
| sitakumar | 0:f610f2c606a8 | 41 | //conversion to pH from sensor output voltage per LM61 data sheet |
| sitakumar | 4:bc63632c6808 | 42 | pH = (voltage-.60924)/.05226667; |
| sitakumar | 0:f610f2c606a8 | 43 | //conversion to degrees C from sensor output voltage |
| sitakumar | 4:bc63632c6808 | 44 | float voltageT = avgTemp*3.3*1000; |
| sitakumar | 4:bc63632c6808 | 45 | tempC = ((voltageT - 435.49)/-2.93); |
| sitakumar | 0:f610f2c606a8 | 46 | tempF = (tempC *9/5) + 32; |
| sitakumar | 0:f610f2c606a8 | 47 | //print current pH and temp |
| sitakumar | 3:98adc27dc82d | 48 | pc.printf("pH = %5.2F at voltage %5.2F V\n\r", pH, voltage); |
| sitakumar | 3:98adc27dc82d | 49 | pc.printf("temp = %5.2F F at voltage %5.2F V\n\r", tempF, voltageT); |
| sitakumar | 0:f610f2c606a8 | 50 | } |
| sitakumar | 0:f610f2c606a8 | 51 | } |
