Seeedstudio Arch Examples : Temperature sensing using thermistor and AnalogIn interface.

Dependencies:   mbed

Fork of Arch_GPIO_Ex4 by Visweswara R

Revision:
5:d035275d4c21
Parent:
4:ba523da0d68a
Child:
6:914bd412ceda
--- a/main.cpp	Tue Sep 17 01:56:36 2013 +0000
+++ b/main.cpp	Mon Oct 07 13:10:03 2013 +0000
@@ -1,15 +1,46 @@
 #include "mbed.h"
+#include "USBSerial.h"
 
-BusOut onboardLEDs(P1_8,P1_9,P1_10,P1_11); /*P1_8 - P1_11 are LED1 - LED4*/
+AnalogIn thermistor(P0_11);   /* Thermistor output connected to P0_11 */
+
+DigitalOut tensplaceLED(LED4);  /* This led blinks as per tens place of temperature value(in deg C) */
+DigitalOut unitsplaceLED(LED1); /* This led blinks as per units place of temperature value(in deg C) */
 
 int main()
 {
-    int i;
+    unsigned int a, beta = 3975, units, tens;
+    float temperature, resistance;
+
     while(1) {
-        for(i=0; i<16; i++) {
-            onboardLEDs.write(i); /* LED1 is LSB  and LED4 is MSB*/
-            wait(0.5);
+        a = thermistor.read_u16(); /* Read analog value */
+        
+        /* Calculate the resistance of the thermistor from analog votage read. */
+        resistance= (float) 10000.0 * (1.0 - (a / 65536.0 ));
+        
+        /* Convert the resistance to temperature using Steinhart's Hart equation */
+        temperature=(1/((log(resistance/5000.0)/beta) + (1.0/298.15)))-273.15; 
+        
+        units = (int) temperature % 10;
+        tens  = (int) temperature / 10;
+        
+        
+        for(int i=0; i< tens; i++)
+        {
+             tensplaceLED = 1;
+             wait(.200);
+             tensplaceLED = 0;
+             wait(.200);
         }
-
+        
+        for(int i=0; i< units; i++)
+        {
+             unitsplaceLED = 1;
+             wait(.200);
+             unitsplaceLED = 0;
+             wait(.200);
+        }
+      
+        wait(0.5);
     }
 }
+