{"id":16,"date":"2013-09-13T01:12:00","date_gmt":"2013-09-13T01:12:00","guid":{"rendered":""},"modified":"2021-07-18T19:39:47","modified_gmt":"2021-07-18T19:39:47","slug":"entertainment-center-thermostat","status":"publish","type":"post","link":"http:\/\/cockfieldofdreams.com\/blog\/2013\/09\/entertainment-center-thermostat.html","title":{"rendered":"Entertainment Center Thermostat"},"content":{"rendered":"<p>I use a china hutch from my grandmother&#8217;s old house as my entertainment center. I never really liked displaying all of one&#8217;s electronics and wires and stuff where everyone can see them, so this suits my needs quite nicely. HOWEVER! This particular piece of furniture doesn&#8217;t have very good ventilation for all of my heat-producing electronics, and it has a tendency to get a bit toasty inside the cupboard unless I left a door open. I decided to fix that by putting some exhaust fans on the outside and hooking them up to an ATtiny45 microcontroller and a temperature sensor. Now, when the temperature inside the hutch rises beyond a certain level (around 95 degrees F) the fans are turned on so the Playstation 3 and Crown amplifier don&#8217;t overheat in the modified entertainment center.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-10-20-43-AM.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" height=\"239\" src=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-10-20-43-AM-300x224.jpg\" width=\"320\" \/><\/a><\/div>\n<p>The first step was the prototyping! I had a HUGE problem here with what should have been a simple circuit. The output of the voltage sensor was supposed to be around 0.75V at room temperature, and it would increase linearly as the temperature increased. (I used a hair dryer to model temperature fluctuations.) I was not getting any sort of reliable data from the sensor whenever the microcontroller was attached to the power rails of the circuit, but I found out that this was due to a lack of &#8220;decoupling capacitors&#8221; that I had failed to place near the sensor and on the power rail. I&#8217;m not 100% sure how this solved my problem, but as an engineer I&#8217;m not bound by the need to find answers, but rather simply by a need to get whatever it is working.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-11-56-32-AM.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" height=\"320\" src=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-11-56-32-AM-224x300.jpg\" width=\"239\" \/><\/a><\/div>\n<p>Soldering everything together. The red\/black wires sticking out of the top of the circuit go to the power supply, which I stole from an old cell phone charger. +5V from a SMPS saves me the time of building a power supply (trivial, but sometimes frustrating). The wires to the right are my dead-bug soldering of the temperature sensor and decoupling capacitor. These will be outside of the enclosure that the rest of the electronics will reside in:<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-12-40-25-PM.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" height=\"320\" src=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-12-40-25-PM-224x300.jpg\" width=\"239\" \/><\/a><\/div>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-12-51-56-PM.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" height=\"239\" src=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Jul-21-12-51-56-PM-300x224.jpg\" width=\"320\" \/><\/a><\/div>\n<p>I mounted the fans to the cardboard backing of the &#8220;entertainment center&#8221;. The one on the bottom right blows in, and the one on the upper left blows out, for a nice circulating effect.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Sep-12-8-57-37-PM.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img decoding=\"async\" loading=\"lazy\" border=\"0\" height=\"239\" src=\"http:\/\/cockfieldofdreams.com\/blog\/wp-content\/uploads\/2013\/09\/Photo-Sep-12-8-57-37-PM-300x224.jpg\" width=\"320\" \/><\/a><\/div>\n<p><span><\/span><span><\/span><br \/>Everything put together! I was told that my color scheme is a little off, but at least it looks better now without the doors wide open any time I want to turn the TV on or listen to music.<\/p>\n<p>HERE&#8217;S THE CODE! I&#8217;ve had to make some changes to the temperature settings. At first the fans would kick on and off once every five to seven minutes, which I thought was too fast. Then I changed the settings and they wouldn&#8217;t come on at all. I think I have it JUST RIGHT now.<\/p>\n<p><span style=\"font-family: monospace;\">\/*<\/span><br \/><span style=\"font-family: monospace;\">this program turns a switch on at approximately 90 degrees<\/span><br \/><span style=\"font-family: monospace;\">it turns the switch off at approximately 85 degrees<\/span><br \/><span style=\"font-family: monospace;\">it is designed to be used with a TMP36 temperature sensor<\/span><br \/><span style=\"font-family: monospace;\">output signal on\/off is ATtiny pin 5 (digital pin 0)<\/span><br \/><span style=\"font-family: monospace;\">input signal from TMP36 is ATtiny pin 7 (analog pin 1)<\/span><br \/><span style=\"font-family: monospace;\">*\/<\/span><br \/><span style=\"font-family: monospace;\"><br \/><\/span><span style=\"font-family: monospace;\">#include &lt;avr\/io.h&gt;<\/span><br \/><span style=\"font-family: monospace;\">#include &lt;util\/delay.h&gt;<\/span><br \/><span style=\"font-family: monospace;\">\/\/setFlag keeps the program from continuously writing pins<\/span><br \/><span style=\"font-family: monospace;\">\/\/if it doesn&#8217;t need to. this makes it one-shot and hopefully<\/span><br \/><span style=\"font-family: monospace;\">\/\/saves a few bits of energy<\/span><br \/><span style=\"font-family: monospace;\">int setFlag = 0;<\/span><br \/><span style=\"font-family: monospace;\"><br \/><\/span><span style=\"font-family: monospace;\">void setup() {<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/set pin modes<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; pinMode(0, OUTPUT);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; pinMode(2, INPUT);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/turn on the fans to make sure the program is working<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; digitalWrite(0, HIGH);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; _delay_ms(2000);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/then turn them off to allow the program to run<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; digitalWrite(0, LOW);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; _delay_ms(500);<\/span><br \/><span style=\"font-family: monospace;\">}<\/span><br \/><span style=\"font-family: monospace;\"><br \/><\/span><span style=\"font-family: monospace;\">void loop() {<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/measure the voltage at pin 7:<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; int sensorValue = analogRead(1);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/calculate the voltage. at room temperature it should be around .760V<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; float volts = sensorValue * (5.0 \/ 1024.0);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/calculate the temperature in Celsius<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; float degC = (100.0 * volts) &#8211; 50.0;<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/make a decision about whether or not to turn the fan on or off<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/the microcontroller effectively acts as a schmitt trigger<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; if (degC &gt; 32 &amp;&amp; setFlag == 0) {<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; &nbsp; digitalWrite(0, HIGH);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; &nbsp; setFlag = 1;<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; }<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; if (degC &lt; 25.5 &amp;&amp; setFlag == 1) {<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; &nbsp; digitalWrite(0, LOW);<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; &nbsp; setFlag = 0;<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; }<\/span><br \/><span style=\"font-family: monospace;\">&nbsp;&nbsp;<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; \/\/only take a reading once every 10 seconds<\/span><br \/><span style=\"font-family: monospace;\">&nbsp; _delay_ms(10000);<\/span><br \/><span style=\"font-family: monospace;\">}<\/span><\/p>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I use a china hutch from my grandmother&#8217;s old house as my entertainment center. I never really liked displaying all of one&#8217;s electronics and wires and stuff where everyone can see them, so this suits my needs quite nicely. HOWEVER! This particular piece of furniture doesn&#8217;t have very good ventilation for all of my heat-producing &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/cockfieldofdreams.com\/blog\/2013\/09\/entertainment-center-thermostat.html\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Entertainment Center Thermostat&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":186,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts\/16"}],"collection":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":1,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":191,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions\/191"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/media\/186"}],"wp:attachment":[{"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cockfieldofdreams.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}