The Cave Pearl Project's Edward Mallon Showcases Accurate Temperature Sensing with a Single Diode

With nothing more than a microcontroller and a single diode — or even no external components at all — Mallon shows how to read temperatures.

Edward Mallon, co-founder of the Cave Pearl Project effort to map and understand the flow of water through cave systems, has written a guide to using a simple diode — or even no external components at all, with many microcontrollers — as a temperature sensor for a microcontroller, based on its reverse bias leakage.

Having previously experimented with using light-emitting diodes (LEDs) as sensors, Mallon began researching the use of different diode types as sensors — exploiting the components' reverse bias leakage effect. Having found a Jeelabs post measuring the leakage in three common diode types, Mallon spotted a note discussing how the reverse current could be used as a temperature sensor - and set about doing exactly that.

"It's worth noting that most diode based temperature sensors use the change in forward voltage because that relationship is linear, with about 2mV less voltage drop for every degree increase of temperature. But chasing a few millivolts with Arduino's 10-bit ADC only allows a precision of ±1°C unless you add amplification, or some other trick," Mallon writes. "By comparison, leakage current can be expected to double with every 10°C increase in temperature, making higher resolutions possible with the same hardware.

"The trade off is using a non-linear relationship which produces variable resolution over the sensing range. And since leakage is also a by-product of manufacturing variations you need to calibrate each diode individually. That’s a show-stopper in production environments where that time costs more than the whole device, but not so much for DIY projects which need to run-test their build for a few days anyway."

By calibrating for each component and using the Steinhart-Hart equation to convert discharge time into a temperature reading, Mallon was able to achieve an accuracy of ±0.1°C over a 40-degree range. "My gut feeling is that the re-purposed equation would work over a wider range if this was a single diode system," Mallon explains. "However AVR inputs are also connected to two protection diodes and a pull-up MOSFET. Each of these is subject to its own reverse bias leakage to some extent, with the upper protection diode acting in direct opposition to the discharge of the ‘sensor’ diode. In fact, you can simply run the ICU timing code with nothing at all connected to the D8 pin, and it will still give you a temperature based reading."

Mallon's full write-up, including the code required to try it yourself, is available on the Cave Pearl Project blog.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles