Class to read temperature measurements from Seeed Studio's IR temperature sensor
Dependents: Seeed_Grove_4_Digit_Display_Clock
SeeedIRTempSensor.h@0:fa362542d13e, 2017-05-21 (annotated)
- Committer:
- tulanthoar
- Date:
- Sun May 21 19:44:02 2017 +0000
- Revision:
- 0:fa362542d13e
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tulanthoar | 0:fa362542d13e | 1 | /* #include <cmath> */ |
tulanthoar | 0:fa362542d13e | 2 | #include "mbed.h" |
tulanthoar | 0:fa362542d13e | 3 | namespace IRTempSensor{ |
tulanthoar | 0:fa362542d13e | 4 | #define SUR_TEMP_PIN PA_3 // Analog input pin connect to temperature sensor SUR pin |
tulanthoar | 0:fa362542d13e | 5 | #define OBJ_TEMP_PIN PC_0 // Analog input pin connect to temperature sensor OBJ pin |
tulanthoar | 0:fa362542d13e | 6 | |
tulanthoar | 0:fa362542d13e | 7 | double measuresureTemp(PinName surPin) { |
tulanthoar | 0:fa362542d13e | 8 | AnalogIn surTPin(surPin); |
tulanthoar | 0:fa362542d13e | 9 | float volts, resistance, temperature; |
tulanthoar | 0:fa362542d13e | 10 | volts = 0; |
tulanthoar | 0:fa362542d13e | 11 | for (int i = 0; i < 100; i++) { |
tulanthoar | 0:fa362542d13e | 12 | volts += surTPin.read(); |
tulanthoar | 0:fa362542d13e | 13 | wait_us(10); |
tulanthoar | 0:fa362542d13e | 14 | } |
tulanthoar | 0:fa362542d13e | 15 | volts *= 3.3/100; |
tulanthoar | 0:fa362542d13e | 16 | resistance = 2000000*volts/(2.5-volts); |
tulanthoar | 0:fa362542d13e | 17 | temperature = 1/(log(resistance/100000)/3964 +(1/298.15)) - 273.15; |
tulanthoar | 0:fa362542d13e | 18 | return temperature; |
tulanthoar | 0:fa362542d13e | 19 | } |
tulanthoar | 0:fa362542d13e | 20 | |
tulanthoar | 0:fa362542d13e | 21 | float measureObjectTemp(PinName surPin, PinName objPin) { |
tulanthoar | 0:fa362542d13e | 22 | AnalogIn objTPin(objPin); |
tulanthoar | 0:fa362542d13e | 23 | float objV = 0; |
tulanthoar | 0:fa362542d13e | 24 | for (int i = 0; i < 100; i++) { |
tulanthoar | 0:fa362542d13e | 25 | objV += objTPin.read(); |
tulanthoar | 0:fa362542d13e | 26 | wait_us(10); |
tulanthoar | 0:fa362542d13e | 27 | } |
tulanthoar | 0:fa362542d13e | 28 | objV *= 3.3/100; |
tulanthoar | 0:fa362542d13e | 29 | /* float pileSignal= objV - 2.5*17.4/(17.4+64); */ |
tulanthoar | 0:fa362542d13e | 30 | float pileSignal = objV - 0.52; |
tulanthoar | 0:fa362542d13e | 31 | pileSignal *= 0.01; |
tulanthoar | 0:fa362542d13e | 32 | float ts = measuresureTemp(surPin) + 273.15; |
tulanthoar | 0:fa362542d13e | 33 | /* float calib = 1+(298.15 - ts)*0.0011; */ |
tulanthoar | 0:fa362542d13e | 34 | float calib = 1; |
tulanthoar | 0:fa362542d13e | 35 | float k = 3.45*pow(10,-13)*calib; |
tulanthoar | 0:fa362542d13e | 36 | float kRecip = 2976078405624.9985; |
tulanthoar | 0:fa362542d13e | 37 | float kRecipAmp = kRecip * 0.01; |
tulanthoar | 0:fa362542d13e | 38 | /* float objT = (pileSignal*kRecip + ts*ts*ts*ts); */ |
tulanthoar | 0:fa362542d13e | 39 | float objT = (objV*kRecipAmp -0.51*kRecipAmp + ts*ts*ts*ts); |
tulanthoar | 0:fa362542d13e | 40 | return pow(objT,0.25) - 273.15; |
tulanthoar | 0:fa362542d13e | 41 | /* return pileSignal*1000; */ |
tulanthoar | 0:fa362542d13e | 42 | /* return objV*100; */ |
tulanthoar | 0:fa362542d13e | 43 | }}; |