{"id":1218,"date":"2020-12-02T21:18:07","date_gmt":"2020-12-02T21:18:07","guid":{"rendered":"http:\/\/mattzobricks.com\/?page_id=1218"},"modified":"2026-03-23T20:41:45","modified_gmt":"2026-03-23T19:41:45","slug":"mattzosensorcontroller","status":"publish","type":"page","link":"https:\/\/mattzobricks.com\/de\/automation\/mattzolayoutcontroller\/mattzosensorcontroller","title":{"rendered":"MattzoLayoutController with Sensors"},"content":{"rendered":"\n<p>Please read the <a href=\"https:\/\/mattzobricks.com\/controllers\/general\" type=\"page\" id=\"1213\">general section<\/a> first!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2024\/04\/Sensor-build-1024x768.jpg\" alt=\"Reed sensor for LEGO trains\" class=\"wp-image-6920\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2024\/04\/Sensor-build-1024x768.jpg 1024w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2024\/04\/Sensor-build-300x225.jpg 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2024\/04\/Sensor-build-768x576.jpg 768w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2024\/04\/Sensor-build-1536x1152.jpg 1536w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2024\/04\/Sensor-build-2048x1536.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Reed sensor for LEGO trains<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Purpose<\/h2>\n\n\n\n<p>The MattzoLayoutController is designed to receive input signals from digital sensors like reed switches and pass the information on to the Rocrail via the MQTT broker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Functional Description<\/h2>\n\n\n\n<p>The MattzoLayoutController connects to MQTT as described in the &#8220;General&#8221; section.<\/p>\n\n\n\n<p>When a connected sensor has contact with a vehicle, the controller instantly sends a sensor event to the MQTT broker.<\/p>\n\n\n\n<p>When a sensor looses contact for more than 0,1 seconds (configurable), the controller sends the &#8220;sensor disconnected&#8221; event to the MQTT broker.<\/p>\n\n\n\n<p>Up to nine reed sensors (or other digital sensors) can be connected directly to the controller. With port extenders, even hundreds of sensors can be connected to the controller.<\/p>\n\n\n\n<p>For more information about reed sensors refer to the <a href=\"http:\/\/mattzobricks.com\/automation\/sensors\" data-type=\"page\" data-id=\"69\">sensor section<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wiring<\/h2>\n\n\n\n<p>The following wiring diagrams shows two options to attach sensors to the controller.<\/p>\n\n\n\n<p>The first diagram shows an example wiring of eight sensors and a status LED:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1007\" height=\"916\" src=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-8-sensors-and-status-LED-0.5.png\" alt=\"Wiring Diagram MLC with 8 sensors and status LED\" class=\"wp-image-4194\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-8-sensors-and-status-LED-0.5.png 1007w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-8-sensors-and-status-LED-0.5-300x273.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-8-sensors-and-status-LED-0.5-768x699.png 768w\" sizes=\"auto, (max-width: 1007px) 100vw, 1007px\" \/><figcaption class=\"wp-element-caption\">Wiring Diagram MLC with 8 sensors and status LED<\/figcaption><\/figure>\n\n\n\n<p>The status LED indicates to WiFi connection status, the MQTT connection status and lights up when one or more sensors are triggered. The status LED is very handy in practice. Therefore, this wiring option is <strong>recommended<\/strong>.<\/p>\n\n\n\n<p>The next diagram displays the option of the MattzoSensorController with 9 sensors and no status LED.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1011\" height=\"919\" src=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-9-sensors-0.5_Steckplatine.png\" alt=\"Wiring Diagram MLC with 9 sensors\" class=\"wp-image-4196\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-9-sensors-0.5_Steckplatine.png 1011w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-9-sensors-0.5_Steckplatine-300x273.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2021\/12\/Wiring-Diagram-MLC-with-9-sensors-0.5_Steckplatine-768x698.png 768w\" sizes=\"auto, (max-width: 1011px) 100vw, 1011px\" \/><figcaption class=\"wp-element-caption\">Wiring Diagram MLC with 9 sensors<\/figcaption><\/figure>\n\n\n\n<p>Instead of using pin D0 for the status LED, it is used for connecting a 9th reed sensor. The option should only be used if you want to connect all of the nine connectible sensors to the controller. As the ESP-8266 has no internal pull-up resistors for pin D0, a strong resistor (10 or 100 kOhm) is required to pull up the port when the reed sensor is released. All other ports are pulled up internally by the MattzoController-Firmware.<\/p>\n\n\n\n<p>Please note for both options, that the reed sensor on pin D8 must be connected to 3V3, not to GND on the other end. This is because D8 is actually pulled down, not pulled up.<\/p>\n\n\n\n<p>One more thing: it is important to understand, that pins D3 and D4 must not be pulled down when you power the controller up, and that pin D8 must not be pulled up during boot. If you do that, the controller will not boot. That means, that the controller can not be successfully powered on when a train is on the sensors. The solution is easy: move the train a little bit away and reboot the controller. Or, even better, do not use D3, D4 and D8 for sensors if you don&#8217;t have to.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Required Components<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>I\/O board with micro controller. We have used a NodeMCU Amica Modul V2 ESP8266 ESP-12F. Similar modules should work as well.<\/li>\n\n\n\n<li>Up to 9 reed sensors (details: see <a href=\"http:\/\/mattzobricks.com\/automation\/sensors\">sensor<\/a> page).<\/li>\n\n\n\n<li>A pull-up resistor (10, 47 or 100 k\u03a9) for pin D0 (if sensor is installed on this pin).<\/li>\n\n\n\n<li>A LED (if status LED is installed). Make sure that the LED cope with the power supply. Depending on the type of LED, they each might need one additional resistor wired in series.<\/li>\n\n\n\n<li>Basic stuff like bread board, wires etc.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Power Supply<\/h2>\n\n\n\n<p>The controller can be powered up with a simple USB charger over USB or some other power supply of similar voltage that is connected to the VIN and GND pins of the controller.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Firmware Configuration<\/h2>\n\n\n\n<p>Please read the&nbsp;<a href=\"https:\/\/mattzobricks.com\/controllers\/mattzolayoutcontroller\">MLC general page<\/a>&nbsp;first.<\/p>\n\n\n\n<p>To configure the firmware configuration, you need to edit the controller configuration file (controller_config.h).<\/p>\n\n\n\n<p>In this file, the following sections are relevant:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SERVO WIRING CONFIGURATION<\/li>\n<\/ul>\n\n\n\n<p>The section is clearly marked in the standard configuration file, and the different parameters are explained with code comments, so you shouldn\u2019t have too many problems to understand what you need to do.<\/p>\n\n\n\n<p>For a start, you should set the pinType to LOCAL_SENSOR_PIN_TYPE, as this is the setting for normal, local sensors. For an explanation of the other sensor types, please refer to the <a href=\"https:\/\/mattzobricks.com\/automation\/sensors\" data-type=\"page\" data-id=\"69\">Sensors<\/a> page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Rocrail Setup<\/h2>\n\n\n\n<p>For general setup instructions please refer to the &#8220;General&#8221; section.<\/p>\n\n\n\n<p>To setup the sensor in Rocrail, navigate to the interface tab of the sensor definition. The MattzoControllerID must be used as &#8220;Bus&#8221; parameter, and the port of the sensor as &#8220;Address&#8221;.<\/p>\n\n\n\n<p>The first port has the number &#8220;1&#8221; (not &#8220;0&#8221;).<\/p>\n\n\n\n<p>For using the sensor as a wheel counter see next section.<\/p>\n\n\n\n<p>ALL OTHER INFORMATION ON THIS PAGE CAN BE NEGLECTED AND HAS NO MEANING!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"891\" height=\"722\" src=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/05\/Rocrail-config-sensors-1.png\" alt=\"\" class=\"wp-image-638\" srcset=\"https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/05\/Rocrail-config-sensors-1.png 891w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/05\/Rocrail-config-sensors-1-300x243.png 300w, https:\/\/mattzobricks.com\/wp-content\/uploads\/2020\/05\/Rocrail-config-sensors-1-768x622.png 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><figcaption class=\"wp-element-caption\">Sensor configuration in Rocrail<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Wheel Counting \/ free@enter<\/h2>\n\n\n\n<p>Rocrail has a very nice feature called &#8220;Wheel counter&#8221;. The idea is that the wheels (i.e. magnets) that pass a sensor are counted. By comparing the number of wheels that have passed the last sensor, Rocrail is able to notice that a train has completely passed a specific sensor on the layout. Rocrail is using that information particularly on &#8220;Enter&#8221;-Sensors of a block, and frees the block ahead after all &#8220;wheels&#8221; have passed the sensor. This speeds up train operations on your layout significantly, as the last block is available for other trains a lot earlier compared to waiting until a train has reached the &#8220;In&#8221;-Sensor of the subsequent block.<\/p>\n\n\n\n<p>In order to use the feature, you need to configure the sensor type as &#8220;Wheel Counter&#8221; in the sensor configuration. The block and loco must also be configured as &#8220;free@enter&#8221;.<\/p>\n\n\n\n<p>To use this feature safely, please make sure that not only your loco, but also the last waggon of your train has a magnet installed. Commuter trains need magnets in the front and in the end.<\/p>\n\n\n\n<p>More details can be found in the <a href=\"https:\/\/wiki.rocrail.net\/doku.php?id=wheelcounting:wheelcounting-en\">Rocrail documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please read the general section first! Purpose The MattzoLayoutController is designed to receive input signals from digital sensors like reed switches and pass the information on to the Rocrail via the MQTT broker. Functional Description The MattzoLayoutController connects to MQTT as described in the &#8220;General&#8221; section. When a connected sensor [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1983,"menu_order":22,"comment_status":"open","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"class_list":["post-1218","page","type-page","status-publish","hentry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"de","enabled_languages":["en","de"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"de":{"title":false,"content":false,"excerpt":false}}},"_links":{"self":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/comments?post=1218"}],"version-history":[{"count":27,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1218\/revisions"}],"predecessor-version":[{"id":8964,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1218\/revisions\/8964"}],"up":[{"embeddable":true,"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/pages\/1983"}],"wp:attachment":[{"href":"https:\/\/mattzobricks.com\/de\/wp-json\/wp\/v2\/media?parent=1218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}