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. The Best Of Dante 14k

    hola amigo como puedo hacer para que no lleve la estufa solo el ventilador osea osea me refiero al diagrama es que apenas tengo 13 años y no se manejar el arduido muy bien es que es un proyecto para mi clase.

  2. hola buen dia tengo una duda que pasaria si yo quiero configurar la temperatura desde fuera de la placa arduino es decir tu definiste amb=25, como le podria hacer si tengo un lcd o una pantalla tactil y quiero modificar la temperatura agradezco su ayuda saludos ,uy buen post

    1. Hello Alex,

      Well, if you have an LCD, then it depends on the model of LCD module you are using. You should read the manuals for these for help. But the concept would be to create code so that the temperature information comes out of some of the Arduino connections and is fed into the display properly... I advise you to see our posts where we work with LCD displays in case they can help you. I think this was your question, although you say "set the temperature", did you mean using a touch screen as an actuator?

      Best regards and thanks for reading us.

  3. Hello,
    Forgive me for writing in such an old thread, but I'm looking for information to read LM35 data and what you are doing fits me very well.
    My big doubt is that if the LM35 can read temperatures between -55º and 150º (0.55v and 1.5v) and arduino offers values between 0 and 1024 for the analogRead reading, with the formula you put here (which is the same I've seen in other sites) it doesn't work. For example, it is impossible to read a negative value.

    While writing this question I looked up the LM35 datasheet (http://www.ti.com/lit/ds/symlink/lm35.pdf) and I think I have found the answer, if you can confirm it I would appreciate it:
    It appears that the LM35 has two modes of operation, one in which it measures from -55º to 150º and another (the one we usually use) which only measures positive values from 0º to 150º and offers voltage outputs from 0V to 1.5V with 10mV increments for each degree Celsius.

    By the way, in my experiment I am using nodemcu whose analogue input only reads values from 0V to 1V which also makes me change the formula (and end up crazy).

    Thanks for the article

    1. Hello
      I did a project with the lm35 and in order to read the full temperature range I used the configuration with the two diodes above "Figure 18. Temperature Sensor, Single Supply (-55° to +150°C)" on page 16 of the datasheet you posted. Read the two analog values (the + and - of the vout in the diagram). Then subtract Vout+ minus Vout-. If the result is positive, it means that the temperature is positive and the result of the subtraction is enough to make the conversion to Cº as it says in the post. If the result is negative (Vout- was higher than Vout+), we have to invert the subtraction: Vout- minus Vout+. The result is the absolute value of the temperature, that is, after converting to Cº, the result is the negative temperature degrees. I don't know if I have made myself clear...

  4. Gabriel Aguilera Urrutia

    My last question (sorry to bother you so much, but you're the only one who has answered me)
    AN4=((AN4*500.0)/1024.0) - 272.15;
    subtracting 272.15 converts from Kelvin to Celsius.
    The lm335 sensor when used with a basic program for LM35 gives me high values.
    That should make it look good?
    Thank you for helping me 🙂

    1. Yes, you are right. My mistake when I was going through the code to answer you I didn't notice that I was simply transforming the voltage to degrees and not converting it from one unit to another.

      Subtracting, as you say, will work.

      Greetings and sorry for the mistake.

Leave a Comment

Your email address will not be published.

en_GBEnglish
Scroll to Top