"> ">

Subscribe to Arduino Academy and start learning today for FREE!

Dual water tank heater thermostat

I am just finishing up a project at work, which requires two water tanks to be maintained at 180F. Each tank has twin 1500 watt, 240vac heating elements, each controlled by a SSR (Solid State Relay). My Arduino Mega 2560 reads two DS18B20 temp sensors (one in each tank), and maintains the temperature with a 5 degree window. I display both tank temperatures on a LCD, and control the color of two RGB LED’s, blue for under temp, green for correct temp, red for over temp. The photo’s are here. The following is the working code for the project.

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

Become the Maker you were born to be. Try Arduino Academy for FREE!

// Connections:
// rs (LCD pin 4) to Arduino pin 12
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

int tank1BLED = 37;
int tank1GLED = 39;
int tank1RLED = 41;
int tank2BLED = 43;
int tank2GLED = 45;
int tank2RLED = 47;

// Data wire is plugged into pin 8 on the Arduino
#define ONE_WIRE_BUS 8

// Setup a oneWire instance to
//communicate with any OneWire devices

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.

DeviceAddress tank2Thermometer = { 0x28, 0x46, 0x3C, 0x16, 0x03, 0x00, 0x00, 0xA9 };
DeviceAddress tank1Thermometer = { 0x28, 0xDF, 0x21, 0x16, 0x03, 0x00, 0x00, 0x1E };

int tank1 = 31; // heater control pins
int tank2 = 33; // heater control pins

float tank1temp = 0;
float tank2temp = 0;

void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(tank1Thermometer, 10);
sensors.setResolution(tank2Thermometer, 10);

pinMode(tank1BLED, OUTPUT); // Tank LED’s
pinMode(tank1GLED, OUTPUT);
pinMode(tank1RLED, OUTPUT);
pinMode(tank2BLED, OUTPUT);
pinMode(tank2GLED, OUTPUT);
pinMode(tank2RLED, OUTPUT);

digitalWrite(tank1BLED, HIGH); // set Tank LED’s off
digitalWrite(tank1GLED, HIGH);
digitalWrite(tank1RLED, HIGH);
digitalWrite(tank2BLED, HIGH);
digitalWrite(tank2GLED, HIGH);
digitalWrite(tank2RLED, HIGH);
lcd.begin(20,4);
// columns, rows. use 16,2 for a 16×2 LCD, etc.

lcd.clear();
// start with a blank screen

pinMode(tank1, OUTPUT); // Tank heaters
pinMode(tank2, OUTPUT);

}

void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
float t1tempC = sensors.getTempC(tank1Thermometer);
float t2tempC = sensors.getTempC(tank2Thermometer);
if (tempC == -127.00) {
lcd.print(“Error”);
else {
// lcd.print(tempC);
// lcd.print(“/”);
tank1temp = (DallasTemperature::toFahrenheit(t1tempC));
tank2temp = (DallasTemperature::toFahrenheit(t2tempC));
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop(void)
{
delay(2000);

sensors.requestTemperatures();

lcd.setCursor(0,0);
lcd.print(“Tank 1: “);

printTemperature(tank1Thermometer);

lcd.setCursor(0,1);
lcd.print(“Tank 2: “);

printTemperature(tank2Thermometer);

if (tank1temp <=178.9)
{
digitalWrite(tank1, HIGH);
digitalWrite(tank1BLED, LOW);
digitalWrite(tank1GLED, HIGH);
digitalWrite(tank1RLED, HIGH);
}

if (tank1temp >= 179 && tank1temp <= 181.9)

{
digitalWrite(tank1GLED, LOW);
digitalWrite(tank1RLED, HIGH);
digitalWrite(tank1BLED, HIGH);
}

if (tank1temp >= 182)
{
digitalWrite(tank1, LOW);
digitalWrite(tank1RLED, LOW);
digitalWrite(tank1GLED, HIGH);
digitalWrite(tank1BLED, HIGH);
}

if (tank2temp <=178.9)
{
digitalWrite(tank2, HIGH);
digitalWrite(tank2BLED, LOW);
digitalWrite(tank2GLED, HIGH);
digitalWrite(tank2RLED, HIGH);
}

if (tank2temp >= 179 && tank2temp <= 181.9)

{
digitalWrite(tank2GLED, LOW);
digitalWrite(tank2RLED, HIGH);
digitalWrite(tank2BLED, HIGH);
}

if (tank2temp >= 182)
{
digitalWrite(tank2, LOW);
digitalWrite(tank2RLED, LOW);
digitalWrite(tank2GLED, HIGH);
digitalWrite(tank2BLED, HIGH);
}

}

Become the Maker you were born to be. Try Arduino Academy for FREE!

 

Subscribe
Notify of
guest
8 Comments
Inline Feedbacks
View all comments
Quigath
12 years ago

Is there any reason this could not be done on an Arduino UNO? I'm wondering why you chose to run on a mega.

Steve Spence
12 years ago

I used 18 I/O pins.

Quigath
12 years ago

It's a nice build, I'd like to do something similar but for a room heater. I especially like the idea of using colored LEDs to quickly see them temp. Maybe I'll borrow some code if you don't mind. My LCD only uses 4 pins and I don't need 2 heating elements so my UNO should work.

Steve Spence
12 years ago

This also works well for heating a fish tank, just limit the temperatures in the two variables, tank1temp and tank2temp.

Unknown
10 years ago

For extra credit, try a PID controller.

Tony Paul
6 years ago

Thanks for sharing your project with us. It can help.

Heating and Cooling Vaughan

Tony Paul
6 years ago

Thanks for sharing such an amazing article. It helps me with the thermostat.

Heating and Cooling Richmond Hill

Archives

8
0
Would love your thoughts, please comment.x
()
x