DIY Home Automation Sensors: The First Sensor

This post is part of a tutorial on building Low-Cost Home Automation Sensors. If you have landed on this page directly I suggest you check first Low-Cost DIY Home Automation Sensors. In this part of the tutorial, you will build the gateway. The gateway will handle the communications for all the nodes in your network.

If you are starting with Arduino you should check the Arduino for Dummies Guide, it will help you get up to speed.

Bill Of Materials

 

Units Description
1 NRF24L01+ 2.4GHz Wireless RF
1 Arduino Nano V3
1 Jumper Cables
1 DHT22 Temperature and Humidity Sensor

 

Build The Circuit

For this particular sensor, I am using an Arduino Nano. It has a very small footprint and works great for nodes that you plan to have connected to a power outlet.

 

 

 

When you buy the DHT22 sensor you might receive one that looks slightly different from the one in the diagram. If you get something that looks like this one, don’t worry.  It is the same sensor but some manufacturers ship it integrated on a PCB only with the 3 pins that are relevant. You just have to connect Out  to D3 and the other 2 to VCC and GND.

Install Additional Libraries

The code for Arduino that you have below requires 2 libraries, MySensors and DHT22.

MySensors

1.Download the latest RC of the MySensors library from this link.

 

2. Add zip file as a new library.

 

 

DHT22

When I wrote this tutorial initially, I was using the library downloaded directly from the library manager in the Arduino IDE. Thanks to the feedback from Nucutza (in the comments) I got to know that the library has been upgraded and the code no longer compiled. As per his suggestion, I am adding the link to the MySensor External Libraries. Among other things, it contains a modified version of the library to interface with DHT11 and DHT22 sensors.

Upload the Sketch to the Arduino

You can find a link on how to upload sketches to Arduino if you are not familiar with the platform yet.

 

Adding new Items to OpenHab

The Arduino sketch you just uploaded will be publishing values in the following topics.

 

Temperature ->  mygateway1-out/1/0/1/0/0
Humidity        -> mygateway1-out/1/1/1/0/1
The definition of the topic above will depend on the parameters defined on your sketch, mostly the node identifier and the id’s that identify each of the sensors.

 

If you change the parameters on the sketch, please make sure you modify the topics accordingly.

 

Temperature ->  mygateway1-out/MY_NODE_ID/CHILD_ID_TEMP/1/0/0
Humidity        -> mygateway1-out/MY_NODE_ID/CHILD_ID_HUM/1/0/1
If you are using OpenHab, make sure you have a look at the MQTT and OpenHab tutorial.
As a reference, here you have the definition of the items for the sketch above.

 

If you want to learn more about the communication protocol of the MySensor library check MySensors Communication Protocol.

 

I hope you liked the tutorial, if you have questions or suggestions please post some comments.

 

This Post Has 10 Comments

  1. The sketch isn’t compiling with the library you mention !

  2. Hi Nucutza,

    Thanks for the heads up. I will update it tonight when I get home.

    I noticed when I Did this tutorial https://www.smarthomeblog.net/smart-arduino-thermostat/

    I had to change a few things o the function that sends the temperatura.

    I will update this code and let you know.

    Thanks again for the heads up!

  3. No problem. However it will compile with the DHT library from MySensorsArduinoExamples

    Thanks for your nice tutoria-lrt. I managed to configure a rpi gateway with rfm69hw radio.
    Furthermore I put an openvpn server on the same pi to acces openhab from internet. (pivpn)
    Now I try to learn more about openhab syntax/configuration. (sitemap, items)

  4. Hi Nucutza,

    I have upgraded the post with your feedback, thanks for taking the time on letting me know. I will a-lrto update this week the part where I download the library for MySensor. MySensors 2.3 is already released so it doesn’t make sense to go for the development branch anymore.

    Just out of curiosity, why have you decided to go with a vpn approach instead of using the OpenHab Cloud to grant external access?

    Thanks for your feedback again!

  5. I choosed vpn mainly for privacy/security.
    I don’t trust to put my home sensors on public sites 🙂

  6. Are you a-lrto planning to use signed messages with MySensors?

  7. Probably I will try.But for now I think that hacking 433Mhz radio links is not very common.

  8. Thx for your tutorial although it took me 2 days to figure out that

    mygateway1-out/7/0/1/0/0 should be mygateway1-out/1/0/1/0/0 and mygateway1-out/1/1/1/0/1

  9. Hi Stefan,

    I read it again and that part was actually poorly explained, sorry about that. I have added some detai-lrt and this weekend will review the full post to provide additional explanation.

    Thanks for pointing it out.

    Anything e-lrte that you had difficulties with?

  10. No, The rest of the tut is clear (i,m not a programmer) and It’s working fine now.
    Thanks again.

Leave a Reply

Close Menu