Automate your home with Arduino and Click On Click Off

Automate your home with Arduino and Click On Click Off

Published on: 31-01-2014 17:29 - Lees in het Nederlands

Please note: this article was semi-automatically translated from Dutch, translation errors may occur, links will lead to Dutch websites, you are welcome to comment in English.

Domotics, smart homes and home automation are hot topics these days. Maybe you remember the 'House of the Future' of Chriet Titulaer? His ideas are no longer dreams of the future, these products are available everywhere nowadays. But it's much more fun to build it yourself!

2006: the parallel port

One of my first attempts at controlling lighting at home I did years ago. I had build an interface that controls 220 Volts with relays via the parallel port. After a while I found out that this central control was not really useful, there were 220 Volts cables running all the way trough my room, and the entire circuit board was powered from a single wall outlet...

Attempt 2: Click On Click Off

Years later I found the solution in Click On Click Off modules. The so-called COCO system uses a relay and a 433 MHz receiver that you plug into the outlet, and a wireless remote control to turn it on. Thanks to the excellent 433 MHz library of Fuzzillogic it is relatively easy to control the sockets in an intelligent way. Please note that this library was written for the Dutch version of COCO, I'm not sure if it will work on British or American COCO units.

Arduino home automation

Arduino COCO home automation systeem

What do you need to build such an intelligent COCO unit? First you need an Arduino as the heart of the system. If you want your domotics unit to work without a computer, but be able to log in with your phone or tablet, you also need an Ethernet Shield. The key components are of course the 433 MHz-transmitter and receiver that allow the Arduino to talk to the COCO-sockets. Order them via Conrad or AliExpress.

Consult the datasheet of your transmitter and receiver for the right pin-out and connections. Both need at least +5 V and ground. The Tx-connector of the transmitter can be connected to any port of the Arduino. The Rx of the receiver must be connected to pin 2 or 3 of an Arduino Uno / Duemilanove, because it works with interrupts. As an antenna you can use a piece of wire about 13 cm.

Schematics of the Arduino COCO home automation system

Besides the transmitter and receiver I also attached a temperature sensor (NTC) and a light sensor (LDR) to my home automation system. Now the system turns on the lights automatically when it gets dark, and spins the fans if it gets too hot. Furthermore, it is important that your Arduino knows what time it is, therefore I use the Time Library. Now your home automation system is able to turn the garden lights off overnight, and turn your bedside lamp on in the morning.

Cheap PIR motion detector

Another useful addition to the domotics system are motion sensors. I wanted to use standard PIR detectors, but the wireless version of Click On Click Off is ofcourse way too expensive. Eventually I came across an offer of 230 Volts motion detectors for ony € 1.50! I decided to take the gamble and bought some, hoping that there was a standard PCB inside.

After disassembly I saw two neatly separated printed circuit boards: a PIR module operating at + 5V to 24V and a 230V relay module with voltage converter to 8V. After removing the 230 Volts part and some experimentation, I found out that the pin-out of the board is Vcc , GND and output, from left to right in the picture.

Pinout of a OEM PIR sensor

Programming the Arduino

Because every situation and every home is different, I will not put my full code here. However, I will outline how the code is structured.

In the main loop of the program, the time-critical processes are performed, in this case only the reading of the sensors. For tracking time and decoding radio frequency signals the library uses interrupt routines, so this is handled automatically.

void loop() {
  sensorTemp = analogRead(PsensorTemp) - 238;
  sensorTemp = pgm_read_word(&temps[sensorTemp]);
  // temperatuur bij voltage opzoeken in lookup-table
  if (sensorTemp > maxTemp) {maxTemp = sensorTemp;};
  if (sensorTemp < minTemp) {minTemp = sensorTemp;};

  sensorBuitenTemp = analogRead(PsensorTempBuiten) - 238;
  sensorBuitenTemp = pgm_read_word(&temps[sensorBuitenTemp]);
  // temperatuur bij voltage opzoeken in lookup-table
  if (sensorBuitenTemp > maxBuitenTemp) {maxBuitenTemp = sensorBuitenTemp;};
  if (sensorBuitenTemp < minBuitenTemp) {minBuitenTemp = sensorBuitenTemp;};

  sensorLicht = analogRead(PsensorLicht) / 10.23;
  if (sensorLicht > maxLicht) {maxLicht = sensorLicht;}
  if (sensorLicht < minLicht) {minLicht = sensorLicht;}

  // Events loop

  // Check voor inkomende verbindingen en laat webserver draaien

  if ((hour() != prevHour) && timeOK) {
    // Elk uur data loggen naar SD
    prevHour = hour();

  if ((weekday() != prevDay) && timeOK) {
    // 0.00u alles resetten
    prevDay = weekday();
    maxTemp = sensorTemp;
    minTemp = sensorTemp;
    maxBuitenTemp = sensorBuitenTemp;
    minBuitenTemp = sensorBuitenTemp;
    maxLicht = sensorLicht;
    minLicht = sensorLicht;

From the main loop, the other functions are called once in a while; logging to the SD card, keep the web server running, and tracking and execution of time and / or sensor -driven events. The system also has an 'home' and 'standby' (sleep/away) status, several events take this into account. Thus, the light comes on when it gets dark when the system is 'home', but not when it is at standby.

Of course we want to be in control, so despite everything running automatically, it should be possible for me and others to take control of the lights. Because I have an RF receiver connected to my Arduino, I can receive signals from the original remote. When you switch a COCO module off, the status of the module in the memory of the Arduino changes also.

Graphical interface

The cream of the crop of this project is the graphical interface from SD card, it is always available without a computer!

Graphical interface of the DIY Arduino home automation system

The interface is built in HTML and CSS and is fully responsive, so the widgets are automatically aligned as the screen size allows. On a large widescreen display there are many widgets next to each other, and on mobile everything shows under each other.

The Arduino Web server displays the HTML page that is stored on the SD card and fill it in with the correct live sensor data and switch status. The Arduino server runs not only on the local network, but is also (protected) approachable from outside. In this way I can keep an eye on my house, and adjust if necessary, from anywhere in the world.

Do you have a home automation solution built by yourself? Let me know in the comments below!

31-05-2015: Here you can download the complete code of the domotica controller.

47 comments on this article »

More articles like this one