Close

Temperature Sensor Integrating (Success)

A project log for Peril-Sensitive Sunglasses

A version of the Peril-Sensitive Sunglasses (as described by Douglas Adams in The Hitchhiker's Guide to the Galaxy)

Minimum Effective DoseMinimum Effective Dose 04/12/2014 at 07:500 Comments

Integrating the TMP36 temperature sensor was simple, I've used it before.  It looks like a transistor and outputs a voltage proportional to temperature.  Adafruit has a thorough guide on its use.

Making the sensor work was easy.  Using the temperature data to make meaningful decisions about detecting Peril is less easy.  Certainly, at a high level I want to assume Peril is present whenever the temperature rises or drops too suddenly, but how do you go about doing that, exactly? What temperature, exactly, does Peril drop in at? 

The devil is in the details, and when you are building something new it's all details.

I did choose a hard high and low temperature to use as "hard" Peril indicators (to detect, say, being engulfed in flames or ice) but I still needed to decide how to detect sudden, abnormal shifts.

I realized that a "sudden" shift in temperature is really a temperature change (up or down) that happens too quickly.  To measure temperature is easy - read the sensor.  But to decide whether the temperature change is too quick requires comparing temperature change X to an amount of time Y.

Change over Time is textbook calculus something.  It might definitely be a derivative, or maybe an integral.  Either way I don't know a lick more about it than that so I settled for a software framework that measures temperature regularly and creates rolling averages at different times.  A change of temperature in excess of X in time period Y is considered Perilous.   (X and Y values are a little up in the air right now but I'm sure a little fiddling will reveal something useful.)

That about wraps it up for the guts of the Temperature Sensor.

(Monitoring body temperature was out since it would require inserting a temperature probe somewhere into the body, which I'm fairly certain would be considered Perilous by other sensors, and the sunglasses would simply wind up being a self-fulfilling prophecy and possibly a paradox of some kind and that just wouldn't do at all.  So the temperature sensor remains more or less aimed at 'ambient'.)

TIP: For reasons that have to do with the output of the TMP36 sensor being high impedence, reading the sensor regularly and frequently and rapidly with the ADC can be glitchy.  A solution is twofold: 1) when you read the sensor, pause 10 milliseconds or so after each analogRead() of it, and 2) every time you want to read the sensor, read the sensor twice and throw away the first result.

Discussions