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@0:f610f2c606a8, 2015-02-18 (annotated)
- Committer:
- sitakumar
- Date:
- Wed Feb 18 05:18:56 2015 +0000
- Revision:
- 0:f610f2c606a8
- Child:
- 1:843151144560
2/17
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 | 0:f610f2c606a8 | 8 | |
| sitakumar | 0:f610f2c606a8 | 9 | int main() |
| sitakumar | 0:f610f2c606a8 | 10 | { |
| sitakumar | 0:f610f2c606a8 | 11 | float voltage, pH, tempC, tempF; |
| sitakumar | 0:f610f2c606a8 | 12 | |
| sitakumar | 0:f610f2c606a8 | 13 | while(1) { |
| sitakumar | 0:f610f2c606a8 | 14 | double totalVal = 0.0; |
| sitakumar | 0:f610f2c606a8 | 15 | double pH_sensor_read = 0.0; |
| sitakumar | 0:f610f2c606a8 | 16 | int totalReadings = 0; |
| sitakumar | 0:f610f2c606a8 | 17 | time_t start = time(NULL); |
| sitakumar | 0:f610f2c606a8 | 18 | time_t seconds = 10; |
| sitakumar | 0:f610f2c606a8 | 19 | time_t end = start + seconds; |
| sitakumar | 0:f610f2c606a8 | 20 | while(time(NULL) < end){ |
| sitakumar | 0:f610f2c606a8 | 21 | pH_sensor_read = pH_sensor.read(); |
| sitakumar | 0:f610f2c606a8 | 22 | totalVal = totalVal + pH_sensor_read; |
| sitakumar | 0:f610f2c606a8 | 23 | totalReadings++; |
| sitakumar | 0:f610f2c606a8 | 24 | } |
| sitakumar | 0:f610f2c606a8 | 25 | double avgSensor = totalVal/(double)totalReadings; |
| sitakumar | 0:f610f2c606a8 | 26 | //hard coded calibration values taken at pH 4 solution to return voltage in mV |
| sitakumar | 0:f610f2c606a8 | 27 | voltage = avgSensor*(800/.24); |
| sitakumar | 0:f610f2c606a8 | 28 | //conversion to pH from sensor output voltage per LM61 data sheet |
| sitakumar | 0:f610f2c606a8 | 29 | pH = (0.0209*voltage)-12.696; |
| sitakumar | 0:f610f2c606a8 | 30 | //conversion to degrees C from sensor output voltage |
| sitakumar | 0:f610f2c606a8 | 31 | tempC = (((voltage/1000) - 0.871481)/-0.0021504); |
| sitakumar | 0:f610f2c606a8 | 32 | tempF = (tempC *9/5) + 32; |
| sitakumar | 0:f610f2c606a8 | 33 | //print current pH and temp |
| sitakumar | 0:f610f2c606a8 | 34 | pc.printf("pH = %5.2F & temp = %5.2F F\n\r", pH, tempF); |
| sitakumar | 0:f610f2c606a8 | 35 | } |
| sitakumar | 0:f610f2c606a8 | 36 | } |
