Saturday, January 30, 2010

Turing-Complete Slow Cooker

The idea on this one is to put my new slow cooker on the internet, so if I can't make it home in time to turn it off and have a delicious dinner, I can log in to my apartment over an SSH tunnel and turn off my slow cooker from anywhere in the world. Great idea! Eventually I'll be able to expand this to other devices. Maybe have my whole kitchen on the internet. Who knows?

The first step is to figure out how to interface with a computer's parallel port. There are 25 pins on a standard parallel port, and eight of them can be physically controlled to be either 0 or 5 volts. And, as I've learned from previous projects, this is enough to operate a MOSFET and control fun things! So I can theoretically control eight devices in the kitchen. I'll probably plug the kitchen light into it because it'd be easy after what I did to it already, but maybe Bradley's coffee pot is next...

These ports used to be used for printers but are largely considered "legacy" now, so I will be using a 1996-era Packard Bell with a Pentium II to interface with various appliances. I installed Ubuntu 9.04 (I didn't have a 9.10 CD but whatever, I'm just using a command-line interface) and then decided to try Python out. I found this page on Ubuntu Forums to start off:

Ubuntu Forums!

After messing around with Python for a little bit I found this tutorial which uses C:


I had to change a couple of things with the source code but I think this is the route I'm going to take. I'm not the world's strongest programmer but I think this will be enough. Eventually, I may go back and switch to Python because someone wrote a GUI to alter the pins on the parallel port. Any way, I have already been able to SSH into the computer I'm going to use to control the pins on the parallel port and am going to start wiring everything up this afternoon. Clemson's iced over so everyone's freaking out and not doing anything interesting, so this will have to do! But to be honest I'd probably be doing this any way. Electricity is awesome.

Friday, January 29, 2010

Fun Tidbits!

No project here, just some fun things I have been thinking about. The first one comes from Georgia Tech Craig, who sent me this website:

Only at Tech

Reminds me of a lot of things that I do and kind of makes me want to be a student at Georgia Tech. Which happens a lot more than I think people realize. After all, Clemson is just Georgia Tech lite, with women. Any way, this site reminded me of some things that I have done that were "only at tech" moments:

My roommate Craig (not from Georgia Tech) and I used to lift weights fairly regularly. He's a bigger guy than me even though I'm about a foot taller than he is, and he can bench press slightly less than double what I can. So one night I spent the evening calculating our power-to-weight ratios to make myself feel a little better about this. Since I'm about 30 pounds lighter AND my arms are longer so I do more work since I lift the weights farther, I figured this would work out in my favor. Craig's was 8 watts per kilogram and mine was 5.5 watts per kilogram, which I guess is good because it's more than half of Craig's.

The other good one was dealing with the doors in Riggs Hall, Clemson's electrical engineering building. They all have signs that say "FIRE DOOR. DO NOT IMPEDE." So I thought a good idea would be to spend an entire semiconductor physics class deriving the minimum required impedance of the doors.

And, not to go into too much detail, but I also just had a 20-minute conversation with a physics professor about deriving mathematically how much more attractive redheaded girls are than non-redheaded girls. We had this conversation in the library and got some fairly odd looks, but we now have objective truth backing up something normally subjective! So that's a bonus. I love science.

Any way, the next project is going to involve wiring my slow cooker to the internet, so stay tuned! It's coming along nicely so far.

Sunday, January 24, 2010

...Now We Can Do the Laundry

The laundry room in our apartment is supposed to use some overhead fluorescent lights, but they are the long tube style and rather than go out and buy some more (our landlord is horrible, it's APM if anyone is thinking of living in Tillman Place in Clemson) I decided to wire up a standard light bulb base to the light switch in the laundry room so we wouldn't have to do the laundry in the dark. (Also, in this picture the bulbs had already been removed)

I scavenged the light bulb base from the lamp I built for my apartment in Charleston (that was a previous project and is on this blog), then found a long power cable meant for a computer and cut both ends off and stripped the black (hot) and green (ground) wires. Then I attached one side of this cable to the light bulb base. After removing the light switch cover to reveal the switch, I attached the green wire to the ground wire inside the wall. Hopefully every light switch fixture has a ground wire somewhere. I attached the black wire to the top of the light switch at the screw-type terminal. Normally, an electric device would be connected to black (hot) and white (neutral) instead of green (ground), but most switches only cut off the power going to the high side of the device, so having the white wire around is unnecessary. In this case, it looked like it was actually there in the wall but I was not sure enough to go grabbing at random wires that were deep in the wall. While the green wire is normally used for safety, as long as the electricity is getting back to where it came from, green or white will work just fine.

After reattaching the light switch to the wall and hollowing out some of the side so the power cable would fit, I hung the wire and the light bulb base from the shelves above the washer and drier. Tada!

That's probably not up to code. ATTENTION FUTURE EMPLOYERS: If I'm working for you then I will do everything to code and it will be extremely safe. I promise. I'm just a poor college student who doesn't want to pay for light bulbs.

Also, on a completely unrelated note, and mostly since I had the camera out already, here is my ukulele!

Sunday, January 3, 2010

Overkill on the Kitchen Light Switch!

WHILE the idea of this project and what it will accomplish may not seem like much, I think for me it was more of a challenge to see if I could implement it. After all, the whole basis of engineering is making life easier for everyone else, and I suppose even if this project will only make the life of my roommates, me, and our visitors only trivially easier then that's positive engineering. The idea was something that is frequently talked about amongst anyone in the apartment.

We have a nice Mitsubishi projector here in the apartment in Clemson, but we have a set of 35W fluorescent light bulbs in the kitchen that wash the picture out if they're on. Often, however, everyone is sitting down by the time this is realized. Any way, in an apartment full of engineers it has been mentioned many, many times that "we should build something so you can turn the kitchen light off from the couch" which I might add, is only about five feet away from the kitchen. Oh well.

I have located an Arduino Diecimila microcontroller and will be attempting to program it for this project.

Normally I would like to have a project like this implemented in hardware (I do not like to program things) but I determined that this would be rather difficult, as the system would have to have memory to determine if the state of the kitchen light, which would mean I would have to use a set of flip-flops for memory and THAT would require finding a clock circuit somewhere, so I would have effectively made my own computer. The microcontroller is just easier even though I have to program. Fun times. But Bradley, my Computer Engineering roommate, helped me with some of that, which is good, because electrical engineers SHOULD NOT have to program things. They should be out in the woods fixing power lines and building missiles and passing the dull programming tasks off to someone else. I guess some people like to program, which works out well for everyone. So that's what computer engineers and computer scientists are for, I guess. Just kidding. But seriously.

Politics aside, here is the general design of the circuit that I worked out while semi-snowed in up in the greater Washington DC area a few weeks ago.

The idea here is that when either of two momentary pushbutton switches are pushed, the microcontroller will make a note of that and change the state of the light (from on to off or off to on). Also shown in my very unofficial-looking drawing is the pull-down configuration of the switches. I found two 33k-ohm resistors for this (they were the first large resistors to come out of the huge bag I have).

Also, since the microcontroller itself can not output enough current to activate the relay that will be switching the 120V 35W AC light, a current amplifier must be constructed. This is familiar territory for me, as it was a key part of my senior design project! Hooray for things from school being useful for a change. The drawing is somewhat inaccurate though, as I have decided to try and find a MOSFET somewhere instead of using a bipolar junction transistor like the TIP31 NPN transistor in the drawing. MOSFETs can typically handle more current for the same size integrated circuit, plus no current can get from the gate into anything and no current from the source to the drain can get back into the gate (under proper use and operating within the specifications of the transistor). This property will effectively isolate the relay circuit (operating at 12V DC) from the control circuit from the microcontroller (operating at 5V DC). I decided that a BJT was undesirable (or, at least, less desirable) since current can flow from the base of this type of transistor into the emitter or collector. It's kind of the same principle as a relay. It's better to use a low voltage source as a control circuit to switch the high voltage circuit, and to keep those two circuits electrically isolated. A MOSFET does these things.

So here is the prototype circuit that uses a 120V source and switches an LED on and off with a push of either of two red buttons.

I found a 120V AC to 12V DC power supply from a big box of junk. I was looking for 12V DC because not only does the relay operate on that much voltage, but the microcontroller can also run on 12V DC. Here's the catch, though: This one, when measured, outputs around 18V DC under no-load and just under that with all of the load from this circuit on it. The top-right corner of the breadboard is my solution to this, a $2 12V DC voltage regulator from RadioShack that can receive up to 35V DC as an input and regulate it to 12V DC and 1 amp. I almost let the smoke out of this one though by wiring it up backwards. Whoops.

The circuit works flawlessly. The yellow LED only represents the kitchen light. When the circuit is actually built, this will simply be a control wire leading to the gate of a MOSFET which will be used to operate a relay which will do the actual switching of the kitching light. Missing from this picture, however, is the MOSFET which I will get either from the electrical engineering building or RadioShack in the morning (or the late afternoon if my current sleep pattern is any indication of when I will wake up). I wired one of the pushbuttons to the relay to test its operation, though, and it works perfectly. One hitch I ran into was that before trying the pushbutton to operate the relay, I was just plugging it manually into the 12V supply. This worked for the relay, but when I manually unplugged it from the 12V supply I believe there was some sort of transient that I caused that caused the microcontroller to turn off. It didn't happen reliably, so I plugged in the switch, assuming it could switch better and faster than I could plug in a wire to the breadboard. I was right about that, and it works pretty well. Assuming the MOSFET will allow the microcontroller to operate the relay, I will begin soldering it together in a permanent fashion tomorrow.

OH! I almost forgot. Here is the code I used to program the microcontroller.

const int lightPin = 12; // pin controlling the light via amp/relay
const int ledPin = 13;
const int wallPin = 2; // input pin for kitchen wall switch
const int couchPin = 1; // input pin for couch switch

int lightState = LOW;
int ledState = LOW;
int wallState = 0;
int couchState = 0;
int counter = 0;
int onoff = 0;
int timer = 0;
int k = 0;

void setup() {
// set pins as inputs or outputs
pinMode(lightPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(wallPin, INPUT);
pinMode(couchPin, INPUT);

void loop() {
//read in the value of the wall and couch buttons. 1=depressed 0=not depressed
wallState = digitalRead(wallPin);
couchState = digitalRead(couchPin);
//if the light is on, and the wall button is being held down, set the timer to 1
//if the button is held down to the length of the specified interval
if (onoff==1) {
for(k = 0; digitalRead(wallPin)==0; k++) {
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
if(k>4) {
timer = 1;
counter = 0;

//if the timer was activated
if (timer == 1) {
digitalWrite(ledPin, HIGH); //turn on the LED to notify user that the timer was activated
delay(5000); //give 5 seconds before light is shut off, will need to change before this is implemented
digitalWrite(ledPin, LOW); //turn off LED
digitalWrite(lightPin, LOW); //turn off light
timer = 0; //reset timer
counter = 0; //reset the counter
onoff = 0; //remember that the light is off
//first two IF statements register if a button was pushed
if (wallState == 1 && timer == 0) {
counter = 1;

if (couchState == 1 && timer == 0) {
counter = 1;

delay(400); //debounce input

//if a button was pressed and the light was on and the timer was not activated
if (counter == 1 && onoff == 1 && timer == 0) {
digitalWrite(lightPin, LOW); //turn the light off
onoff = 0; //remember that the light is off
counter = 0; //reset the counter

//if a button was pressed and the light was off and the timer was not activated
if (counter == 1 && onoff == 0 && timer == 0) {
digitalWrite(lightPin, HIGH); //turn the light on
onoff = 1; //remember that the light is on
counter = 0; //reset the counter


The idea about that commented-out part is that eventually someone (Randy or Bradley) can program the microcontroller to recognize certain inputs from the switches and activate a 30-second timer on the kitchen light. So, for example, if the kitchen light switch is held down for three seconds, the microcontroller will notice this and shut the kitchen light off after 30 seconds to allow the user to get out of the room with the light still on. (This will be kind of useful because the light switch layout in our apartment is pretty horrible.)

My first MOSFET!

OK I have the prototype circuit finished now. I bought a MOSFET at RadioShack which will act as a switch and activate the relay when the output from the microcontroller goes high. This is the finished prototype (that other switch's wire broke after I made sure it worked):

The first problem! The packaging says that the transistor will turn on when the gate voltage is somewhere from 2 to 4 volts. Apparently, though, the transistor will only operate in weak inversion even when the input to the gate is at 5 volts. To get the transistor to operate in strong inversion, it needs a higher voltage than it says on the packaging. WAY TO GO RADIOSHACK. It took me quite a while to realize this but I have my semiconductors class to thank for giving me the knowledge to realize what was going on! (Basically, if the transistor doesn't see a high enough voltage at the gate, it'll only turn on a little bit instead of all the way, and turning on just a little bit wouldn't allow enough current to pass through the coil of the relay to activate it.)

This led to the second problem. It was already late at night by the time I figured this out, and I couldn't go to the store to buy more components, which I thought I needed because I had to find a way to make a 5V signal from the microcontroller into somewhere around a 12V signal. I thought at first I'd just buy a bipolar junction transistor and wire it up to activate the MOSFET, and while this would be easier to do, it seemed like a bit of overkill. Also, I couldn't get to a store. So what I did instead was wire the 5V output of the microcontroller to the noninverting input on a Fairchild 741CN operational amplifier and the output of the amplifier to the gate of the mosfet. I configured the op amp as a non-inverting amplifier with a gain of 2 by using a 3k-ohm resistor and a 1.5k-ohm resistor, which doubled the 5 volt input signal to a 10-ish volt input signal. More than enough to allow the MOSFET to operate in strong inversion.

This led to the third problem. What was happening was the circuit would work perfectly for about ten seconds and then the relay would constantly switch on and off with about a half second interval between switching. My guess is there was some screwy wiring that was causing the MOSFET gate to charge up and then discharge suddenly, which caused the transistor to "turn on" and then "turn off" again over and over. My solution for this, since I couldn't think of anything else to do, was to rip everything off of the breadboard and start over. Now the circuit works exactly as it was designed. Whenever either button is pressed, the relay changes state (which will operate the kitchen light directly). Now the only thing to do is solder it all together!


So the kitchen light switch was soldered together and installed tonight. Pictures!

This is the circuit, completely soldered together except for one of the switches, which is on the top case. Also as a side note, I figured out that the reason the relay was flipping on and off earlier is because both of the switches need to be plugged in to the microcontroller at all times otherwise it sees a floating value as one of the inputs and continues to toggle the relay.


Some housekeeping:

I added plexiglass covers to the light switch in the kitchen. I think it adds a little something special, but a picture should suffice:

I also have a note to one of my roommates in case he woke up early and couldn't figure it out, I didn't want him getting frustrated at me.