Adam Konrad / Mbed 2 deprecated TempTower

Dependencies:   BLE_API DnsQuery ESP8266Interface NetworkSocketAPI mbed nRF51822

Fork of BLE_TemperatureBeacon by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers temp.cpp Source File

temp.cpp

00001 #include "mbed.h"
00002 #include <math.h>
00003 AnalogIn thermistor(P0_3);
00004 
00005 int beta = 3975;
00006 float temperature, resistance;
00007 
00008 float getTemp() {
00009     unsigned int a = thermistor.read_u16(); /* Read analog value 16 bit 65536*/
00010     
00011     /* Calculate the resistance of the thermistor from analog votage read. positive feedback 100k to ground 10 bit ADC*/
00012     resistance= (float) 100000.0 * ((1023.0 / a) - 1.0);
00013 
00014     /* Convert the resistance to temperature using Steinhart's Hart equation */
00015     temperature=(1/((log(resistance/100000.0)/beta) + (1.0/298.15)))-273.15; 
00016     return temperature;
00017 }