Introduction: Arduino Thermostat With Relay for Colour Film Development

About: I'm curious and therefore I can do a lot and nothing at the same time

This prototype is just the first step of a bigger project I hope to conclude during this year. In particular this prototype has a box-like shape and it's usable without driving you mad trying to keep modules connected. It's not nice to see, but it does the work.

This is a thermostat that keep a bath of water and some bottle of acid solutions warm during the process of develop analogue film.

The parts and the modules:

This is a thermostat connected to a water heater for camping kitchen. The idea is to use the heater to warm up a bucket of water where bottles and a dev. tank are plunged. The idea is to start the device and make the whole things inside the water reaching the working temperature before starting the process.

Let's see what you'll need if you want to build one:

Here's what you need:

  • Arduino UNO (or Mega or even Nano) - after mark is about 12€
  • Two LCD screen (16x2) or one bigger (20x4) - the second solution is much more elegant, but I went with I got. However, the big LCD 20x4 is about 17€
  • Two temperature sensors DS18B20 with cable - cheap and reliable, about 7€ a couple
  • Single relay board - not easy to find the single one, but only 7€
  • Analogue 5-buttons keypad - super useful! it use only one pin! 4€
  • AC plug - the cheapest you can find, the one I got is from a hardware store and was 3-4 €
  • Wires and Dupont connection to make cables long as you need!

The connection are pretty simple but let's go with order:

LCD Screens:

Using the i2c connection allows you to have just 2 pin used for the screen (+2 for alimentation) and makes the whole thing elegant and neat. In the schematic you see the connection of two screen 16x2 both on the same i2c port. In order to do this, you have to carefully solder a connection on the i2c board on the back of one of those to make it have a different address. You can find more info about it on the net, just search "multiple LCD i2c on Arduino".

DS18B20 sensors:

This are simple too, but you need to plug a ca. 5kOhm resistance for each one, in order to make it works properly. It has to be plugged between the data wire and the positive one (Vcc). Usually this sensors come with coloured wires: black, red and yellow (or white). Black goes on GNN (negative) and red on Vcc (positive 5V), the third is the data wire and you need to plug it on an analogue pin. I used A1 and A2 for this project. To calibrate, consider this instructables.

Analogue Keypad:

The keyboard need to be plugged in an analogue pin, I used A0 for mine. Here you have to keep in mind something and maybe to modify the library to make it works.

This kind of keypad works with resistance, that means that when you press a button the pin receive an input in voltage between 0 and 1023 based on how many resistances are between the button and the pin. The library I used is a modified version of this. First of all I connected the keypad to Arduino and opened a serial monitor to check the input on A0 where I plugged. Using a simple sketch to check the values I wrote down the results for each button and than I modified the library with my values. I obtained a custom version of the same library and used it in every sketch.

Relay board, AC and plug:

This is connected to A3 and it just gives input to the relay to open or close when I want during the sketch. The AC comes and goes directly to the plug only with the negative wire, the phase runs through the relay in the NO (normally open) pin. That means that the phase goes into the relay from the COM port, comes out from the NO port and goes to phase port of the plug. Arduino does the rest.

Doing so, if I connect everything but Arduino, the plug has no energy and can't burn any heater or electrocuted anybody. If you'd connect the plug to the NC port of the relay, the circuit would be normally closed and the energy would be free to go till the plug and beyond, if there is a beyond connected.

Step 1: The Code

Here we declare libraries and modules:

First the Temperature Sensor DS18B20:

#include "Wire.h"
#include "OneWire.h" #include "DallasTemperature.h" #define ONE_WIRE_BUS_1 A1 #define ONE_WIRE_BUS_2 A2 OneWire ourWire1(ONE_WIRE_BUS_1); OneWire ourWire2(ONE_WIRE_BUS_2); DallasTemperature sensor1(&ourWire1); DallasTemperature sensor2(&ourWire2);

Then a custom library from an improved library to read the keypad from the SainSmart module. Here you find it:

#include "AnalogKeypad_Reader.h"
AnalogKeypad_Reader keypad;

LCD Library using i2c connection

#include "LiquidCrystal_I2C.h"
LiquidCrystal_I2C lcd(0x27,16,2); LiquidCrystal_I2C lcd2(0x25,16,2);

Relay's PIN

#define RELAY1 A3

Here come the variables part. To completely understand it, you want probably check the instructables to calibrate the sensors. The second part of them, from tMin and below, are the variables to keep the temperature stable in the baths. tMin is the working temperature and tMax is the one the heater warm the water up to until the acid is at the working temp. After that it all should remain at that temp.

float RawLow = -0.3;
float RawHigh = 99.6; float RawLow2 = -0.5; float RawHigh2 = 99.1; float ReferenceLow = 0; float ReferenceHigh = 99.9; float RawRange = RawHigh - RawLow; float RawRange2 = RawHigh2 - RawLow2; float ReferenceRange = ReferenceHigh - ReferenceLow;

float tMin = 38; float tMax = 42; int val = 0; int state = 0; int stateSt =0; int previous = 0;

Then we go to the setup:

RELAY1 set as output and thermometer resolution to 11bit (to have an increase of +0.125°C in the measurement)

void setup(){
pinMode(RELAY1, OUTPUT); lcd.init(); lcd.backlight(); lcd2.init(); lcd2.backlight(); sensor1.begin(); sensor2.begin(); sensor1.setResolution(11); sensor2.setResolution(11); }

The loop:

Temperature request and calibration added then printed on serial and on the first LCD

void loop(){
sensor1.requestTemperatures(); sensor2.requestTemperatures(); float RawValue = sensor1.getTempCByIndex(0); float RawValue2 = sensor2.getTempCByIndex(0); float CorrectedValue = (((RawValue - RawLow) * ReferenceRange) / RawRange) + ReferenceLow; float CorrectedValue2 = (((RawValue2 - RawLow2) * ReferenceRange) / RawRange2) + ReferenceLow; Serial.println("------"); Serial.print("Temp. Acqua: "); Serial.print(CorrectedValue); Serial.println(" C "); Serial.print("Temp. Acido: "); Serial.print(CorrectedValue2); Serial.println(" C ");

lcd.print("Acqua "); lcd.print(CorrectedValue, 1); lcd.print(" "); lcd.setCursor(0,1); lcd.print("Acido "); lcd.print(CorrectedValue2, 1); lcd.print(" ");

Functions: Pressing UP_KAY the sketch will activate the relay and starting the function heater();

Pressing UP_KEY again to deactivate the relay board.

val = keypad.getKey();
if (val == UP_KEY){ state = 1 - state; } if (state == 1){ heater(); } else { digitalWrite(RELAY1, HIGH); lcd2.setCursor(10,0); lcd2.print("H: OUT"); }

} //end of loop

Core function of the relay board:

The heater works up to 42°C for the water until the acid solution (where the second sensor is) reaches 38°C

void heater(){
float RawValue = sensor1.getTempCByIndex(0); float RawValue2 = sensor2.getTempCByIndex(0); float CorrectedValue = (((RawValue - RawLow) * ReferenceRange) / RawRange) + ReferenceLow; float CorrectedValue2 = (((RawValue2 - RawLow2) * ReferenceRange) / RawRange2) + ReferenceLow; lcd2.setCursor(10,0); lcd2.print("H: "); if(CorrectedValue2 < tMin && CorrectedValue < tMax){ //If statament to activate relay when tCal1 < tMax (42°) AND tCal2 < tMin (38°) digitalWrite(RELAY1, LOW); //Relay ON lcd2.print(" ON"); }else if (CorrectedValue < tMin){ digitalWrite(RELAY1, LOW); //Relay ON lcd2.print(" ON"); } else { digitalWrite(RELAY1, HIGH); //Relay OFF lcd2.print("OFF"); } }

Step 2: The Box

In the end, when you have all connected and working, you want to have it in a box or something similar.

I just use some thin plywood, a little drill and sand paper.

First of all I designed it on paper, and thought on how big should it be. Than I cut the plywood in make the proper 3mm holes to screw Arduino and the other modules on it, than I screw the plywood to a bigger piece of old wood from a shelf.

That's it. I built it and connected all together and made it works.

Than I calibrate the sensors with this method!

Step 3: Add Another Sensor to Keep Acids Controlled

Here you can find some useful sketches in order to do all what I did.

Obviously the main sketch of the thermostat,

than the one to check the addresses of the lcd to connect them the right way,

The sketch I used to calibrate the sensor with.

Arduino Contest 2017

Participated in the
Arduino Contest 2017