Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 69.47 KB | None | 0 0
  1. 500: Internal Server Error
  2.  
  3.  
  4. An exception occurred while executing 'INSERT INTO `wallabag_entry` (uid, title, url, is_archived, is_starred, content, created_at, updated_at, mimetype, language, reading_time, domain_name, preview_picture, is_public, http_status, user_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, "How to Build DIY Door Sensors for your Home Automation Project", "https:\/\/www.smarthomeblog.net\/diy-door-sensors-arduino\/", 0, 0, "<p>As a DIY person, you are probably comfortable with the idea of protoboards placed in conspicuous locations of your house.<\/p><div class=\"code-block code-block-8\" style=\"margin: 8px 0; clear: both;\">\n<!-- Ezoic - ALL_IN_CONTENT_FLOAT_1 - mid_content -->\n\n<!-- End Ezoic - ALL_IN_CONTENT_FLOAT_1 - mid_content --><\/div>\n\n<p>But\u2026What happens when not everyone in your household shares your passion for experimentation or your cat develops a fetish for stealing cables (this is my case\u2026)<\/p>\n<p>Door sensors are paramount for any Home Automation System and you need something that you can <em>Set and Forget<\/em> and that gets the approval from every member of the family, especially the cat.<\/p>\n<p>On this tutorial, you will learn how to create door and window sensors that run on batteries for long periods of time and don\u2019t look like explosive artifacts hanging from your door.<\/p>\n<p>This post is meant to be the second part\u00a0\u00a0<a href=\"https:\/\/www.smarthomeblog.net\/diy-home-automation-sensors\/\" target=\"_blank\" rel=\"noopener noreferrer\">DIY Home Automation Sensors: The Ultimate Guide.<\/a>\u00a0I would advise you to check that one first, you will need some familiarity with the MySensors library for this project.<\/p>\n\n<h2>DIY Door Sensors: Features<\/h2>\n<p>Here is a brief outline of the features that your door sensors will have:<\/p>\n<ul><li>The components used to build the door sensors are low-cost. I don\u2019t want to go bankrupt over this project.<\/li>\n<li>It runs on batteries for about a year. We want something that we can\u00a0<em>set and forget.<\/em><\/li>\n<li>It reports battery level to my home automation system. You don\u2019t want to discover that it ran out of battery when you needed it the most.<\/li>\n<li>It communicates wireless with my Home Automation System.<\/li>\n<\/ul>\n<h2>DIY Door Sensors:\u00a0 Requirements<\/h2>\n<p>Before you start this tutorial, there is some basic infrastructure and knowledge that you need to acquire:<\/p>\n<ul><li>You need a Home Automation Controller that will receive the updates from your door sensors. I would recommend you <a href=\"https:\/\/www.smarthomeblog.net\/openhab-raspberry-pi\/\" target=\"_blank\" rel=\"noopener noreferrer\">OpenHab<\/a>.<\/li>\n<li>MySensors also needs an\u00a0<a href=\"https:\/\/www.smarthomeblog.net\/mqtt-openhab\/\" target=\"_blank\" rel=\"noopener noreferrer\">MQTT broker<\/a> connected to your Home Automation Controller.<\/li>\n<li>You also need to build a\u00a0<a href=\"https:\/\/www.smarthomeblog.net\/diy-home-automation-sensors-gateway\/\" target=\"_blank\" rel=\"noopener noreferrer\">MySensors Gateway<\/a> which will relay the messages to the MQTT broker above.<\/li>\n<li>If you are starting with Arduino you should check the <a href=\"https:\/\/amzn.to\/2pOjeMw\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino for Dummies Guide<\/a>, it will help you get up to speed.<\/li>\n<\/ul>\n<h2>DIY Door Sensors: Bill of Materials<\/h2>\n<p>Here you can find the list of components that you will need for the door sensors project.<\/p>\n<p>Most of the items come in packages with several units so you will be able to build several sensors with them.<\/p>\n<table><tbody><tr><td width=\"86\">Unit<\/td>\n<td width=\"367\">Description<\/td>\n<td width=\"328\">Comments<\/td>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2tF0FNc\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino Pro Mini 3.3v 8mhz<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"http:\/\/s.click.aliexpress.com\/e\/7QjAY72\" target=\"_blank\" rel=\"noopener noreferrer\">DC\/DC Step up booster In: 0.8 \u2013 3.0 Out:3.3v<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2Nnqvx8\" target=\"_blank\" rel=\"noopener noreferrer\">NRF24L01+ 2.4GHz Wireless RF<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2KDt508\" target=\"_blank\" rel=\"noopener noreferrer\">Capacitor\u00a0throughhole 0,1uF<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2KDt508\" target=\"_blank\" rel=\"noopener noreferrer\">Capacitor\u00a0throughhole 4,7uF<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2ME3vZV\" target=\"_blank\" rel=\"noopener noreferrer\">Pinheaders\/Jumpers<\/a><\/td>\n<td>Optional. Cables can be soldered directly to the board.<\/td>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2tTld3J\" target=\"_blank\" rel=\"noopener noreferrer\">Screw terminal 5,08 spacing<\/a><\/td>\n<td>Optional. Cables can be soldered directly to the board.<\/td>\n<\/tr><tr><td>2<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2NbxetW\" target=\"_blank\" rel=\"noopener noreferrer\">Resistor\u00a0throughole 1M<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2NbxetW\" target=\"_blank\" rel=\"noopener noreferrer\">Resistor\u00a0throughole 470k<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2NbyEoo\" target=\"_blank\" rel=\"noopener noreferrer\">Battery Case Holder<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2KmvksP\" target=\"_blank\" rel=\"noopener noreferrer\">FTDI Programmer<\/a><\/td>\n<td>You need one of these to program the Arduino Pro Mini if you don\u2019t have one already.<\/td>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/amzn.to\/2KyTuQO\" target=\"_blank\" rel=\"noopener noreferrer\">Door Sensor or Reed Switch<\/a><\/td>\n<td\/>\n<\/tr><tr><td>1<\/td>\n<td style=\"text-align: left;\"><a href=\"https:\/\/www.openhardware.io\/view\/4\/EasyNewbie-PCB-for-MySensors\" target=\"_blank\" rel=\"noopener noreferrer\">EasyPCB for MySensors<\/a><\/td>\n<td\/>\n<\/tr><\/tbody><\/table>\n<h3>\u00a0<a href=\"https:\/\/amzn.to\/2tF0FNc\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino Pro Mini 3.3v 8mhz<\/a><\/h3>\n<p>Arduino is a very powerful micro-controller with lots of features,\u00a0 but low power consumption is not one of them.<\/p>\n<p>One of the requirements of the project is to be very efficient when it comes to battery consumption and for that reason, I want to give you a few tips to reduce the Arduino power consumption.<\/p>\n<ul><li><strong>Use the Arduino 3.3v version<\/strong>, the power consumption is significantly lower than the 5v version and this project doesn\u2019t require 5V anyway.<\/li>\n<li><strong>Remove the voltage regulator and the power led<\/strong>. This mod will significantly extend the battery life of your sensor.\u00a0 If this sounds like gibberish to you don\u2019t worry, I will leave a video at the end of the tutorial that explains how to desolder those two components.<\/li>\n<\/ul><p>I should say that this is not required for the DIY Door Sensor to function correctly but it is very relevant if you want your node to run on batteries for a long period of time.<\/p>\n\n<h3><a href=\"https:\/\/amzn.to\/2Nnqvx8\" target=\"_blank\" rel=\"noopener noreferrer\">NRF24l01 (Radio)<\/a><\/h3>\n<p>The NRF24l01 is an inexpensive component that adds the wireless feature to our nodes. It works on 2.4 GHz so the range is not astonishing but sufficient for an average Home Automation Project.<\/p>\n<p>Let me know if you have range issues, or live in a big house, there are a few things that can be done.<\/p>\n\n<h3><a href=\"http:\/\/s.click.aliexpress.com\/e\/7QjAY72\" target=\"_blank\" rel=\"noopener noreferrer\">DC\/DC Step up booster<\/a><\/h3>\n<p>Without getting into unnecessary jargon here, there are 3 parameters you should pay attention to:<\/p>\n<ul><li>You will be using 2 AA batteries connected in series. This amounts to <strong>3.3V<\/strong>\u00a0more or less (depending on the batteries)<\/li>\n<li>The Arduino needs at least 2.9 Volts to perform correctly.<\/li>\n<li>The radio needs at least 1.9 Volts to communicate.<\/li>\n<\/ul><p>As you probably know, the voltage on a battery drops with its usage. This means that as soon as the voltage of the battery drops below 2.9v your node will be rendered useless.<\/p>\n<p>The solution to the problem above is called <em>Boost Converter<\/em>. A boost converter is a fancy name for a component that keeps the same output voltage regardless of the input. There is a minimum input voltage depending on the model that you are using, this one is 0.8v.<\/p>\n<p>Obviously, the booster doesn\u2019t do this for free, in order to step up the voltage, it has to step down the current.<\/p>\n<p>Adding a boost converter to the circuit will help to squeeze\u00a0all the juice out of your batteries, prolonging the life of your node.<\/p>\n<p>There is a caveat here, the boosters input noise into the circuit and the radio (NRF24L01) doesn\u2019t like that. For that reason, the radio needs to be powered directly from the battery.<\/p>\n<p>Don\u2019t worry about this, the PCB that we will use has this covered.<\/p>\n\n<h3><a href=\"https:\/\/amzn.to\/2KDt508\" target=\"_blank\" rel=\"noopener noreferrer\">Capacitors<\/a><\/h3>\n<p>We have two capacitors on the node that will carry out different tasks:<\/p>\n<ul><li><strong>4.7 <\/strong>uF: This one will be connected between the power supply and the radio (NRF24l01). It provides stability and avoids failure in the communications.<\/li>\n<li><strong>0.1 uF<\/strong>: This capacitor will have a similar function but for the voltage measurer. I will talk about this later.<\/li>\n<\/ul><h3><a href=\"https:\/\/amzn.to\/2ME3vZV\" target=\"_blank\" rel=\"noopener noreferrer\">Pinheaders\/Jumpers<\/a><\/h3>\n<p>Pinheaders and Jumpers are optional and I generally don\u2019t put them in. I like to solder the components to the PCB directly.<\/p><div class=\"code-block code-block-9\" style=\"margin: 8px 0; clear: both;\">\n<!-- Ezoic - ALL_CONTENT_BREAK_1 - mid_content -->\n<!-- placeholder 107 blocked. Reason : inactive -->\n<!-- End Ezoic - ALL_CONTENT_BREAK_1 - mid_content --><\/div>\n\n<p>If you are thinking of reusing the same node for something else in the future, you may consider adding them.<\/p>\n\n<h3><a href=\"https:\/\/amzn.to\/2tTld3J\" target=\"_blank\" rel=\"noopener noreferrer\">Screw terminal 5,08 spacing<\/a><\/h3>\n<p>They are optional but I like to use the screw terminals for the battery. In my experience, the power supply is less stable when I don\u2019t use them.<\/p>\n\n<h3><a href=\"https:\/\/amzn.to\/2KmvksP\" target=\"_blank\" rel=\"noopener noreferrer\">FTDI Programmer<\/a><\/h3>\n<p>The Arduino Pro Mini does not have a USB input which means that in order to program it, you need an FTDI programmer or another Arduino.<\/p>\n<p>I find the first option to be the easiest one.<\/p>\n\n<h3><a href=\"https:\/\/amzn.to\/2NbyEoo\" target=\"_blank\" rel=\"noopener noreferrer\">Battery Holder<\/a><\/h3>\n<p>This is just a piece of plastic to hold your 2AA batteries. You can get creative and build one yourself but honestly\u2026for what they cost, I would buy them.<\/p>\n\n<h3><a href=\"https:\/\/www.openhardware.io\/view\/4\/EasyNewbie-PCB-for-MySensors\" target=\"_blank\" rel=\"noopener noreferrer\">EasyPCB for MySensors<\/a><\/h3>\n<p>The EasyPCB has been one of my biggest discoveries lately. It is a PCB created by\u00a0<a href=\"https:\/\/www.openhardware.io\/user\/6\/projects\/sundberg84\">sundberg84<\/a>\u00a0that leverages the main functionalities described at the MySensors forum.<\/p>\n<p>It basically reduces the time to solder a node to a few minutes, leaving you with a quality sensor that doesn\u2019t look like a monstrosity surrounded by cables.<\/p>\n<p>Here is a video where Sunberg84 explains the features of the PCB.<\/p>\n\n<div class=\"oceanwp-oembed-wrap clr\"><iframe width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/pZTy71tRa1s?feature=oembed&amp;enablejsapi=1&amp;origin=https:\/\/www.smarthomeblog.net\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowful-lrtcreen=\"\">[embedded content]<\/iframe><\/div>\n\n<p>Sundberg releases new revisions of the PCB every now and then so when you receive them at home, the components might be arranged slightly differently.<\/p>\n\n<h3><a href=\"https:\/\/amzn.to\/2KyTuQO\" target=\"_blank\" rel=\"noopener noreferrer\">Door Sensors<\/a><\/h3>\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/Sin-t\u00edtulo-1.jpg\"><img class=\"aligncenter wp-image-897 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/Sin-t\u00edtulo-1.jpg\" alt=\"Arduino DIY Door Sensors: Door Sensor\" width=\"250\" height=\"276\"\/><\/a><\/p>\n<p>The reed switch is the bread and butter of the door sensors project. When you receive it at home, it will look like the picture above.<\/p>\n<p>They can come in two modes, <em>normally opened<\/em> and <em>normally closed,\u00a0<\/em>being <em>normally opened<\/em>\u00a0the most usual one.<a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/Sin-t\u00edtulo-1.jpg\"><br\/><\/a><\/p>\n\n<p>How do they work?<\/p>\n\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/magnetic_reed_switch_howitworks.png\"><img class=\"aligncenter wp-image-898 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/magnetic_reed_switch_howitworks.png\" alt=\"Arduino DIY Door Sensors: Reed Switch\" width=\"665\" height=\"374\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/magnetic_reed_switch_howitworks.png 665w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/magnetic_reed_switch_howitworks-300x169.png 300w\" sizes=\"(max-width: 665px) 100vw, 665px\"\/><\/a><\/p>\n\n<p>I have borrowed this image from <a href=\"https:\/\/randomnerdtutorials.com\">RandomNerdTutorials,<\/a>\u00a0great site in case you didn\u2019t know about it.<\/p>\n<p>As you can see, the door sensor has two terminals, these two terminals will be disconnected (switch opened) when there isn\u2019t a magnet closed to the switch. At the moment you approach the magnet to the switch, it closes connecting the two terminals together.<\/p>\n<p>How can the microcontroller (Arduino) leverage this?<\/p>\n<p>Very simple, you will be connecting one of the terminals to a digital input and the other one to VCC or GND.<\/p>\n<p>When the door\/window is closed, the switch and the magnet are together closing the switch and communicating the two terminals.<\/p><div class=\"code-block code-block-10\" style=\"margin: 8px 0; clear: both;\">\n<!-- Ezoic - DESKTOP_CONTENT_BREAK_2 - mid_content -->\n\n<!-- End Ezoic - DESKTOP_CONTENT_BREAK_2 - mid_content --><\/div>\n\n<p>This will connect our digital input to GND or VCC, depending how you wired things up. When the situation changes, your node will send a message to the microcontroller to notify that the door is opened.<\/p>\n<p>If you haven\u2019t used door sensors before, I would suggest you play around with it first.<\/p>\n\n<h3>Wire Things Up<\/h3>\n<p>There are many ways you can connect the Door Sensor but my recommendation is to connect it according to the following diagram.<\/p>\n\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/DoorSensorSchema.jpg\"><img class=\"aligncenter wp-image-902 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/DoorSensorSchema.jpg\" alt=\"Arduino DIY Door Sensors: Door Sensor Connection Diagram\" width=\"351\" height=\"474\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/DoorSensorSchema.jpg 351w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/DoorSensorSchema-222x300.jpg 222w\" sizes=\"(max-width: 351px) 100vw, 351px\"\/><\/a><\/p>\n\n<p>You might be wondering why there is a resistor between D3 and the Arduino VCC output. It is called pull-up resistor and it is intended to provide a default value to the D3 input.<\/p>\n<p>This means that when the switch is opened (your door or window is opened) the default value will be HIGH since we have a pull-up resistor connected to D3. On the contrary, when you close the door, the reed switch will close pushing the LOW status to D3.<\/p>\n<p>Is the resistor mandatory? Not really\u2026<\/p>\n<p>Arduino has an internal pull-up resistor that you can use to set the default value to HIGH, however, this resistor has a value of 20K and the one in the diagram above has a value of 1M.<\/p>\n<p>Why do you care about that?<\/p>\n<p>Mr. Ohm can shed some light on this\u2026<\/p>\n<p>As you know,\u00a0 I = V\/R<\/p>\n<p>20K Resistor:<\/p>\n<p>I = 3.3v\/20000\u03a9\u00a0 =\u00a00.000165 A = 165\u00a0uA<\/p>\n<p>1M Resistor:<\/p>\n<p>I = 3.3v\/1000000\u03a9\u00a0 = 0.0000033 A = 3.3 uA<\/p>\n<p>If we used the pull-up resistor included in the Arduino board the node would draw more current than it should.<\/p>\n<p>Don\u2019t worry too much about this, the EasyPCB already has a placeholder for this resistor.<\/p>\n\n<h2>Battery Measurer<\/h2>\n<p>This is, in my opinion, the cooler part of the project. I am talking about the functionality that will report the status of the battery to your Home Automation Controller. This capability makes the sensor more reliable knowing that you will be notified when the battery is about to expire.<\/p>\n<p>The EasyPCB already has all the placeholders to easily build this functionality but if you want to know more about it I strongly recommend you to visit\u00a0 <a href=\"https:\/\/www.mysensors.org\/build\/battery\" target=\"_blank\" rel=\"noopener noreferrer\">Battery Powered Sensors<\/a>\u00a0at the MySensors forum.<\/p>\n\n<h2>DIY Arduino Door Sensors:\u00a0 Soldering the PCB<\/h2>\n<p>Less talking and more building\u2026It is time to start soldering the board.<\/p>\n<p>In order to give you an idea of how things are going to look, here is a picture of the before and after soldering process.<\/p>\n\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/BeforeAfterComprimida.jpg\"><img class=\"aligncenter wp-image-943 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/BeforeAfterComprimida.jpg\" alt=\"Arduino DIY Door Sensors: Before and After PCB\" width=\"720\" height=\"422\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/BeforeAfterComprimida.jpg 720w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/BeforeAfterComprimida-300x176.jpg 300w\" sizes=\"(max-width: 720px) 100vw, 720px\"\/><\/a><\/p>\n<div class=\"code-block code-block-11\" style=\"margin: 8px 0; clear: both;\">\n<!-- Ezoic - DESKTOP_CONTENT_BREAK_3 - mid_content -->\n\n<!-- End Ezoic - DESKTOP_CONTENT_BREAK_3 - mid_content --><\/div>\n\n<p>You only need to solder the components in the picture above and they are all labeled on the EasyPCB, having said that, I think it is worth sharing a few tips to help you throughout the process.<\/p>\n<ol><li>If your Arduino came without the pinheads soldered to the board (which is usually the case) solder the pinheads of the FTDI Connector pointing to the reset button, it will help you fit things better on the PCB. If you forget to do this, you can bend them backward afterward.<\/li>\n<li>You need to connect the two terminals where it says BAT. You can either use a jumper or just solder them together. I generally solder them since I always power my nodes using 2 AA batteries and the radio works perfectly with it.<\/li>\n<li>If you are using the 5V version of the Arduino Pro Mini you would need to solder the other jumper (REG) and use a voltage regulator. For this tutorial is best to use the Arduino 3.3v<\/li>\n<li>I follow a particular soldering the components, this is not mandatory but I think it makes the process quicker and easier.\n<ol><li>Solder the two terminals of the BAT jumper.<\/li>\n<li>Add the resistors into the through-hole placeholders.<\/li>\n<li>Place the Arduino and the radio on the PCB.<\/li>\n<li>Add the capacitors, the screw terminal and the booster.<\/li>\n<\/ol><\/li>\n<li>Remeber that the capacitors that you are using for this tutorial have polarity. This means that every leg has its place.\u00a0 The negative leg is the one with the stripe (usually white) on the body of the capacitor. You will see that the PCB is labeled with a <em>g<\/em>\u00a0on the negatieve side.<\/li>\n<li>The reed switch, as I explained to you before, should go between D3 and GND.\u00a0 You can use pinheads or solder the cables directly to the PCB, I generally act based on my level of laziness that day\u2026<\/li>\n<\/ol><p>And here it is!! the DIY Door Sensor!<\/p>\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/IMG_20180701_17110823194-Comprimida.jpg\"><img class=\"aligncenter wp-image-945 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/IMG_20180701_17110823194-Comprimida.jpg\" alt=\"Arduino DIY Door Sensors: Door Sensor Finished\" width=\"720\" height=\"540\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/IMG_20180701_17110823194-Comprimida.jpg 720w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/IMG_20180701_17110823194-Comprimida-300x225.jpg 300w\" sizes=\"(max-width: 720px) 100vw, 720px\"\/><\/a><\/p>\n\n\n<h2>DIY Arduino Door Sensor:\u00a0 The Enclosure<\/h2>\n<p>Having nice enclosures is part of the beautification process so I have designed an enclosure that you can use to put your sensor in.<\/p>\n<p>Here you have a link to <a href=\"https:\/\/www.thingiverse.com\/thing:2989101\" target=\"_blank\" rel=\"noopener noreferrer\">Thingiverse<\/a> in case you want to get it printed.<\/p>\n<p>There is space to put the reed switch inside of the enclosure or pass the cables through a hole.<\/p>\n\n\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/SensorEnclosure.jpg\"><img class=\"aligncenter wp-image-918 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/SensorEnclosure.jpg\" alt=\"Arduino DIY Door Sensors: Enclosure\" width=\"650\" height=\"345\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/SensorEnclosure.jpg 650w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/06\/SensorEnclosure-300x159.jpg 300w\" sizes=\"(max-width: 650px) 100vw, 650px\"\/><\/a><\/p>\n<h2\/>\n<h2\/>\n<h2>DIY Door Sensor:\u00a0 The Code for Arduino<\/h2>\n<p>I will walk you through the relevant parts of the code but you will be able to find the full version in the <a href=\"https:\/\/github.com\/smarthomeblog\/MySensors\/blob\/master\/BatteryDoorSensor.ino\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub Repository<\/a>.<\/p>\n<!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642c1650286559\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">#define MY_DEBUG\n#define MY_RADIO_NRF24\n\n#define DOOR_SENSOR_PIN 3\n#define MY_NODE_ID 5\n#define CHILD_ID_DOOR 1\n#define CHILD_ID_VOLTAGE 2<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642c1650286559-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642c1650286559-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642c1650286559-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642c1650286559-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642c1650286559-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642c1650286559-6\">6<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642c1650286559-7\">7<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642c1650286559-1\">#define MY_DEBUG<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642c1650286559-2\">#define MY_RADIO_NRF24<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642c1650286559-3\">\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642c1650286559-4\">#define DOOR_SENSOR_PIN 3<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642c1650286559-5\">#define MY_NODE_ID 5<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642c1650286559-6\">#define CHILD_ID_DOOR 1<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642c1650286559-7\">#define CHILD_ID_VOLTAGE 2<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0010 seconds] -->\n<p>The main things you need to pay attention to here are:<\/p>\n<ul><li>DOOR_SENSOR_PIN tells Arduino where you have connected the door sensor. If you followed the diagram it will be 3.<\/li>\n<li>MY_NODE_ID: This identifies your node in the network of sensors. It should be unique for every node (sensor) that you have.<\/li>\n<li>CHILD_ID_DOOR and CHILD_ID_VOLTAGE identify sensors within the node. This will make more sense once we create the items in OpenHab.<\/li>\n<\/ul><p\/><!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642d2916658348\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">static const uint64_t UPDATE_INTERVAL = 1800000;\nint oldBatteryPcnt = 0;\nint oldValue = 0;\nfloat VBAT_PER_BITS = 0.0032551319648094;\nfloat VMIN = 1.9;\nfloat VMAX = 3.24;<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d2916658348-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d2916658348-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d2916658348-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d2916658348-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d2916658348-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d2916658348-6\">6<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d2916658348-1\">static const uint64_t UPDATE_INTERVAL = 1800000;<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d2916658348-2\">int oldBatteryPcnt = 0;<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d2916658348-3\">int oldValue = 0;<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d2916658348-4\">float VBAT_PER_BITS = 0.0032551319648094;<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d2916658348-5\">float VMIN = 1.9;<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d2916658348-6\">float VMAX = 3.24;<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0004 seconds] -->\n<p\/>\n<ul><li>VMIN and VMAX are parameters to calculate the percentage of the battery. I set VMIN as 1.9v since it is the lowest voltage that the radio can deal with. VMAX is the voltage that the 2AA batteries in series will normally have out of the box.<\/li>\n<li>I am measuring the battery using one of the analog inputs (A0) and the possible values will go from 0 to 1023. In order to transform that number (0-1023) into a voltage, we use the\u00a0\u00a0VBAT_PER_BITS which is basically 3.33v\/1024.<\/li>\n<\/ul><p\/><!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642d6693200873\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">MyMessage msgDoor(CHILD_ID_DOOR,V_TRIPPED);\nMyMessage msgVBat(CHILD_ID_VOLTAGE,V_CUSTOM);\n\n\nvoid presentation() \n{\npresent(CHILD_ID_DOOR, S_DOOR);\n}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d6693200873-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d6693200873-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d6693200873-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d6693200873-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d6693200873-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d6693200873-6\">6<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642d6693200873-7\">7<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642d6693200873-8\">8<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d6693200873-1\">MyMessage msgDoor(CHILD_ID_DOOR,V_TRIPPED);<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d6693200873-2\">MyMessage msgVBat(CHILD_ID_VOLTAGE,V_CUSTOM);<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d6693200873-3\">\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d6693200873-4\">\u00a0<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d6693200873-5\">void presentation()\u00a0\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d6693200873-6\">{<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642d6693200873-7\">present(CHILD_ID_DOOR, S_DOOR);<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642d6693200873-8\">}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0003 seconds] -->\n<p>This section declares the MySensors Messages and presents them to the gateway.<\/p>\n<!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642da491714531\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">void setup()\n{\n\n\/\/ use the 1.1 V internal reference\n#if defined(__AVR_ATmega2560__)\n analogReference(INTERNAL1V1);\n#else\n analogReference(INTERNAL);\n#endif\n \npinMode(DOOR_SENSOR_PIN,INPUT);\n}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642da491714531-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642da491714531-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642da491714531-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642da491714531-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642da491714531-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642da491714531-6\">6<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642da491714531-7\">7<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642da491714531-8\">8<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642da491714531-9\">9<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642da491714531-10\">10<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642da491714531-11\">11<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642da491714531-12\">12<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642da491714531-1\">void setup()<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642da491714531-2\">{<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642da491714531-3\">\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642da491714531-4\">\/\/ use the 1.1 V internal reference<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642da491714531-5\">#if defined(__AVR_ATmega2560__)<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642da491714531-6\">\u00a0\u00a0\u00a0\u00a0analogReference(INTERNAL1V1);<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642da491714531-7\">#else<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642da491714531-8\">\u00a0\u00a0\u00a0\u00a0analogReference(INTERNAL);<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642da491714531-9\">#endif<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642da491714531-10\">\u00a0\u00a0<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642da491714531-11\">pinMode(DOOR_SENSOR_PIN,INPUT);<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642da491714531-12\">}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0002 seconds] -->\n<p>Define the INTERNAL analog reference.<\/p>\n<p>You wil use this for the voltage measurer.<\/p>\n<!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642dc696440971\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">void getBatteryLevel()\n{\n \/\/ Battery monitoring reading\n int sensorValue = analogRead(BATTERY_SENSE_PIN);\n delay(500);\n\n \/\/ Calculate the battery in %\n float Vbat = sensorValue * VBAT_PER_BITS;\n send(msgVBat.set(Vbat, 3));\n int batteryPcnt = static_cast&lt;int&gt;(((Vbat - VMIN) \/ (VMAX - VMIN))*100.);\n \n if (batteryPcnt &gt; 100) {\n batteryPcnt = 100;\n }\n \n sendBatteryLevel(batteryPcnt);\n}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-6\">6<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-7\">7<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-8\">8<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-9\">9<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-10\">10<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-11\">11<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-12\">12<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-13\">13<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-14\">14<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-15\">15<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642dc696440971-16\">16<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642dc696440971-17\">17<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-1\">void getBatteryLevel()<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-2\">{<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-3\">\u00a0\u00a0\/\/ Battery monitoring reading<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-4\">\u00a0\u00a0int sensorValue = analogRead(BATTERY_SENSE_PIN);<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-5\">\u00a0\u00a0delay(500);<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-6\">\u00a0<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-7\">\u00a0\u00a0\/\/ Calculate the battery in %<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-8\">\u00a0\u00a0float Vbat = sensorValue * VBAT_PER_BITS;<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-9\">\u00a0\u00a0send(msgVBat.set(Vbat, 3));<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-10\">\u00a0\u00a0int batteryPcnt = static_cast&lt;int&gt;(((Vbat - VMIN) \/ (VMAX - VMIN))*100.);<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-11\">\u00a0\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-12\">\u00a0\u00a0\u00a0\u00a0if (batteryPcnt &gt; 100) {<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-13\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0batteryPcnt = 100;<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-14\">\u00a0\u00a0\u00a0\u00a0}<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-15\">\u00a0\u00a0\u00a0\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642dc696440971-16\">\u00a0\u00a0\u00a0\u00a0sendBatteryLevel(batteryPcnt);<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642dc696440971-17\">}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0008 seconds] -->\n<p>This function calculates the battery level and sends it to the controller.<\/p>\n<!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642df174973950\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">void motion_on()\n{\n \n bool tripped = digitalRead(DOOR_SENSOR_PIN) == LOW;\n send(msgDoor.set(tripped?\"0\":\"1\")); \/\/ Send tripped value to gw\n}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642df174973950-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642df174973950-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642df174973950-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642df174973950-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642df174973950-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642df174973950-6\">6<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642df174973950-1\">void motion_on()<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642df174973950-2\">{<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642df174973950-3\">\u00a0\u00a0 <\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642df174973950-4\">\u00a0\u00a0 bool tripped = digitalRead(DOOR_SENSOR_PIN) == LOW;<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642df174973950-5\">\u00a0\u00a0 send(msgDoor.set(tripped?\"0\":\"1\"));\u00a0\u00a0\/\/ Send tripped value to gw<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642df174973950-6\">}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0003 seconds] -->\n<p>The function motion_on() reads the value from the door sensor and sends it to the home automation controller, in my case OpenHab.<\/p>\n<!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642e1258466607\" class=\"crayon-syntax crayon-theme-arduino-ide crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div>Arduino<\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">void loop() \n{ \n sleep(digitalPinToInterrupt(DOOR_SENSOR_PIN),CHANGE, UPDATE_INTERVAL);\n motion_on();\n getBatteryLevel();\n}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e1258466607-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e1258466607-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e1258466607-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e1258466607-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e1258466607-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e1258466607-6\">6<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e1258466607-1\">void loop()\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e1258466607-2\">{\u00a0\u00a0\u00a0\u00a0<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e1258466607-3\">\u00a0\u00a0\u00a0\u00a0sleep(digitalPinToInterrupt(DOOR_SENSOR_PIN),CHANGE, UPDATE_INTERVAL);<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e1258466607-4\">\u00a0\u00a0\u00a0\u00a0motion_on();<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e1258466607-5\">\u00a0\u00a0\u00a0\u00a0getBatteryLevel();<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e1258466607-6\">}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0003 seconds] -->\n<p>the main thing you need to pay attention to here is the function <em>sleep.\u00a0<\/em>It tells Arduino to sleep all the time and only wake up under two circumstances:<\/p>\n<ul><li>Every X amount of milliseconds specified by the variable\u00a0UPDATE_INTERVAL. In my case, it is 2 hrs.<\/li>\n<li>Every time that there is an interruption coming from the DOOR_SENSOR_PIN.<\/li>\n<\/ul><p>This basically means that your node will be sleeping all the time and will only wake up every two hours or when your window opens or closes.<\/p>\n<div class=\"code-block code-block-12\" style=\"margin: 8px 0; clear: both;\">\n<!-- Ezoic - DESKTOP_CONTENT_BREAK_4 - mid_content -->\n\n<!-- End Ezoic - DESKTOP_CONTENT_BREAK_4 - mid_content --><\/div>\n\n<h2>Testing your brand new Door Sensor<\/h2>\n<p>At this point, your door sensors should be up and running but how do you know everything worked?<\/p>\n<p>I like to use a tool called <a href=\"http:\/\/mqttfx.jensd.de\/\" target=\"_blank\" rel=\"noopener noreferrer\">MQTT.fx<\/a>, it is a simple free tool to monitor your MQTT network.<\/p>\n<p>Just subscribe to the topic\u00a0mygateway1-out\/MY_NODE_ID\/#<\/p>\n<p>Remember to replace\u00a0MY_NODE_ID by the number you used in your Arduino sketch.<\/p>\n\n<figure id=\"attachment_948\" aria-describedby=\"caption-attachment-948\" style=\"width: 720px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/MQTTFx.jpg\"><img class=\"wp-image-948 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/MQTTFx.jpg\" alt=\"Arduino DIY Door Sensors: MQTT FX\" width=\"720\" height=\"365\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/MQTTFx.jpg 720w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/MQTTFx-300x152.jpg 300w\" sizes=\"(max-width: 720px) 100vw, 720px\"\/><\/a><figcaption id=\"caption-attachment-948\" class=\"wp-caption-text\">LEAD Technologies Inc. V1.01<\/figcaption><\/figure><h3\/>\n<p>If you see messages showing up in MQTT.Fx you can consider the experiment a success \ud83d\ude42<\/p>\n\n<h2>Adding the Door Sensors to your Home Automation Controller<\/h2>\n<p>The sensor that you just built will be compatible with any Home Automation controller that supports MQTT, which is pretty much all of them out there\u2026<\/p>\n<p>I am going to give the example for OpenHab which is the controller that I use.<\/p>\n<h3>Items File<\/h3>\n<p>You should already be familiar with this part from the <a href=\"https:\/\/www.smarthomeblog.net\/mqtt-openhab\/\" target=\"_blank\" rel=\"noopener noreferrer\">MQTT Tutorial<\/a>\u00a0that I wrote a few months ago but here you have some details on how to add these particular door sensors to your current OpenHab implementation.<\/p>\n<p>Remember to replace the NODE ID and the SENSOR ID used in the items below, using the ones in your Arduino sketch.<\/p><!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642e4686832255\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div><\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">Contact mqtt_terrace_contact \t\t {mqtt=\"&lt;[mosquitto:mygateway1-out\/5\/1\/1\/0\/16:state:OPEN:1],&lt;[mosquitto:mygateway1-out\/5\/1\/1\/0\/16:state:CLOSED:0]\"} \nNumber mqtt_terrace_voltage \"Terrace Voltage [%.2f] V\" {mqtt=\"&lt;[mosquitto:mygateway1-out\/5\/2\/1\/0\/48:state:default]\"}\nNumber mqtt_terrace_battery \"Terrace Battery [%.0f] %\" {mqtt=\"&lt;[mosquitto:mygateway1-out\/5\/255\/3\/0\/0:state:default]\"}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e4686832255-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e4686832255-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e4686832255-3\">3<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e4686832255-1\">Contact mqtt_terrace_contact\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \t\t\u00a0\u00a0 {mqtt=\"&lt;[mosquitto:mygateway1-out\/5\/1\/1\/0\/16:state:OPEN:1],&lt;[mosquitto:mygateway1-out\/5\/1\/1\/0\/16:state:CLOSED:0]\"}\u00a0\u00a0<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e4686832255-2\">Number\u00a0\u00a0mqtt_terrace_voltage\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Terrace Voltage [%.2f] V\"\u00a0\u00a0 {mqtt=\"&lt;[mosquitto:mygateway1-out\/5\/2\/1\/0\/48:state:default]\"}<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e4686832255-3\">Number\u00a0\u00a0mqtt_terrace_battery\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"Terrace Battery [%.0f] %\"\u00a0\u00a0 {mqtt=\"&lt;[mosquitto:mygateway1-out\/5\/255\/3\/0\/0:state:default]\"}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0006 seconds] -->\n<p\/>\n<h3\/>\n<h3>Sitemap<\/h3>\n<p>If you would also like to add your items to your sitemap, check this example below, it can give you an idea.<\/p>\n<!-- Crayon Syntax Highlighter v_2.7.2_beta -->\n\n\t\t<div id=\"crayon-5d72f6ff642e9642220346\" class=\"crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate\" data-settings=\" minimize scroll-mouseover\" style=\" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;\">\n\t\t\n\t\t\t<div class=\"crayon-toolbar\" data-settings=\" mouseover overlay hide delay\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\">\n\t\t\t<div class=\"crayon-tools\" style=\"font-size: 12px !important;height: 18px !important; line-height: 18px !important;\"><div class=\"crayon-button crayon-nums-button\" title=\"Toggle Line Numbers\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-plain-button\" title=\"Toggle Plain Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-wrap-button\" title=\"Toggle Line Wrap\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-expand-button\" title=\"Expand Code\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-copy-button\" title=\"Copy\"><div class=\"crayon-button-icon\"\/><\/div><div class=\"crayon-button crayon-popup-button\" title=\"Open Code In New Window\"><div class=\"crayon-button-icon\"\/><\/div><\/div><\/div>\n\t\t\t<div class=\"crayon-info\" style=\"min-height: 16.8px !important; line-height: 16.8px !important;\"\/>\n\t\t\t<div class=\"crayon-plain-wrap\"><textarea wrap=\"soft\" class=\"crayon-plain print-no\" data-settings=\"dblclick\" readonly=\"\" style=\"-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;\">\t\tText label=\"Security\" icon=\"camera\"\n\t\t\t{\n\t\t\tText item=mqtt_entrance_door icon=\"frontdoor\" label=\"Entrance\"\n\t\t\tText item=mqtt_terrace_contact icon=\"frontdoor\" label=\"Terrace\"\n\t\t\t}\n\n\t\tText label=\"Battery\" icon=\"battery\"\n\t\t\t{\n\t\t\tText item=mqtt_terrace_battery icon=\"battery\" label=\"Battery [%.0f]\"\n\t\t\tText item=mqtt_terrace_voltage icon=\"energy\" label=\"Voltage [%.2f]\"\n\t\t\t}<\/textarea><\/div>\n\t\t\t<div class=\"crayon-main\" style=\"\">\n\t\t\t\t<table class=\"crayon-table\"><tbody><tr class=\"crayon-row\"><td class=\"crayon-nums \" data-settings=\"show\">\n\t\t\t\t\t<div class=\"crayon-nums-content\" style=\"font-size: 12px !important; line-height: 15px !important;\"><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e9642220346-1\">1<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e9642220346-2\">2<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e9642220346-3\">3<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e9642220346-4\">4<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e9642220346-5\">5<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e9642220346-6\">6<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e9642220346-7\">7<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e9642220346-8\">8<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e9642220346-9\">9<\/div><div class=\"crayon-num crayon-striped-num\" data-line=\"crayon-5d72f6ff642e9642220346-10\">10<\/div><div class=\"crayon-num\" data-line=\"crayon-5d72f6ff642e9642220346-11\">11<\/div><\/div>\n\t\t\t\t<\/td>\n\t\t\t\t\t\t<td class=\"crayon-code\"><div class=\"crayon-pre\" style=\"font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;\"><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e9642220346-1\">\t\tText label=\"Security\"\u00a0\u00a0icon=\"camera\"<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e9642220346-2\">\t\t\t{<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e9642220346-3\">\t\t\tText\u00a0\u00a0 item=mqtt_entrance_door icon=\"frontdoor\" label=\"Entrance\"<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e9642220346-4\">\t\t\tText\u00a0\u00a0 item=mqtt_terrace_contact icon=\"frontdoor\" label=\"Terrace\"<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e9642220346-5\">\t\t\t}<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e9642220346-6\">\u00a0<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e9642220346-7\">\t\tText label=\"Battery\"\u00a0\u00a0icon=\"battery\"<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e9642220346-8\">\t\t\t{<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e9642220346-9\">\t\t\tText item=mqtt_terrace_battery icon=\"battery\" label=\"Battery [%.0f]\"<\/div><div class=\"crayon-line crayon-striped-line\" id=\"crayon-5d72f6ff642e9642220346-10\">\t\t\tText item=mqtt_terrace_voltage icon=\"energy\" label=\"Voltage [%.2f]\"<\/div><div class=\"crayon-line\" id=\"crayon-5d72f6ff642e9642220346-11\">\t\t\t}<\/div><\/div><\/td>\n\t\t\t\t\t<\/tr><\/tbody><\/table><\/div>\n\t\t<\/div>\n<!-- [Format Time: 0.0003 seconds] -->\n\n<p>Once you have it configured it will look similar to the screenshot below.<\/p>\n<p><a href=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/2018-07-02_22-27-13.jpg\"><img class=\"aligncenter wp-image-949 size-full\" src=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/2018-07-02_22-27-13.jpg\" alt=\"Arduino DIY Door Sensors: OpenHab Sitemap\" width=\"445\" height=\"246\" srcset=\"https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/2018-07-02_22-27-13.jpg 445w, https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/2018-07-02_22-27-13-300x166.jpg 300w\" sizes=\"(max-width: 445px) 100vw, 445px\"\/><\/a><\/p>\n<p>I hope you have enjoyed this tutorial on how to build DIY Door Sensors.<\/p>\n<p>If you have questions on the post let me know in the comments. Also, if you think your friends might like this share it, please! It helps to get the word out there.<\/p>\n\n<h2>Additional Resources<\/h2>\n<p>Here you have a few additional resources that might help you with the content of the blog post.<\/p>\n<p>The first resource is the<a href=\"https:\/\/www.mysensors.org\/\" target=\"_blank\" rel=\"noopener noreferrer\"> MySensors<\/a> website. I always go there when I am looking for inspiration \ud83d\ude42<\/p>\n<p>If you have started with the tutorial and you want to know how to remove the voltage regulator and the led from the Arduino board here is a neat video to do just that.<\/p>\n\n<p class=\"responsive-video-wrap clr\"><iframe width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/7qujkC72dYs?feature=oembed&amp;enablejsapi=1&amp;origin=https:\/\/www.smarthomeblog.net\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowful-lrtcreen=\"\">[embedded content]<\/iframe><\/p>\n\n<p>Lastly, for newbies to the Arduino Pro Mini, here there is a video on how to solder the pins to the board.<\/p>\n\n<p class=\"responsive-video-wrap clr\"><iframe width=\"1200\" height=\"675\" src=\"https:\/\/www.youtube.com\/embed\/37mW1i_oEpA?feature=oembed&amp;enablejsapi=1&amp;origin=https:\/\/www.smarthomeblog.net\" frameborder=\"0\" allow=\"autoplay; encrypted-media\" allowful-lrtcreen=\"\">[embedded content]<\/iframe><\/p>\n<div class=\"code-block code-block-1\" style=\"margin: 8px 0; clear: both;\">\n<div id=\"amzn-assoc-ad-9fa2887d-d2c0-429f-b2ed-f9d1fdfc8bf7\"\/><\/div>\n<div class=\"code-block code-block-13\" style=\"margin: 8px 0; clear: both;\">\n<!-- Ezoic - DESKTOP_AFTER_CONTENT - bottom_of_page -->\n<a href=\"https:\/\/www.ezoic.com\/what-is-ezoic\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\" style=\"cursor:pointer\"\/><img src=\"https:\/\/go.ezoic.net\/utilcave_com\/img\/ezoic.png\" style=\"height:12px !important; padding:2px !important; border:0px !important; cursor:pointer !important; width: 58px !important; margin:0 !important; box-sizing: content-box !important;\"\/>report this ad\n<!-- End Ezoic - DESKTOP_AFTER_CONTENT - bottom_of_page --><\/div>", "2019-09-20 18:30:00", "2019-09-20 18:30:00", "text\/html", "en-US", 17, "www.smarthomeblog.net", "https:\/\/www.smarthomeblog.net\/wp-content\/uploads\/2018\/07\/DIY-Door-Sensor.jpg", null, 200, 2]: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF0\x9F\x99\x82</...' for column 'content' at row 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement