Temperature Sensing

Dependencies:   mbed

Fork of Arch_Analog_Thermistor_Blinker by Visweswara R

main.cpp

Committer:
yihui
Date:
2014-08-20
Revision:
7:5c2ade6745ae
Parent:
6:914bd412ceda

File content as of revision 7:5c2ade6745ae:

#include "mbed.h"

AnalogIn thermistor(A1);   /* Temperature sensor connected to Analog Grove connector */

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()
{
    unsigned int a, beta = 3975, units, tens;
    float temperature, resistance;

    while(1) {
        a = thermistor.read_u16(); /* Read analog value */
        
        /* Calculate the resistance of the thermistor from analog votage read. */
        resistance= (float) 10000.0 * ((65536.0 / a) - 1.0);
        
        /* Convert the resistance to temperature using Steinhart's Hart equation */
        temperature=(1/((log(resistance/10000.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);
    }
}