Friday, June 28, 2013

Temperature Guage and ?

Well, one thing I can say is that being busy with all manner of other stuff (see Figure 1) leaves me little time to blog about it. I guess that's fine but I'd like to keep a history of at least some of the junk I'm doing and learning about electronics. So here goes an update!

Figure 1: Kerbal Space Program: It takes time to run a multi-world space program!

So, the temperature guage bit is done. I need to purchase additional sensors (next is humidity and air-pressure).

Part of what I'm doing at the moment with the thermostat/thermometer is playing with showing some trends. Nothing very fancy but it's interesting enough to do.

Currently I display Celsius and Fahrenheit with either an up-arrow, down-arrow or weird-character next to that. Up means temperatures have been rising (over a certain timeframe). Down... you know. The weird character means the temperature really hasn't strayed out of a certain range so I consider the temperature to not be changing.


Also (as you can see in the photo) I change the background color of the display depending on how warm it is. Anything below 65 is a light teal, between 65-68 is a nice violet and above 68 is an ANGRY RED!

Trends for getting warmer or cooler are currently calculated over 5 minute periods. The error threshold is set to 1 degree so the arrows do change pretty often. By trend I mean a least-squares regression.

So basically in the code there is a counter that is read. It's the Arduino millis() function that gives me the number of milliseconds since the Arduino was reset. Five minutes is a nice neat 300,000 milliseconds so that's why I pick that number.

Once I get the value from millis() I add 300,000 to it and store it in my float timeCheck variable. Once millis() returns timeCheck I calculate my trend. I'm not fitting a curve here--just a simple slope calculation:


My tolerance to determine if the slope is to be considered an actual up/down change is 2 degrees. So basically in the code (I'll dump that out in a later post) I store the value of the temperature, then 300,000 milliseconds later I calculate the slope. If it's greater than |2| then I'll display an up-arrow or down-arrow based on the actual sign (+/-) of m.

Nothing special... and really just a slow-changing indicator of what the previous "5-minute bucket" was trending. Really for the future I'll probably look at holding some data on an SD card and providing slopes over the course of different timeframes (various hours I guess). Plus then we could also do a nice graph from that data using least squares regression or something.

I suppose I'll be adding a humidity sensor next!

-~-~-~-~-~-~-

No comments:

Post a Comment