Introduction: Make Your Own Programmable Thermostat for $66 With Arduino

About: "If you want to build a ship, don't drum up people to collect wood and don't assign them tasks and work, but rather teach them to long for the endless immensity of the sea." - Antoine de Saint Exupéry. I long …

This project will show you how you can create your own programmable thermostat with temperature probe, an LED readout and ability to remote control outlets.

The core of this project is actually a driver for a 4 digit seven segment display.

There are lots uses for such a device. You can purchase something called a PID controller for about $120. The parts for this cost me about $66. If you can scrounge some of the parts you can do even better.

I use mine to control hot water baths for cooking meet. See my instructable on cooking perfect steak for why you might want this.

There are probably a dozen ways to do this. This was my way.

This project requires soldering small surface mount components (well one easy one IMHO). There are a lot of wires and it can be hard to debug certian problems. This is probably not a great project for a novice or the easily frustrated.

At this time the instructable isn't as detailed and foolproof as possible. My prototype works and this is my attempt to document the process. However, until I build my sweet new steampunk themed version, the instructable is going to be a little bit raw. You should be confident about these sorts of projects enough to do some minor debugging of the hardware and connections before you dive in. Just in case I got something wrong, you know. The software is solid at least. :)

Recomended Instructables:
Replace the $20 arduino in this project with $8 worth of electronics.
Generic Micro Controller switch outlets. I embedded this idea into this project. You can just build this stand alone version on hook it up to this project.

UPDATE: 2011-July-28 LM335A sensor version, cheaper, no surface mount soldering.

I am experimenting with replacing the thermocouple and booster with an LM335A sensor. It's not as accurate, and it won't go above 100 degrees C. However it's $1.50 compared to $28 for the thermocouple and booster. For souse-vide cooking it should work fine. There is a PCB123 diagram file in the diagram step if you want to see how to hook one up.
I have also gone to using the Atmega168 chip directly with the minimum hardware needed to support and program it. That's also in the PCB123 file along with a circuit board.
I plan to have circuit boards and solder your own kits available on Kickstarter soon. I am planning a run of 500. The kits will be ~$40 shipped. Let me know if you are interested. The Kickstarter never happened. I did another couple Arduino based Kickstarters and documented the projects on Instructables. Stay tuned, more to come I am sure.

Step 1: Gather Materials

Project:
1 X Arduino Pro Mini 328 - 5V/16MHz
1 X Thermocouple Type-K Glass Braid Insulated
1 X Thermocouple Amplifier Digital MAX6675
1 X Wall Adapter Power Supply - 5VDC 1A
1 X Outlet from the home store
1 X SOIC to DIP Adapter 8-Pin
1 X 4-Digit 7-Segment Display
1 X plastic outlet box
1 X extension cord or old computer cord.
1 X Relay SPDT Sealed 5v coil T9AS5D12-5
1 X Rotary Potentiometer - Linear COM-09288
1 X Trim potentiometer (optional)
1 X 2n2222 transistor or other similar switching PNP resistor.
1 X 1uf capacitor
5 X 330 ohm resistor (This used to say 470, but that makes the display pretty dim)
1 X 1N4148 diode
4 ft X Aquarium tubing (the bluish kind that might be silicone)
1 X breadboard, perfboard, circuit board or custom enclosure.
Spring Terminals - PCB Mount (2-Pin) (sparkfun PRT-08073)
Various wire.
Pins for mounting the Arduino. I used the legs off resistors and so on from previous projects, but you can buy some headers.

Coming Soon:
I am prototyping circuit boards for these. I got my first one from BatchPCB not long ago and it worked, but needs some changes to be ready for prime time. Hopefully boards with instructions will be done by end of summer 2011. BatchPCB sure is slow. :)

Gear:
  • Soldering Iron. (Adjustable is highly recomended)
  • Soldering supplies.
  • Basic soldering skills or a willingness to buy replacement parts as you learn. Soldering the Max chip is the hardest part of the project. It's not too hard to solder to the breakout board. Check out these videos and explanation. http://www.sparkfun.com/tutorials/96
  • FTDI basic breakout or other way to interface with your Arduino chip.
  • Computer to program the chip from.

You can use any kind of Arduino you want. If you get the mini like I did, make sure you have the programming chip or cable. You can also get or make an RBB arduino to shave a few dollars off the project. If you are really ambitious you can hack together an Arduino from an Atmeta chips and parts.

You can find everything electronic at Sparkfun.com. Of course you can shave some cost by sourcing some stuff elsewhere. For example, if you can find a wall adapter in the 5v range at the dollar store or second hand. Etc.

Note that the program I have later works with a button control and not a potentiometer. I will update this soon.

Step 2: Test the Components.

Before you solder this all up, it's a good idea to get it working on a bread board. So, go to the next step, but do it once without soldering on your breadboard.

Once you get connections working, you can start soldering them together.

You can modify the program easily to to cycle through different displays. Don't just use 8888 since you might short some wires and not realize it. Each possible segment has an entry in the segments array, you can cycle through them and each digit to get a good test program going. Try replacing loop with this to get a program that will light each segment in turn.

int _digit = 0;
int _segment = 0;
void loop(){
_segment++;
if(_segment > 7) {_segment = 0; _digit++;}
if(_digit > 3) {_digit = 0;}
delay(500);
lightDigit(digit[_digit], segments[_segment]);
//readTemp();
//handleButton();
}

Step 3: Solder It All Together

This is a lot of work. Even with the plans I would give yourself plenty of time to do this. Soldering the thermocouple booster to the breakout is the hardest job here. Sparkfun has some great tutorials on soldering surface mounts. There is only one in the whole project and it's was pretty easy for my first surface mount.

The eagle files are attached, but I don't garantee they are 100% correct. They are a post documentation of my prototype.

Wiring Instructions:
1. Go look at Arduino Controller Relay. There is one embedded in this project. You may wish to just make and test on of those before the rest of this project.
1a. Wire up the relay, 2n2222 and 1k resistor according to the diagram or the other project. Test that a 5v signal can activate the relay. (Before you plug it in please.)
2. Wire all the digits anode connection to a 470 resistor then to an ardinuo IO pin. (Software configurable, but keep notes if you change my wiring recomendation).

Arduino -> resistor -> seven seg
Digits

14 (A0) -> resistor - >1
15 (A1) -> resistor -> 2
16 (A2) -> resistor -> 6
17 (A3) -> resistor ->8


3. Wire the segment cathodes to IO pins. Don't use the ones for the colon, decimals or indicator dot.
Arduino -> seven seg
Segments
3 -> 5
4 -> 3
5 -> 16
6 -> 15
7 -> 14
8 -> 13
9 -> 11

4. Wire pin 2 to the base resistor on the 2n2222.
5. Mount the MAX6675 on the breakout.
6. Solder the breakout to the arduino pins.
7. Solder the filter cap to the breakout board as close as possible.
8. Solder some wires to the K+ and K- on the breakout board. You won't be able to solder the thermocouple to the board, so don't try. You will need a mechanical connection. Alligator clips are ugly but effective.
9. Wire up the indicator LED to pin 2 with a 470 resistor to ground.

At this point you can plug in the arduino and verify you can get temp readings from the thermocouple, and verify that the indicator led goes off and on when the set point is above or below the setting. See the next step for the code.

The eagle files are licensed under a Creative Commons Attribution 4.0 International License.

http://creativecommons.org/licenses/by/4.0/

Step 4: Program the Chip.

Download the program and upload it to the chip. Update 2011-July-28: I have now put the code in source control on Github:  git@github.com:dustinandrews/Arduino-Thermostat.git has the latest code. This project uses the MAX chip version which is tested and known to work.

The LM335a version is still being developed.

Read the program for some helpful tips.

The code reads and scales the control knob to run between 100 and 200 degrees, which is useful for souse-vide cooking.

This program is mostly a seven segment driver with a little bit of serial reader for the MAX chip thrown in. I got the MAX reader code off the innerwebs, so thanks to the author of that.

See the comments for some different test modes you can enable. Comment the regular code and only run one test mode at a time.

Step 5: Waterproof and Calibrate the Thermocouple

If you want to use the thermocouple underwater, you will need to waterproof it. (or buy a more expensive waterproof one in the first place.) In my application I need a waterproof thermocouple but it doesn't have read fast.

Get a length of silicone aquarium tubing about as long as your thermocouple. Plug the ends and soak in hot water for about a minute. While its still warm and pliable, feed the thermocouple in. I found stretching and relaxing the tube helped the last half go in. Leave a couple of inches at the end.

Cut the end with a hot knife, or tie a knot and hit it with a blow torch for about 1 second. When it's cool, suck on the end hard to check the seal.

When the seal is good zip tie the other end of the tubing to your circuit board for strain relief. Connect up to the board and supply power to the board from the computer.

At room temperature the reading will probably be right on. However, I found the MAX booster chip heats up after about 5 minutes and the calibration gets off. Assuming you want to keep water hot, like me, get a bucket and fill it with water at about 140 deg. F. Put the thermocouple in the bath and wait 10 minutes.

Compare the reading with a reference thermometer. Make a note of the delta and make an adjustment to this line in the program. -10 is my calibration which is about 2 deg. F.

int calibration = -10; //temp calibration compensation * .25deg C

Upload the correction value to the arduino with new sketch.

Advanced Tip: You could add a trim pot to one of the leftover analog ports to be able to trim on the fly. My V2 board will have that.

Step 6: Add the Power Supply and Cord.

Run your cord into the project box (Outlet box). Use one of the side holes so it will sit flat. Hook up ground and the white wire to the oulet as per the outlets instructions.

Hook the black wire to the NO (normally open) post on the relay. Hook the switched post up to the outlet. I cable tied the crap out of these wires to prevent them coming loose and causing mahem.

Add a barrel connector to the project or cut the adapter end off the power 5v supply. Plug it in and measure the ends with a meter and label them clearly. UNPLUG it and solder the leads to the board where indicated. I used a 12v relay and power supply. One 12v supply easily runs my relay and my arduino (RAW port used), but test yours to be sure you have enough power. (I'll be testing the parts I recomend soon. You may need two 5v wall warts, but I doubt it.)

Optionally wire the plug ends directly into the power feeds in the box. The black wire should come from the outlet and not the one that went through the relay, of course. Otherwise you will have two plugs coming out of the project. I ran this way for a while with no problems.

At this point, you should be able to plug the project in, the Arduino should fire up, the LED will show the current temperature, the indicator LED will go on and off with the the outlet depending on the set point.

Step 7: Enjoy Some Temperature Controlled Fun

Personally, I use mine to cook steak. You could also cook Eric's famous beef ribs.

Make sure anything you hook up doesn't pull more amps than your relay is rated for. Small fans and aquarium heaters should be no problem. Air conditioners, fridges and larger heaters may or may not be OK.

Note: Amps is not the same as volts or watts. Amps = Wattage / Voltage. I triple checked my heater before I hooked it up. Be safe and get help if you aren't sure.

Enjoy!

LED Contest

Participated in the
LED Contest