IoThack15

Dependencies:   mbed

Committer:
ramun
Date:
Sat Nov 07 01:37:28 2015 +0000
Revision:
0:5f28c9594b50
hack0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ramun 0:5f28c9594b50 1 #include "mbed.h"
ramun 0:5f28c9594b50 2
ramun 0:5f28c9594b50 3 AnalogIn thermistor(A1); /* Temperature sensor connected to Analog Grove connector */
ramun 0:5f28c9594b50 4
ramun 0:5f28c9594b50 5 int main()
ramun 0:5f28c9594b50 6 {
ramun 0:5f28c9594b50 7 unsigned int a, beta = 3975;
ramun 0:5f28c9594b50 8 float temperature, resistance;
ramun 0:5f28c9594b50 9
ramun 0:5f28c9594b50 10 while(1) {
ramun 0:5f28c9594b50 11 a = thermistor.read_u16(); /* Read analog value */
ramun 0:5f28c9594b50 12
ramun 0:5f28c9594b50 13 /* Calculate the resistance of the thermistor from analog votage read. */
ramun 0:5f28c9594b50 14 resistance= (float) 10000.0 * ((65536.0 / a) - 1.0);
ramun 0:5f28c9594b50 15
ramun 0:5f28c9594b50 16 /* Convert the resistance to temperature using Steinhart's Hart equation */
ramun 0:5f28c9594b50 17 temperature=(1/((log(resistance/10000.0)/beta) + (1.0/298.15)))-273.15;
ramun 0:5f28c9594b50 18
ramun 0:5f28c9594b50 19 //printf(" Temp Sensor Analog Reading is 0x%X = %d ", a, a);
ramun 0:5f28c9594b50 20 //printf("resistance %f",resistance);
ramun 0:5f28c9594b50 21 //printf("\n\rCurrent Temperature: %f C \n\r", temperature);
ramun 0:5f28c9594b50 22 printf("%.2f\n\r", temperature);
ramun 0:5f28c9594b50 23
ramun 0:5f28c9594b50 24 wait(2);
ramun 0:5f28c9594b50 25 }
ramun 0:5f28c9594b50 26 }