Thursday, September 12, 2013

Entertainment Center Thermostat

I use a china hutch from my grandmother's old house as my entertainment center. I never really liked displaying all of one'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'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't overheat in the modified entertainment center.

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 "decoupling capacitors" that I had failed to place near the sensor and on the power rail. I'm not 100% sure how this solved my problem, but as an engineer I'm not bound by the need to find answers, but rather simply by a need to get whatever it is working.

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:

I mounted the fans to the cardboard backing of the "entertainment center". The one on the bottom right blows in, and the one on the upper left blows out, for a nice circulating effect.

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.

HERE'S THE CODE! I'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't come on at all. I think I have it JUST RIGHT now.

this program turns a switch on at approximately 90 degrees
it turns the switch off at approximately 85 degrees
it is designed to be used with a TMP36 temperature sensor
output signal on/off is ATtiny pin 5 (digital pin 0)
input signal from TMP36 is ATtiny pin 7 (analog pin 1)

#include <avr/io.h>
#include <util/delay.h>
//setFlag keeps the program from continuously writing pins
//if it doesn't need to. this makes it one-shot and hopefully
//saves a few bits of energy
int setFlag = 0;

void setup() {
  //set pin modes
  pinMode(0, OUTPUT);
  pinMode(2, INPUT);
  //turn on the fans to make sure the program is working
  digitalWrite(0, HIGH);
  //then turn them off to allow the program to run
  digitalWrite(0, LOW);

void loop() {
  //measure the voltage at pin 7:
  int sensorValue = analogRead(1);
  //calculate the voltage. at room temperature it should be around .760V
  float volts = sensorValue * (5.0 / 1024.0);
  //calculate the temperature in Celsius
  float degC = (100.0 * volts) - 50.0;
  //make a decision about whether or not to turn the fan on or off
  //the microcontroller effectively acts as a schmitt trigger
  if (degC > 32 && setFlag == 0) {
    digitalWrite(0, HIGH);
    setFlag = 1;
  if (degC < 25.5 && setFlag == 1) {
    digitalWrite(0, LOW);
    setFlag = 0;
  //only take a reading once every 10 seconds

Tuesday, September 3, 2013

Just for Fun

So I decided I had had enough of practical, useful projects, and I built this:

The circuit is called a Slayer Exciter. It is a hand-wound air-core transformer (it took me about two hours to wind the transformer; the red cylinder in the picture is actually about 400 turns of 34-gauge magnet wire) capable of generating a high voltage and a very strong electric field capable of illuminating a fluorescent light bulb. There are lots of online how-tos floating around which go into great detail about this "poor man's Tesla coil" so I won't go into great detail here. Basically, it's a very simple oscillating circuit consisting of a transistor, two diodes, and some resistors that can turn a low voltage DC source into very high voltage AC. Here are some pictures! 

Some prototyping, just to make sure it all works: 

Putting it all together on a piece of wood, as I am wont to do with electrical things:

 And, on an unrelated note, perhaps the most random two things to be purchased at one time from Amazon. A 14-ounce tin of almond flour for gluten-free baking and a Lieutenant Commander Geordi Laforge action figure to make sure I have the nerdiest cubicle in the office: