Home Automation Using Raspberry Pi, Arduino, Domoticz, MySensors.




About: I am a Project Management Analyst at a reputed brand. Electronics and Photography are my hobby which I pursue on my weekends.

Hi Fellow makers,

This is my first Instructable on Home Automation. The idea is to build a controller and wireless nodes to control and monitor.

After a lot of hit and trial with many different controllers like OpenHab, DomotiGa, Ago Control, finally I decided to go with Domoticz as Controller and MySensor for Nodes.

You must be wondering why I decided to build. I had a problem which I wanted to resolve. It all started with Water management. I live in a area where we get water supply for only 2hrs a day. This is when I have to fill up the overhead tank so that I can use the water for daily consumption. The problem is the overhead Tank is on terrace above 3rd Floor and without access to floor as its locked. Secondly The water supply is from 4AM-6AM which is a very inconvenient time. I cant know how much water is stored and when its overflowing or when its empty.

So I decided to build my own water level sensor and a relay to control the water pump.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: How Would It Look Like

Step 2: Preparing Raspberry Pi

Lets begin buy preparing Raspberry Pi as a controller. I have used Domoticz as a control software.

  • Install Domoticz on Raspberry Pi. Download the software from Domoticz Download
  • Burn the image to SD card using Win32 Disk Imager
  • Now plug in the SD card and boot.
  • Connect to Raspberry Pi using terminal
  • Run command sudo raspi-config
  • Apply Expand File System.
  • Reboot.
  • Now you can access the Controller software using http://your-raspi-IP:8080

Step 3: Adding Gateway to Raspberry Pi

Now we will create the gateway, so that the nodes can communicate.

For gateway we will use

  • NRF24L01+
  • Arduino Uno or Arduino Mini Pro
  • USB Cable to connect with Raspberry Pi
  • Some cables.
  • LED's 2-Green, 1-Red, 3 - 1K resistor (Optional)

Follow instructions here to connect the NRF24L01 module to Arduino.

Now load the Gateway Sketch on Arduino. Skecth is available here

Once done, connect Arduino to Raspberry pi using USB cable.

Now we will configure the gateway on Domoticz. Goto Setup>> Hardware.

  • Type in any Name you want for Gateway
  • Select type as MySensor Gateway USB
  • In Serial Port if detected it would show USB01 or USB02. Select it.
  • Check Enabled.
  • Click Add.

The optional LED's can be used to Show the TX,RX, Error status on getway.

Now your gateway is ready to accept new nodes.

Step 4: Building a Water Level Node With Relay

The first step is build the Ultrasonic sensor module for installation on water Tank.

Material used:

  1. HC-SR04 ultrasonic Module
  2. Some Wires
  3. Casing to hold everything together
  4. 2pcs 2 Pin terminal Block(I did not have any other connectors handy)
  5. 1pc Red Led
  6. 1pc 1k resistor
  7. Some hot glue to keep everything in place.

The instruction on connecting the wires can be found here

Now will build the receiver for Ultrasonic sensor.

  1. Solder female header pins on prefboard for Arduino and NRF24L01+.
  2. Build the Relay driver using the circuit shown.
  3. I have added a 3.3V Regulator using AMS1117 for NRF24L01+
  4. Once everything is in place tested the cuircuit
  5. For power supply I am using an old Nokia Charger I had lying around.

I have attached the sketch to control relay and read Utrasonic sensor using one Node.

The water level shown is in percentage. I dont know how I can get it display in % in Domoticz, but as of now it shows in cm but actually its in %.

The calculation is (Tank Height-Actual Reading)/3. The tank is 300cm high.

Step 5: Automating the Motor(Water Pump)

You must be wondering where is the automation here. In Domoticz it supports Blocky. You can create your own rules to control.

Now in Domoticz goto Settings >>More Options>> Events and create 2 new events.

  1. If Time =5:00AM then Turn Motor On
  2. If Water level >=95 then Turn Motor Off.
  3. If Time >=6:00AM then turn off motor.

This would turn the motor on at 5 and once the water level is reached to 95 or time is >=6:00 then it would turn off the motor.

I have the temperature sensor already working, but its still on
Breadboard. Will complete it during weekend and upload. Also I am working on PIR and MQ-2 Gas sensor, still trying to figure out which sensors can be combined in one node. Thanks for reading and will be back soon with more nodes. In case you have any questions please feel free to ask will try to answer if possible.

Home Automation

Participated in the
Home Automation

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    15 Discussions


    4 years ago on Introduction

    If you like my article, please vote me for Home Automation Contest. Thanks


    Question 1 year ago on Step 2

    Should I burn the domoticz image?


    1 year ago

    Good information
    Thanks for sharing


    1 year ago

    Absolute beginner here, but am I able to use a second Arduino Uno and NRF24L01+, i.e. same setup as the gateway, to connect up the sensor, instead of building one up with the Arduino Mini? Thanks

    2 replies

    Reply 1 year ago

    I did not get you question. Are you not able to use Arduino mini? More info would be of help to help you.


    Reply 1 year ago

    Sorry, what I meant was can I use a Uno instead of the setup you have with the mini, as I already have 2 Uno boards to hand. Saves me buying a mini.


    2 years ago


    Which version of Raspbian did you use? I am having problems with Raspbian stretch


    1 reply

    Reply 2 years ago

    I used image from Domoticz site. Its precooked with domoticz


    2 years ago

    Nice explained instructable, thanks for sharing! :)


    2 years ago

    Anyone know if I can use Mysensors v2 and serial gateway with Domoticz on RasPi?


    4 years ago on Introduction


    Maybe this is a stupid question, but I've only got my first Arduino Uno in two days ago. Already have been working with Domoticz on Rpi for over a year now. Recently I've build a water irrigation system for my garden, controlled by a relay which can be switched through Domoticz using a GPIO. Now I would like to add some ground moisture sensors, using a Arduino and the domoticz Gateway to Mysensors to water the garden when the soil gets too dry.
    I've uploaded the serialgateway sketch to an Arduino Uno and I also have a sketch to read the output of the sensor using the Analog output. Now my question is, how can a add this sketch to the arduino without deleting the gateway sketch?

    If I understand correctly, uploading the gateway sketch is obviously the first step, after that you'll have to upload specific sketches for various sensors to be able to add a 'node' ?

    Can you put me on the right track? Thanks in advance!

    1 reply

    Reply 3 years ago

    The Sketch for the gateway you will upload to the arduino that works as the gateway. Your sensor's sketch will be uploaded to your node (not to the gateway).

    So you need ONE arduino for the gateway. Thi will send/receive information from/to your server.
    And you will need one arduino for each node you build. In one node you can use more than one sensor it you need.

    For example you can have a node to read temperature, humidity, level of something, open/close sensor and a relay do activate something.

    The controller will see that node plus each sensors.

    The most common is to have one sensor per node, but you can have multiple


    4 years ago on Step 3

    Hello i got a huge question

    i am deply sorry my english is not my native speak so I hope you get what i say

    as far as I have read the gateway its something that the main arduino tells to the raspberry what information he gets as main i speak as the serial one, My question is if I can connect a Xbee to the Rasp and send comands to it from the arduino in somewhere else, if not can i just boost info from the arduino that is conected to the rasp

    exp i get a ADC from that main arduino and i get the data to the rasp and then to the app