Connect the relay and the temperature sensor to the YUN

The first step in our arduino project is to buy and assemble al the components. You need and Arduino YUN microcontroller, one or more temperature sensors and a relay.

Arduino YUN.

The Arduino YUN is a new member of the arduino family, and it has a few advantages over an Arduino Uno or an Arduino Leonardo. To summarize, the Arduino YUN is an Arduino Leonardo with an on board ethernet, wifi, a sd card reader, and another processor, an Atheros AR9331 , which executes a Linux operating system called “Linino”, and based on the OpenWRT Linux.

It’s like having a small Linux server, capable of acting as a web server, a database server, and it can interact with the arduino via webservices, read and write the status of the arduino digital pins, and to communicate with the sketch reading and writing data.

All of that, out of the box.

More info about the arduino YUN:

Products from

Temperature sensor DS18B20

We will use a cheap temperature sensor, the DS18b20, known as “one wire” sensor. This means that the sensor can work in a special mode called “parasite mode”, and it can use the Dq pin to store energy, do the measurement of the temperature, and send the data through the same pin to the arduino. Because of this, the sensor takes 750ms to do a measurement, but this is fast enough to our purposes.

DMore intormation about this sensor and how it works.

Relay to turn on and off the boiler.

By default, the thermostat expects to find a “High Level Trigger” relay acting as on-off switch, like this one. The project can work with “Low Level Triggered” relays, but you have to adjust the settings in the app, to let the thermostat know what kind of relay it has.

The important thing here is that the relay must capable to interact with the arduino and the electric current of our home. Because of that you need a 5V/220V relay. You can find it in dealextreme or or amazon.

A micro sd card as storage device.

We will use a micro sd card to act as our “Linino” storage device. You can use an old micro sd card. 1Gb will be more than enough. You can use an old usb drive  instead of the micro sd card if you want, but I find the micro sd card more stylish.

It is very important to use an external memory and don’t use the internal memory of the Arduino YUN. The reason is that the yun’s memory is a flash memory, and the number of writes are limited.

Micro SD insertada en arduino YUN
A micro sd card mounted on the arduino YUN

How to power the Arduino YUN.

The yun needs 5v electrical current. Be carefully, with more than 5V, the arduino yun will be damaged. I’m using an old smartphone charger which has a microusb connection. You can use an usb cable connected to a computer if you want.

How to connect the temperature sensor.

You can buy the resistance and the temperature sensor already mounted in a board. In this case, the board comes with a little led which will show us when the sensor is measuring the temperature.

Ds18b20 keyes temperature sensor
Ds18b20 keyes temperature sensor

Do the following connections:

  • green cable: connects the pin (-) of the keyes board with the GND pin of the  arduino.
  • orange cable:  pin (+) of the keyes board with the 5V pin of the arduino.
  • red cable: connects pin S of the keyes board with the digital pin 2 on the arduino.
Detalle de la placa keyes con el sensor DS18B20 conectada al YUN
Detail of the connections

Placa Keyes DS18B20 y Arduino YUN

A new feature since the version 1.4 of the android app, is that the thermostat can handle up to 20 wired temperature sensors. Some users of the project have managed to install different wired sensors at home in different rooms. The connections are easy: you have to connect the sensors in serial with the main sensor, like in the following images.

Three wire temperature sensors connected in serial mode.

How to connect the relay.

The connections are the same connections that we did in the exercise ” how to control a bulb with arduino yun and Android:

  • White cable: connects the IN pin of the relay with the digital pin nº  6 of the arduino.
  • Black cable: this is our ground connection. You have to connect it in the breadboard, in the same row as the ground connection of the temperature sensor.
  • Brown cable: this connection provides 5V to the relay. Because of that you need to connect the cable to the same row in the breadboard that we are using to feed the temperature sensor with 5v (the row of the orange cable).
  • Electrical connections of the relay: you have to use two of the electrical connections to connect your relay to your boiler. The relay has to work in Normal Open mode, because of that you have to connect one wire to the NO electrical connector, and the other to the GND connector. More information about this topic in our faq.
Detalle de la conexión del relé al arduino YUN
How to connect the relay to the arduino, 1/2
Detalle de la conexión del relé IN del relé al pin digital 6.
How to connect the relay to the arduino 2/2.

Everything is connected now, except the connection of the relay and the boiler. The next step is to download and install the Android app. Then, you will use the wizard to install all the needed software on the Arduino Yun. Next step.