Ramun Hofmann
/
New_Seeed_Test
IoThack15
main.cpp
- Committer:
- ramun
- Date:
- 2015-11-07
- Revision:
- 0:5f28c9594b50
File content as of revision 0:5f28c9594b50:
#include "mbed.h" AnalogIn thermistor(A1); /* Temperature sensor connected to Analog Grove connector */ int main() { unsigned int a, beta = 3975; 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; //printf(" Temp Sensor Analog Reading is 0x%X = %d ", a, a); //printf("resistance %f",resistance); //printf("\n\rCurrent Temperature: %f C \n\r", temperature); printf("%.2f\n\r", temperature); wait(2); } }