Temperature Control Using Arduino UNO

I'm working On a Automatic Temperature Control of a Hot water system. It has got temperature output coming out through thermocouple sensors in volts. What I am trying to do is, I want to write a code which takes that analogue input (volts) if that is less then 3.62V then it provide 5V to my next circuit(a relay switch) and keep providing until analogue input voltage get to 3.62V. If it’s more or equal then 3.62V then it provide 0V to my next circuit to do nothing.
Next step would be it every after 5 min it keeps checking and do as mentioned above in certain condition. If it does the same more quickly it wouldn’t be a problem.

My problem area is,

• I am not sure for the code if it would do what i want or not. So please help me with it.
• I don’t know if i write 3.62V directly in condition or do i need to consider the ADC in the Arduino UNO and have to use different number for 3.62V.
• To provide 5V to my next circuit shall i just use one digital pin and ground with my next circuit and make that digital pin go high under certain condition?
• If yes, I don’t know how to enable any digital pin to use it and then how to write the condition to make it go high when my analogue input is less than 3.62V. else do nothing

#include <SerLCD.h>
#include <SoftwareSerial.h>
SoftwareSerial NSS(0,2);
SerLCD lcd(NSS);

int analogInput = 1;
int refresh = 2000;
long TotalTime = 0;
long TimeRun = 0;
float vin = 0.0;
int value =0;

void setup()
{
  pinMode(analogInput, INPUT);
  Serial.begin(9600);
  NSS.begin(9600);
}

void loop()
{
  value = analogRead(analogInput);
  TotalTime = TotalTime + refresh;
  vin = (value);
  TimeRun = TotalTime / 1000; // trying to show total time since system turned on in sec
  
  lcd.clear();
  lcd.print(vin);
  lcd.setPosition(2,0);
  lcd.print(TimeRun);
  delay(2000);
}

click the MODIFY button in the upper right of the post window.
Highlight all you code.
click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button.
click SAVE (at the bottom).
When you post code on the forum, please make a habit of using the code tags "#" button.

I'm working On a Automatic Temperature Control of a Hot water system.

It has got temperature output coming out through thermocouple sensors in volts

.

What I am trying to do is, I want to write a code which

IF analogue input (volts) < 3.62V
then

digitalWrite(relay,HIGH); // it provide 5V to my next circuit(a relay switch) => (COM= 5V, /"next circuit" =N.C.)
IF analogue input (volts) > 3.62V then
digitalWrite(relay,LOW); // it provide 0V to my next circuit to do nothing.
// Next step would be it every after 5 min it keeps checking

My problem area is,

I am not sure for the code if it would do what i want or not.

I don’t know if i write 3.62V directly in condition or do i need to consider the ADC in the Arduino UNO and have to use different number for 3.62V.

To provide 5V to my next circuit shall i just use one digital pin and ground with my next circuit and make that digital pin go high under certain condition?

If yes, I don’t know how to enable any digital pin to use it and then how to write the condition to make it go high when my analogue input is less than 3.62V. else do nothing

"next circuit" is too vague. Identify nature of "next circuit " exactly. (WHAT IS IT ?)
What is so special about 3.62V ?
Why are you doing this ?
READ THESE:

Thank you so much for replying.

next circuit :

next circuit is a relay switch circuit including 3, 6V relays to switch on 3 big 10V relays. those 3 big 10V relays are there to switch 3 coils on i've got in my hot water tank under certain condition.
so when those condition meet microcontroller provides 5V to the 6V relay switch circuit with a view to switch on the coils in hot water tank.
thant condition is, voltage from analogue input should be less then 3.2V. Basically thermocouple sensor provides different voltage for different temperature. but those voltages are in mV which is very small to feed into microcontroller. so i have an amplifier circuit to amplify that signal and amplified voltage signal will go into the microcontroller.
now, 3.2V is an amplified voltage for 70 deg celsius. so what i am trying to do is maintain 70 deg in my hot water tank.

The analogRead will get you a value between 0 and 1023 representing a voltage between 0 and 5V. So you could do the math and calculate the voltage you're getting in code, being careful to use float variables and compare that to 3.62. Alternatively, you could do the calc by hand and use the result of the analogRead directly, comparing it therefore to to 741.

Note that the arduino can't source much current (no more than 40mA) to switch your low voltage relays.

This discussion is getting out of hand. Post a photo of a hand drawn schematic if you want to continue this discussion. I am not going to discuss it any further without a schematic.

if i'm not wrong then,

in my if condition i have to take (3.2/1024) V instead of 3.2V right ?

my very first relay connected to the microcontroller is very small, its 6V and 66 OHM so if calculated it gives 75.75mV.
so i think that shouldn't be the problem.

what schematic is exactly you would like to have a look ?

As @wildbill said, your code will be very much simpler if you figure out the numeric (0-1023) equivalents of the voltages you want to measure and don't bother with voltage calculations within your code. For example if you are using the normal 5v voltage reference then 3.2 v will be repesented by 1023/5 * 3.2 = 654. You can do this on a calculator and it avoids the need for floating point maths and variables in the Arduino

If you place this at the top of your code

const int tempThreshold = 654;

you can just refer to tempThresold in your IF statements.

Using 654 (for example) rather than 3.2v has another major advantage. If you need to print the value from the ADC for debugging purposes it will be immediately comparable.

...R

what schematic is exactly you would like to have a look ?

A schematic of the circuit you are talking about of course.

Best temperature control generally utilizes a full PID algorithm with properly tuned control values to give overall best results as to heat up time from ambient, minimum over shoot and generally most accurate final temperature control for the process. These can be pretty complex to set-up initially for a beginner even though there does exist a PID library for the arduino platform and I wouldn't recommend it for you first attempt at a simple project.

For your stated project I would rather recommend you try an implement a simple 'band gap controller'. Instead of just looping and making the heater on off decision based on being <> a single desired value (70C) you rather bracket that decision value and on each pass of the main loop if the temp is say >= 73C you turn the digital output off and if it's <= 68C you turn the digital output on. The use of the 'hysteresis' band will prevent the relay from chattering on and off as you reach your desired setpoint. Water temperture change is a rather slow process and using a band gap control will keep the temp within the desired range you use, and of course you can play with the delta values to see how tight you can keep it without over switching of the heater. This is how most central forced air home furnaces operate as the mechanical thermostat has the hysteresis build in mechanically in it's contacts.

Good luck with the project.

For your stated project I would rather recommend you try an implement a simple 'band gap controller'. Instead of just looping and making the heater on off decision based on being <> a single desired value (70C) you rather bracket that decision value and on each pass of the main loop if the temp is say >= 73C you turn the digital output off and if it's <= 68C you turn the digital output on. The use of the 'hysteresis' band will prevent the relay from chattering on and off as you reach your desired setpoint. Water temperture change is a rather slow process and using a band gap control will keep the temp within the desired range you use, and of course you can play with the delta values to see how tight you can keep it without over switching of the heater. This is how most central forced air home furnaces operate as the mechanical thermostat has the hysteresis build in mechanically in it's contacts.

Great idea !
That's an excellent suggestion for probably more than half of all the temp control posts we see here.

Robin2:
You can do this on a calculator and it avoids the need for floating point maths and variables in the Arduino

If you hard-code the arithmetic expression to convert the constant value from temperature units to analog input values in your code, the compiler should evaluate it for you and just put the resulting value in the executable image. That might make it clearer if you want it to be obvious what value you're using in real-world temperature units.

The simple map() function is an easy way to convert ADC count values to a units range that makes more sense inside your sketch or for sending out the serial port.

says:
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V

does it means it can not take voltage lower than 7 or 6 V ?

It should work at 6v but 7v is better.

...R

I'm feeding 3.2v or below. So according to u will it recognise that range of voltage ?

Like, I have a condition in my code that is analogue input voltage is less then 3.2V thn do something and if it is greater than 3.2 then do something else. So my question is can it not read that level of voltage ? Is it has to be more than 7V and below 12V ?

The analog input range is set by the Vcc. If the chip is a 3.3V processor then your range is 0 to 3.3V. If it is a 5V version then your range is 0 to 5V. The resolution is set by the AnalogReference statement.

On a 5V board the default is 5V on 5V boards and 3.3V on 3.3V boards. You can change it to Internal with this statement making it 1.1V but then your allowable range is 0 to 1.1V and no higher.
You have no optioins here . You have to use 5V, so you can measure anything from 0 to 5V and the value measured is
5V/1023-0.00488V (4.88mV) per count so anything you measure is (Vanalogin/0.00488V) counts.
1V=204 counts
2V = 408 counts
3V =612 counts
4V= 816 counts
5V = 1023 counts

Thank you :slight_smile:

I got answer to my question, but now I don't understand what it means by input voltage recommended 7-12 ?

The arduino external dc power barrel jack is the input for the onboard regulator.
When the USB cable is plugged in, the onboard regulator is not used because the circuitry detects the USB 5V input and uses that.
When you plug in the external dc barrel jack power of 7V or higher up to 12V , the circuitry detect that and switches to that by turning off the mosfet that normally allows the USB 5V to connect to the board. This is accomplished using a comparator which compares the dc input jack voltage to 3.3V . If it detects voltage there is switches off the USB 5V. The reason the voltage must be 7V is that all regulators have and overhead, just like all comapanies have an overhead. The bottom line is not voltage (or money ) in , it is voltage (or money) in minus the overhead, which in this case is 2V. That's why you need 7V in to get 5V on the board.The reason it should not exceed 12V is that the regulator must dissipate the extra heat caused by having to drop the voltage from 12 to 7V, just like a company must pay employees who have nothing to do. Does that explain it (with my crappy analalogies) ?

tank you so much for the reply. and yes it did explain.

now, may i please know what 9600 means ? this line was written for serial enabled 16X2 LCD.

Serial.begin(9600);