I am trying to implement an PT100 sensor algo and I am blocked. I can’t seem to figure out where to plug in all of the numbers.
Here is the linearisation algo:
R(t) = R(0)(1 + A * t + B * t^2)
R0 = 100 Ohm
A=3,908 x 10^-3
B=-5,775 x 10^-7
I am having trouble with how to code 10^-3 or 10^7 and keep getting scalar expected errors.
`// assign hardware.pin5 to a global variable
therm <- hardware.pin8;
// therm2 <- hardware.pin9;
// configure pin5 to be an ANALOG_IN
therm.configure(ANALOG_IN);
// therm2.configure(ANALOG_IN);
// these constants are particular to the thermistor we’re using
// check your datasheet for what values you should be using
const a_therm = 3.9083*(10^-3);
const b_therm = -5.775*(10^-7);
// const t0_therm = 273.15;
// the resistor in the circuit (100Ω)
const R2 = 100.0;
//set relay variables to off
// relaystrikeState <- false;
relaymashstate <- false;
function MashTemp_C() {
local Vin = hardware.voltage();
local Vout = Vin * therm.read() / 65535.0;
local R_Therm = (R2*Vin / Vout) - R2;
local mashresistalgo = R2*(1 + R_Therm*a_therm + b_therm*(R_Therm*R_Therm));
local mashtemp_C = (R2*a_therm) / (a_therm - R2*mashresistalgo)
return mashtemp_C;
}
function startWarmup() {
// Get and log Fahrenheit temperature
local mashtemp = MashTemp_C();
server.log(mashtemp + " C");
targetMashTemp <- 163; //Target Mash Temperature
targeHyst <- 0.2; //Hysteresis to avoid Relay jitter
if (mashtemp < (targetMashTemp-targeHyst)) //Turn on Mash circulation pump
{
if (!relaymashstate)
{
relaymashstate = true;
server.log("Mash Relay Off");
}
}
else if (mashtemp > (targetMashTemp-targeHyst)) //Turn off Strike heat
{
if (relaymashstate = false);
server.log("Mash Relay On");
}
mashrelay <- hardware.pinB;
strikerelay <- hardware.pinC;
// configure LED pin for DIGITAL_OUTPUT
mashrelay.configure(DIGITAL_OUT);
strikerelay.configure(DIGITAL_OUT);
// hardware.pinB.write(relaystrikeState?1:0);
hardware.pinC.write(relaymashstate?1:0);
// wakeup in 5 seconds and read the value again:
imp.wakeup(5.0, startWarmup);
}
startWarmup()`