HVAC setpoint differential controller

I am new to the forum and to creating anything of this kind, so please be patient and helpful!

Description:
This device is being created to turn the load pump on and off for charging a heat storage tank from a heat source (i.e. wood boiler, solar, etc.) It uses 2 thermistors, one in a well submerged 6" into the storage tank water, and the other strapped to the pipe to determine the temperature of the charging water. There is a set point temperature that the tank is trying to acheive. The pump will be turned on to charge so long as the charging water is higher in temperature by as much as the differential than the tank and the tank has not yet reached its set point temperature.

Componenents:
I plan to use the Arduino Duemilanove USB board.

I plan to use a DPDT 120vac relay to turn the pump on/off and have the digital pin output 5v to trigger the coil. Is 5v sufficient to trigger it?

I plan to use National Semiconductor LM34 thermistors

Code:
I have cobbled together this code from other projects on this forum and on the web. I think it is pretty close to the minimum I would need to run this. When I try to verify it I get this message when it reaches the bottom:

In function [ch8216]void loop()[ch8217]:
error: a function-definition is not allowed here before [ch8216]{[ch8217] token

A fix for the error and any additions or fixes for the hardware or software for this project would be appreciated. Thanks for your help!

int sourcetempPin = 0; // Source thermister connected to analog pin 0

int storagetempPin = 1; // Storage tank thermister connected to analog pin 1

int relayPin = 12; // Relay connected to digital pin 12

int setpoint = 175; // Set the desired storage maximum temp in Fahrenheit here

int differential = 5; // Set the differential between source temp and storage temp in Fahrenheit here

unsigned long last_temperature_check_time = 0;

void setup()
{
pinMode(sourcetempPin, INPUT); // sets the analog pin as input
pinMode(storagetempPin, INPUT); // sets the analog pin as input
pinMode(relayPin, OUTPUT); // sets the digital pin as output
}

void loop() // Checks temperatures and turns pumps on/off
{
unsigned long time = millis();
if (time - last_temperature_check_time > 20000) //has it been 20 seconds?
{

//Check Temperature routine
long tempsource;
long tempstorage;
long temp1;
long temp2;
int source_val=0;
int storage_val=0;

source_val=analogRead(sourcetempPin); //read value of center leg of LM34 on source
storage_val=analogRead(storagetempPin); //read value of center leg of LM34 on storage
tempsource = source_val; //output voltage of LM34, 10mV = 1 Degree Celcius
tempstorage = storage_val; //output voltage of LM34, 10mV = 1 Degree Celcius
temp1=(5tempsource100/1024); //creates true Fahrenheit
temp2=(5tempstorage100/1024); //creates true Fahrenheit

//Turn Relay on/off routine
if ((temp1) > (temp2) + (differential)) //check source temp for differential
{
digitalWrite (relayPin, HIGH); //if temp is above x degrees turn pin "ON"
}
else if ((temp2) > (setpoint)) //check storage temp against setpoint
{
digitalWrite (relayPin, LOW); //if temp is below x degree turn pin "OFF"
}
else
{
digitalWrite (relayPin, LOW); //if temp is below x degree turn pin "OFF"
}

delay(20000); //Check temp every 20 seconds
}

I doubt the Arduino pin is going to directly power the relay you need. Why not use a Triac with an opto-isolator for safety?

Something like this:


for the temperature, if it's relatively low temps then a thermistor should do the trick. The RepRap project uses thermistors and Arduino so take a look there for what you'll need( hardware and software ):
http://reprap.org/bin/view/Main/Thermistor

You are missing the closing brackets at the end of loop. Put a } at the end and it should compile.

You should not try and set analog pins as inputs, analogRead does this implicitly.
The following lines should be removed, they set digital pins 0 and 1 as inputs!
pinMode(sourcetempPin, INPUT);
pinMode(storagetempPin, INPUT);

Good luck!

I have a little experience with the LM34 chips. First, understand they are not thermistors which is good because they have a linear output and are much easier to use. Second, if they are any distance away from the Arduino, make sure you use the RC circuit that is in the spec sheet from National for the LM34/35. If memory serves me, it says to use a 1uF cap with a 75ohm resistor in series from output to ground to decouple the chip.

On the breadboard the circuit I made worked great, but once IRL and on the end of a 6' lead it was not usable. Adding the decoupling RC circuit fixed the problem. I even used shielded cables and still had a big problem. Here are some pictures of my shield board I made:

Derrin

Thanks for the great input guys and being patient with a beginner! This is a great forum to support this product.

I doubt the Arduino pin is going to directly power the relay you need. Why not use a Triac with an opto-isolator for safety?

Something like this:
http://www.mikrocontroller.net/attachment/32974/triac2.JPG

I talked to someone else too and your right the relay I referenced would not work. I looked up the Triac because I was not familiar with them. I think I kind of get it. The Arduino 5v would connect to contact 1 and I assume the Arduino ground to contact 2? I am unclear about the side with contacts 4,5, & 6. Do those hook directly to 110vac or do they go to a relay? I have very little experience with this type of stuff, so please be as simple and clear as possible. Even better would be links to exact products I could order and a schematic of exactly how to hook it up.

You are missing the closing brackets at the end of loop. Put a } at the end and it should compile.

You should not try and set analog pins as inputs, analogRead does this implicitly.
The following lines should be removed, they set digital pins 0 and 1 as inputs!
pinMode(sourcetempPin, INPUT);
pinMode(storagetempPin, INPUT);

Thanks for helping me clean this up. I will remove the pinMode entries as suggested. Can you reference for me exactly where the loop ends for that bracket to go? I thought it ended at the bottom of the code and I do have a bracket there.

I got the code all settled now, it verfies fine. Thanks for the help Mem

I still need help understanding what terminals to hook into for the moc3041 triac and if there are any other components needed on the 110vac pump side of it.

If memory serves me, it says to use a 1uF cap with a 75ohm resistor in series from output to ground to decouple the chip.

Can you suggest a specific make and model for the 1uF cap? When I search sites for one there are way too many and a lot of numbers I don't understand. :o

Thanks

I actually used the 1uF tantalum caps from Radio Shack. They were expensive considering, but I needed them fast. Allelectronics has them also. For relays, I used Omron G6C-1114P-US 5vdc relays from Electronic Goldmine driven from simple 2N2222 transistors wired per the relay tutorial in the Playground.

So far so good.

Thanks guys for all the input so far. Having talked to some people and read more on the forum and other sites, I have decided to use the Dallas 1-wire thermometers instead of the LM34 ones. The reason being that in the end I can put a lot more of them in to monitor my heating system performance and not take up more ports on the Arduino. I haven't made up my mind yet on the triac vs. relay for controlling the pump. Here are the preliminary components I am looking at using in addition to the the Arduino usb board:

  1. A couple DS18S20+ digital thermometers with a 4.7k 1/2watt resistor.(is 1/2 watt sufficient?)

  2. This http://www.allelectronics.com/make-a-store/item/MOC3022/OPTO-ISOLATOR-TRIAC-OUTPUT/-/1.html triac or this http://www.allelectronics.com/make-a-store/item/RLY-625/5VDC-DPDT-DIP-RELAY/-/1.html relay with a transistor (does it really need one if the relay is 5v? If so, please suggest one at allelectronics as I want to order all the stuff from one place) Any opinions on what would work better or is it just two different ways of doing it?

The code will be a whole other issue since my original stab at it was specific to the LM34. If anyone has code input, that would be great too. Thanks for all the help!