Description: using LM35 sensor to calculate the temperature

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Victordang
Date:
Mon Apr 02 05:44:11 2018 +0000
Commit message:
update LM35

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 237dc73ab9ff main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 02 05:44:11 2018 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+#include "string"
+PwmOut motor(p21);
+Serial pc(USBTX, USBRX); //enable serial port which links to USB 
+AnalogIn sensor(p15); //LM35 sensor
+int main() {
+int i,N=400;
+ float tempC, avg,a[N];    pc.printf("\r\nLM35 Temperature Program");
+    pc.printf("\r\n******************\r\n");
+    wait(1); // wait 1 second for device stable status
+    while (1) {
+avg = 0;
+for(i=0;i<N;i++)        {
+            a[i]=sensor.read();
+            wait(.01);
+        }
+        for(i=0;i<N;i++)        {
+            avg=avg+(a[i]/10*1000); //divide to 10mV
+}
+tempC = (avg/N*10); 
+pc.printf("\n\rTemperature is %4.1f C, avg = %4.5f  \r\n",tempC, avg/N);
+wait(1);
+    }
+   }
diff -r 000000000000 -r 237dc73ab9ff mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Apr 02 05:44:11 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file