Introduction: How to Calibrate a Cheap Temperature Sensor
I have a lot of electronics projects that involves temperature reading. Weather stations, room monitoring, or just to check the temperature of a part and trigger a fan, are some typical applications that require temperature sensors.
I discovered an advertising on a website about a very cheap temperature sensor made by Microchip. I took the opportunity of an online order to add some of these sensors. They were cheap, but the initial precision is only ±2°C. But with a simple calibration, the accuracy can be increased to ±0.5°C ! We'll see in this Instructable how to do this.
Step 1: About the Sensor
Ok, the sensor is the MCP9700. I was able to get them for 0.2€ par part. The output signal is an analog tension in the range 0..5V, it means that you can use an ADC pin of a micro-controller to simply get the temperature. It doesn't need any other part ! The temperature range is -40 to 150°C. Good enough for my projects !!
The sensor is available in different packages, I choose the TO-92 models.
The sensor datasheet is here. A lot of useful information are inside !
Step 2: Arduino Code, Wiring and First Tests
Ok, as the output signal is an analog tension, the Arduino wiring and sketch is very simple. The sensor, pins down and text facing you, is :
- left pin : Vdd -> to Arduino 5v
- middle pin : Vout -> to arduino A0 pin
- right pin : GND -> to arduino GND
The code is attached. It's a simple analog reading. To make the measure more accurate, I use a simple loop to get 5 temperatures values and to compute the average temperature.
On page 11 of the datasheet, the sensor transfer function formula is given : Vout = Tc * Ta + V0c
- Vout : the output tension (read from the arduino)
- Tc : Temperature coefficient
- Ta : Ambient temperature (we are looking for this value)
- V0c : sensor output voltage at 0°C
This last value is given in the "DC electrical characteristics" table, page 3 of the datasheet. For my sensor (the MCP9700), this value is 500 mV.
It means that , for my Arduino, that the ambient temp formula is :
Temperature = ( (TensionAnalog /204.8) - 0.5) / 0.01 ;
- TensionAnalog is the raw value taken from the analog pin. The arduino ADC is a 10 bits range, so the read value range is 1024 (2^10) for 5 volts, and 0 for 0 volts. So to get a value in volts, you need to divide the analog value by 1024/5 = 204.8
- The 0.5 is the V0C value, in volt (500 mV)
- 0.01 is the temperature coefficient Tc (10 mV / °C)
I set up the sensor and my weather station sensor on my window, in order to compare the temperatures.
After a few minutes, my station says that the ambient temperature is 26.4. Meanwhile, the sensor says that the temperature is... 24.8°C. we are in the tolerance given by Microchip, but not enough accurate.
Let's change this !
Step 3: Calibration
Ok, as we consider that the temperature output is a linear function, and the temperature coefficient is right, we need to modify the offset of VoC.
The "exact" temperature sensor (my weather station reference), regarding the sensor values, are, in average, (the average value was computed with Excel) 1.98°C higher.
The actual V0C offset is 500mV, so it means that the new offset should be 500-1.98, so 480.2.
My new temperature formula is now :
TemperatureMoyenne = TemperatureMoyenne + ( ( (TensionAnalog /204.8) - 0.4802) / 0.01);
Same installation, the new results are now better.
Step 4: Conclusion
We have seen how to compare a temperature taken from a cheap sensor to make it more accurate. Of course, my calibration technique is not great, as I suppose that the output signal is fully linear, I didn't take the effects of the self-heating,the sensor is black, my weather station sensor is white, so, not very good.
Microchip says, page 11 of the datasheet, that the accuracy can be improved by calibrating the sensor at 25°C (just done). An application reference is also given, if you want to learn more.
But remember that chip costs 0.2€, and I didn't really need an incredible precision. The method described here is only a way to get better values, not fully accurate ones. In case of precision, just get a thermocouple or a more accurate (and expensive) sensors !
Final word : we got a violent thunder a few hours after my calibration (my weather station was right^^). The temperature drops at 18°C, and the sensors values were OK.... !
We have a be nice policy.
Please be positive and constructive.