Better precision with Arduino (floats)
<p>I'm trying to do the Steinhart-Hart temperature calculation on an Arduino. The equation is <a href="https://i.stack.imgur.com/Dg9rq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dg9rq.png" alt="enter image description here"></a></p>

<p>I solved a system of 3 equations to obtain the values of A, B and C, which are: </p>

<pre><code>A = 0.0164872
B = -0.00158538
C = 3.3813e-6
</code></pre>

<p>When I plug these into WolframAlpha to solve for <code>T</code> I get a value in Kelvins that makes sense: </p>

<p><code>T=1/(0.0164872-0.00158538*log2(10000)+3.3813E-6*(log2(10000))^3) solve for T</code> </p>

<p><code>T = 298.145 Kelvins = 77 Fahrenheit</code></p>

<p>However when I try to use this equation on my Arduino, I get a very wrong answer, I suspect because doubles do not have enough precision. Here's what I'm using: </p>

<p><code>double temp = (1 / (A + B*log(R_therm) + C*pow(log(R_therm),3)));</code></p>

<p>This returns 222 Kelvin instead, which is way off. </p>

<p>So, how can I do a calculation like this in Arduino?? Any advice is greatly appreciated, thanks. </p>