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
Diff: main.cpp
- Revision:
- 0:f610f2c606a8
- Child:
- 1:843151144560
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Feb 18 05:18:56 2015 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+#include "time.h"
+
+DigitalOut myled(LED1);
+//serial connection via USB
+Serial pc(USBTX, USBRX);
+AnalogIn pH_sensor(A0);
+
+int main()
+{
+ float voltage, pH, tempC, tempF;
+
+ while(1) {
+ double totalVal = 0.0;
+ double pH_sensor_read = 0.0;
+ int totalReadings = 0;
+ time_t start = time(NULL);
+ time_t seconds = 10;
+ time_t end = start + seconds;
+ while(time(NULL) < end){
+ pH_sensor_read = pH_sensor.read();
+ totalVal = totalVal + pH_sensor_read;
+ totalReadings++;
+ }
+ double avgSensor = totalVal/(double)totalReadings;
+ //hard coded calibration values taken at pH 4 solution to return voltage in mV
+ voltage = avgSensor*(800/.24);
+ //conversion to pH from sensor output voltage per LM61 data sheet
+ pH = (0.0209*voltage)-12.696;
+ //conversion to degrees C from sensor output voltage
+ tempC = (((voltage/1000) - 0.871481)/-0.0021504);
+ tempF = (tempC *9/5) + 32;
+ //print current pH and temp
+ pc.printf("pH = %5.2F & temp = %5.2F F\n\r", pH, tempF);
+ }
+}
\ No newline at end of file
