Seeedstudio Arch Examples : Temperature sensing using thermistor and AnalogIn interface.
Fork of Arch_GPIO_Ex4 by
main.cpp
00001 #include "mbed.h" 00002 00003 AnalogIn thermistor(P0_11); /* Thermistor output connected to P0_11 */ 00004 00005 DigitalOut tensplaceLED(LED4); /* This led blinks as per tens place of temperature value(in deg C) */ 00006 DigitalOut unitsplaceLED(LED1); /* This led blinks as per units place of temperature value(in deg C) */ 00007 00008 int main() 00009 { 00010 unsigned int a, beta = 3975, units, tens; 00011 float temperature, resistance; 00012 00013 while(1) { 00014 a = thermistor.read_u16(); /* Read analog value */ 00015 00016 /* Calculate the resistance of the thermistor from analog votage read. */ 00017 resistance= (float) 10000.0 * ((65536.0 / a) - 1.0); 00018 00019 /* Convert the resistance to temperature using Steinhart's Hart equation */ 00020 temperature=(1/((log(resistance/5000.0)/beta) + (1.0/298.15)))-273.15; 00021 00022 units = (int) temperature % 10; 00023 tens = (int) temperature / 10; 00024 00025 00026 for(int i=0; i< tens; i++) 00027 { 00028 tensplaceLED = 1; 00029 wait(.200); 00030 tensplaceLED = 0; 00031 wait(.200); 00032 } 00033 00034 for(int i=0; i< units; i++) 00035 { 00036 unitsplaceLED = 1; 00037 wait(.200); 00038 unitsplaceLED = 0; 00039 wait(.200); 00040 } 00041 00042 wait(0.5); 00043 } 00044 } 00045
Generated on Tue Jul 12 2022 17:49:52 by 1.7.2