Home automation with Arduino: automatic climate control

Symbol for cold heat

A home automation system makes life easier and more comfortable. Now we can create an inexpensive automated system with Arduino, without the need for expensive PLCs and home automation devices.. The system can be installed in a living or working area to ensure that we are always at a comfortable temperature.

The experiment consists of creating a system that measures the ambient temperature and can switch on a heater or a cooling system, depending on the temperature detected. In this way it will constantly maintain an ideal temperature in winter and summer without us having to lift a finger.

Materials needed

  • Arduino UNO board. (Available in our shop)
  • LM35 temperature sensor. The LM35 can operate with voltages between 4 and 30v, so it will work perfectly in our Arduino (5v). It can also measure temperatures in a range from 150ºC to -55ºC, more than enough to measure normal ambient temperatures.
  • Electric heater or cooker.
  • Fan or cooling system.
  • 2 relays with 5v control system and 220v output (5v-220v).
  • Single-core cable for connections to the Arduino board.
  • 4mm electric cable for 220v connections.
  • Switch (220v).
  • Connection sheets.
  • 2 female and 1 male plug (220v).

Procedure

First I would like to explain how the sensor we are going to use in practice works. The LM35 provides output voltages proportional to the detected temperature. 150ºC is equivalent to 1.5v output and -55ºC to 0.55v. So we can make a simple rule of three to calculate the temperatures detected as a function of the voltage. The output is linearso each degree Celsius is equivalent to 10mV increase in output (10mV/°C). For the calculation we can use the following formula:

ºC = (5 * analogRead(PIN_SENSOR) * 100) / 1024

Being analogRead(PIN_SENSOR) the voltage expressed in mV of the output of the LM35 sensor that we obtain through the analogue pin of the Arduino. Remember that the analogue inputs of the Arduino, despite being analogue are treated as digital by the microcontrollerrepresenting them with 10-bit values.

As we can see, if we look at the LM35 temperature sensor we can see three pins, one that we must connect to the +5v of Arduino, the central one to the output where the voltages corresponding to the measured temperatures will be collected and the right one for ground (GND).

LM35 pins

Now that we know how the sensor works, let's start with the assembly. We will simply connect the left pin to the +5v terminal of the Arduino board, the middle pin to the analogue input A4 (for example) and the right pin to ground (GND).

LM35 connected to Arduino

Next we will place the corresponding relays for the cooker and for the refrigerator. The relays also have different pins for control. The relay will act as an automatic switch that will send current to the appliance in question. By having two unconnected circuits, the relay can be controlled by voltages of a few volts (5v in our case) of direct current and act as a switch for alternating currents of 220v, sufficient to power domestic appliances. As it is a normally open relay, only when the Arduino sends a voltage to the relay, it will allow the current to flow to the electrical device connected to it.

The connection of the relay will be as follows. On one side we must connect terminals A and B to the Arduino board. One to GND or ground and the other to one of the digital outputs, for example 3 for one relay and 2 for the other.

Relay pins

On the other hand, taking appropriate precautionsIf you have a male plug, you must connect the cables to a male socket in order to be able to connect it to any socket and obtain the necessary power.

Fitting a plug

One of the wires (phase or neutral) used for the previously assembled plug is cut and a switch is inserted to switch the voltage on and off at any time.

Fitting a switch

The other ends are then connected to two splice plugs, one for each pole, and two new wires are taken from each terminal. That is, so that there are two new phase wires and two new neutral wires. The two new phase or neutral wires, either one, are connected to the terminal marked C in the image of the relay.

After that, we will continue making the appropriate connections with the wires coming out of the relays and we will mount two female plugs. This will give us two sockets to connect the fan to one and the heater to the other.

electrical-connections

The electrical assembly of our experiment is now ready. Now it's time to program the sketch, which will be as simple as the one in the following image:

[cpp]
//Climate control

const int amb=25; //Declaration of temperature constant
const int vent=3; //Declare fan pin
const int estu=2; //Declare pin estufa
int AN4=A4; //Declare analogue input on pin 4

void setup(){
pinMode(vent, OUTPUT);
pinMode(estu, OUTPUT);
pinMode(AN4, INPUT);
}
void loop()
{
AN4=analogRead(A4); //Analogue connection of LM35
AN4=(AN4*500.0)/1024.0; //Calculate temperature in ºC
Serial.println(AN4);
if(AN4amb) //If the temperature is higher than 25ºC
{
digitalWrite(vent, HIGH); //Activate fan relay
digitalWrite(estu, LOW); //Disables the cooker's relay
}
else // In any other case, both are disabled.
{
digitalWrite(vent, LOW);
digitalWrite(estu, LOW);
}
delay(180000); //Delay between measurement and measurement of 3min.
}
[/cpp]

Finally, we can connect the air conditioner/fan and the stove/heater to the sockets and test that everything is working properly. We can cool the sensor or heat it ourselves to see how it works. and that the relays are activated correctly. Thanks to the inclusion of the Serial.println in the source code, we can display the values in degrees Celcius on our PC screen while we have the Arduino connected. In order for the circuit to be autonomous, we will have to connecting the Arduino board to a power source suitable or 5v batteries.

Buy - Arduino UNO rev.3

More information - Controlling Arduino from Raspberry Pi

21 thoughts on “Domótica con Arduino: climatizador automático”

  1. How do you turn off the split without abruptly cutting off the power and not affecting its operation?

  2. Good day, arduino is a very practical environment for this type of project and I am glad that there are people like you who program and share their experiences, for my part I could contribute that you could integrate a keyboard a lcd and optocouplers to separate the stages of control and power and perhaps you could also use a thermocouple type j or k and thus expand the range of measurement could control a furnace a boiler... I that is..hehe.... I congratulate you for your work friend.

  3. Hello friend I see that you have problems with setting your memperatura and a lcd I did a test and need an arduino due (because it has mini usb connection and use a numeric keypad pc and because I connect the lcd by i2c not to use a normal lcd and connect both cable) and I could make that I could change the temperature I wanted and display it by the lcd is only a matter of research there is much material for the network, successful

Leave a Comment

Your email address will not be published.

en_GBEnglish
Scroll to Top