loading
Picture of Arduino Thermostat with TC74 sensor
IMG_1609.JPG
2012-04-25_17-27-48_914.jpg
2012-04-25_17-28-00_138.jpg
Hello all!

This is a quick guide on how to use an Arduino© to control whether a cooling fan and a heater is turned on depending on the detected temperature from a TC74 Arduino sensor.

This is for a final project for an Electronics class I am currently taking, though I came into this project with pragmatism in mind, because of the hot summers and cold winters (ok, 60 degrees indoors is cold for me, but that's probably because I'm Californian).

Working on this project should give good hands-on practice in working with the Arduino, soldering, and general circuitry, as well as coding for the Arduino and workin gon the logic needed for the coding.

Why adjust the fan and/or heater if the Arduino can do it for you?  (Ok, this is probably easy enough to do, but making it technologized (not a word) is just much cooler (no pun intended).

Also, there is a video at the end of this Instructables if you'd like everything described verbally.

Best of luck!

Step 1

Materials.

You'll need...
* An Arduino© microcontroller, made by Arduino (with USB connector)
* A Fan (This project used the following one: http://www.amazon.com/Lasko-Personal-Inches-White-2002W/dp/B000QR6VXW/ref=sr_1_1?s=home-garden&ie=UTF8&qid=1333608671&sr=1-1)
* A Heater (This project used the following heater: http://www.amazon.com/Pelonis-Heater-fan-Heat-Settings/dp/B000PAQHLG/ref=sr_1_32?s=home-garden&ie=UTF8&qid=1333608582&sr=1-32 )
* TC74 Temperature Sensor
* Wires
* Relays,  Relays here were solid-state relays, with a smaller current (2 Amp) Crydom D2W202F for the Fan and a large current 25 Amps NTE Electronics Relay for the heater, which requires up to 1500W.
* A breadboard
* Heat-shrink tubes
* Two wall outlets for use
* Two optional (10,000 ohm) potentiometers
* A computer with Arduino software
* Code

Tools
* Soldering iron
* Wire cutter and wire stripper
* Crimper
* Screwdriver or alternative
* Heat gun (optional)

Safety warning:  Live wires may be dangerous, especially when either the fan or heater is plugged in.  Please either use the heat-shrink tubes to cover these up or better yet, box the whole contraption.
 
Remove these adsRemove these ads by Signing Up

Step 1: Starting off

Picture of Starting off
Simple diagram for fan.png
Unpack the fan and heater.

We'll start with the fan, as this poses less fire hazard (the heater pulls a lot of current).

We wish to make a closed current loop through the solid-state relay, 120 V AC and the fan motor itself.  Basically, we want to be able to put in zero volts somewhere such that the fan is told to turn off and when we give in 5 V somewhere, then the fan turns on.

After this is done, we can test the fan to make sure that it's talking to the Arduino.

Use any digital output pin you want, but I chose pin 13.

For an easy pin 13 on/off program...

Go to Files -> Basics  -> Examples -> Blink when your Arduino software window is open.  (This is conveniently pointed at pin 13.)  Don't forget to plug in the fan into a 120 V AC plug or the equivalent. 

Hardware wise, follow these steps.

1.  Unpackage the fan.
2.  Make a cut across half of the wire to expose one end.
3.  Solder the two ends of this wire to the two ends on the solid-state relay's AC side.
4.  Heat-shrink tubing should cover this connection.
5.  Hook up the two other leads (+ and - 3 to 28 V DC) to the Arduino at pin 13 and ground, respectively.
6.  Upload code and watch your fan work!

Step 2: Setting up the heater

Picture of Setting up the heater
Set up the heater in a similar fashion.

1.  Cut to half the heater's cord and pull the wire apart to create two open ends.
2.  Use the other solid state relay (heavy-duty) by screwing down the ends of crimped wires to ensure contact.  Do the same with connections to the Arduino on the 3 to 32 V side.
3.  Plug into Arduino at pin 4 and at ground.
4.  Upload code, and hopefully the heater should work!  (Use a similar code as the fan code, but switch the pin to pin 4.

Note:  Make your incision close to the fan.  This will leave lots of cord length for the plug to be further away from all the wires set up.  Do similarly with the heater.

Step 3: Integrating the TC74 Sensor

Picture of Integrating the TC74 Sensor
The TC74 sensor is a temperature sensor that reads temperature in degrees Celsius with plus/minus 1 degree resolution.  It can read from -40 to 125 degrees Celsius.  The one I have in particular is the TC74A2.

Usage of the TC74 can be found at this Instructables page.
http://www.instructables.com/id/Arduino-Temperature-Sensor/

In short, hook up the TC74 as such.  (From the side of the inscription.)

Pin on far left, nothing
Second pin to Analog 4
Middle pin to ground
Fourth pin to Analog 5
Far right pin to 5 V (from Arduino, may be hooked via the breadboard)

TC74A2's code is 1001010, which is hexadecimal for 4a.  This will come in handy later.

Step 4: TC74 Arduino code

Picture of TC74 Arduino code
The TC74 uses the Wire library for the Arduino.

The code is as follows, and can be modified to fill in other needs.

#include "Wire.h"
    //wire library
    #define address 0x4a

    #define baudrate 9600
    //baudrate for communication
    byte val = 0;
    void setup()
    {
    Wire.begin();
    Serial.begin(baudrate);
    }

    void loop()
    {
    Serial.print("temperature in Celsius: ");
    //let's signal we're about to do something

    int temperature;
    //temperature in a byte

    Wire.beginTransmission(address);
    //start the transmission

    Wire.write(val);

    Wire.requestFrom(address, 1);
    if (Wire.available()) {
    temperature = Wire.read();
    Serial.println(temperature);
    }

    else {
    Serial.println("---");
    }
    delay(5000);
    }

(Downloadable below.)

Note that the code submitted by nadav at http://www.instructables.com/id/Arduino-Temperature-Sensor/step4/Code-Code-and-more-code/ is for the old version of Arduino, hence the changes of Wire.receive and Wire.send to Wire.read and Wire.write.

What this program should do is, provided that you set some threshold temperatures, converts the fahrenheit temperature reading from the TC74 and sends it to the Arduino, where the Arduino determines whether the value is high or low enough to trigger the turning on of the fan and the heater.  It will then wait another 5 seconds before taking another reading and figuring out whether the reading has changed the digital state of the system.

Turning on the serial monitor of the Arduino program should read out...


Temperature in Celsius    __   (Current temperature from TC74)

Note that we cannot control when the heater and fan turn on yet.

Step 5: Setting Threshold Fan/Heater Values

Picture of Setting Threshold Fan/Heater Values
Now is when the potentiometers come into play.  Connect the potentiometers, with the two ends on 5V and ground and the middle going to an analog input.  Do this for the other appliance's potentiometer as well.

In order to read out what the potentiometer tells the Arduino, initialize the variables and code the following...

fanDigit = analogRead(fanAnalog)/4;
heaterDigit = analogRead(heaterAnalog)/4;

This will give the Arduino a number from 0-255 depending on where the potentiometer is twisted.

This can be used to provide a threshold, with an example of code for the application of a threshold below.

fanThreshold = 20 + fanDigit*10/255;
heaterThreshold = 10 + heaterDigit*10/255;

<more code>
//inside void loop()
if(temperature>fanThreshold) {
        digitalWrite(13, HIGH);
      }
       else {
         digitalWrite(13, LOW);
       }
       if(temperature<heaterThreshold) {
         digitalWrite(4, HIGH);
       }
       else {
         digitalWrite(4, LOW);
       }

Step 6: The Whole Code (Downloadable below.)

Picture of The Whole Code (Downloadable below.)
//Arduino Thermostat Project
//Takes an analog input from a potentiometer and uses that
//as the desired temperature cutoffs.
//Fan and heater are both controlled by separate potentiometers
//though their modes (high, medium, low) are controlled
//on the device-side.
//Thresholds represent the desired temperature to which we want
//the current temperature to move towards.

//Fan can only be adjusted from 65 to 85 degrees Fahrenheit
//Heater can be adjusted from 55 to 75 degrees Fahrenheit.
   
    #include "Wire.h"
    //wire library
    #define address 0x4a

    #define baudrate 9600
    //baudrate for communication
    byte val = 0;
    int fanAnalog = A0;
    int heaterAnalog = A1;
    int fanDigit = 0;
    int heaterDigit = 0;
    int fanThreshold = 0;
    int heaterThreshold = 0;
    //initialize and set up variables
   
    void setup()
    {
    Wire.begin();
    Serial.begin(baudrate);
    pinMode(13, OUTPUT);
    pinMode(4, OUTPUT);
    }

    void loop()
    {
    fanDigit = analogRead(fanAnalog)/4;
    heaterDigit = analogRead(heaterAnalog)/4;
    fanThreshold = 65 + fanDigit*20/255;
    heaterThreshold = 55 + heaterDigit*20/255;
    //Tells us at what temperature things will or will not happen.
    Serial.print("temperature in Fahrenheit");
    Serial.print("\t");
    Serial.print("Fan Threshold Temp");
    Serial.print("\t");
    Serial.print("Heater Threshold Temp");
    Serial.println("");

    int temperature;
    int temperatureF;
    //temperature in a byte
    //initialize Fahrenheit temperature

    Wire.beginTransmission(address);
    //start the transmission

    Wire.write(val);

    Wire.requestFrom(address, 1);
    if (Wire.available()) {
    temperature = Wire.read();
    temperatureF = temperature *9/5+32;  //converts to Fahrenheit.  Yes, I'm American.
      if(temperatureF>fanThreshold) {
        digitalWrite(13, HIGH);  // Turns on fan if the temperature is higher than threshold
      }
       else {
         digitalWrite(13, LOW);  //Turns or keeps fan off
       }
       if(temperatureF<heaterThreshold) {
         digitalWrite(4, HIGH);  // Turns on heater is temperature is lower than threshold
       }
       else {
         digitalWrite(4, LOW);  // Turns heater off
       }
    Serial.print("\t  ");
    Serial.print(temperatureF);
    }
    else {
    Serial.print("---");
    }
    Serial.print("\t");
    Serial.print("\t");
    Serial.print("\t");
    Serial.print("\t ");
    Serial.print(fanThreshold);
    Serial.print("\t");
    Serial.print("\t");
    Serial.print("\t  ");
    Serial.print(heaterThreshold);
    Serial.println("");
    //Prints out values for current temperature, then both threshold values.
    //Lots of formatting
    delay(5000);
    }

Step 7: In conclusion...and more ideas?

Picture of In conclusion...and more ideas?
IMG_1609.JPG

Well, you've reached the end! Congratulations! If you have all the parts and put them together correctly, then you've made a thermostat out of an Arduino microcontroller!

Although I did not say how to adjust the fan or heater strength, which might require disassembly of the fan or the heater, I'm sure there are instructions for those somewhere.

There are a few things you can do to try to spice up this experiment!

First, you can bypass the serial monitor and use some LED's to read out the temperature value. Furthermore, safety and aesthetics can be improved by boxing up the hardware with just the connections, fan, heater, and potentiometer knobs sticking out. Other possible projects include making your own fan and/or heater (not too difficult conceptually) and hooking that up.

One possible alternative idea provided by my Physics professor is to replace the TC74 with a Wheatstone bridge, with the variable resistor as a thermistor and a corresponding resistor being a potentiometer.

As promised, here's the video!

Hope you can find some enjoyable and pragmatic use for this project! Please vote, rate, and/or comment!

read more1 month ago

Can I replace the Fan by Honeywell TurboForce Fan ?

gummygoodness (author)  read more1 month ago

I see no issue with such a change!

sherwoodp1 year ago
It says your video is private. Any chances of getting to review it somehow? Have you done anything more to this project since posting it on Instructables? Is there a particular reason why you chose the TC74 Temperature Sensor over the DS18B20 or TMP35/TMP36?
gummygoodness (author)  sherwoodp1 month ago

Hello! I made the video public now. Not sure why or how it became private, as it definitely was not so earlier in this Instructables' lifetime. (Apologies for the poor quality of the video! I think I filmed it with a cellphone.)

The department machine shop suggested using the TC74 temperature sensor. However, I'm sure other alternatives (like the ones you mentioned) should fit in nicely.

prphntm3 years ago
I assume adding a serial display to readout the "setpoint" temperature would not be too difficult to implement.

Any ideas for doing that?
gummygoodness (author)  prphntm3 years ago
Adding a serial display LED to show the any of the values in the thermostat would fit nicely in with the implementation. (It wasn't done here because of time constraints, but it probably wouldn't take too much longer.)