After having learned how to drive a nixie tube with Arduino, today I’ll show you how to read the data coming from the temperature sensor.
The sensor I chose, designed for liquid coolers, it’s a 10Kohm thermistor. It’s indeed a resistor whose value changes based on its temperature; the nominal value (10Kohm for my sensor) is the resistance the sensor has at a temperature of 25°.
I can therefore use an analog PIN of my Arduino to read the voltage across the sensor and then calculate the resistance. You also need to add a pull-down resistor – this too with a value of 10Kohm – as it follows:
To convert the raw data read by Arduino’s ADC (analog to digital converter) to a temperature value, you can use the Steinhart-Hart equation:
this equation calculates the absolute temperature (T, Kelvin) from the resistance (R) and 3 constants that depends on the specific thermistor you’re using. For 10Kohm sensors, the typical values of the constants are:
- a =0.001129148
- b =0.000234125
- c = 0.0000000876741
You can now write a function that calculates the Celsius temperature (Kelvin – 273,15) having the value returned by analogRead() (RawADC) as its input:
double Thermistor(int RawADC) { long Resistance; double Temp; Resistance = 10000.0*((1024.0 / RawADC) - 1); Temp = log(Resistance); Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp)); Temp = Temp - 273.15; return Temp; } |
I wrote a sketch (available on Github) that, every two seconds, reads the temperature from a thermistor connected to PIN A0 and displays it on the serial monitor: