lego train track bridge

lego train track bridge

lego train sets walmart

Lego Train Track Bridge

CLICK HERE TO CONTINUE




The infrared remote controlled LEGO train is out of view, but it needs to be stopped! How can we control a train if you can’t see it? The ESP8266 is the greatest thing since sliced bread, for IoT projects. It’s basically an 802.11n WiFi chip with a microcontroller that provides GPIOs. The only issue with this is that it can be a pain to get going. The chip only supports 3.3v and requires some additional circuitry to program and connect to a USB interface. It’s doable, but the small chip expands into a larger circuit which increases overall install size (in development environments). The NodeMCU attempts to solve these problems by placing the ESP8266 on a dev board, that includes GPIO breakouts, a USB interface and power management. By writing some minimal code on the chip, I can control a motor via a simple REST interface. Basically, I can just go to a web URL and something happens. To provide a front-end and connect it to the Internet of Things, I will use Node-RED hosted on a Raspberry Pi. L




ike many of the other Internet of LEGO projects, Node-RED is used to send commands, collect data and build a simple UI to interact with the network. A previous IoL article, Lego Train Automation – IR Power Functions, used the standard infrared receiver and a Raspberry Pi based transmitter to control the train. It worked really well and didn’t require any modifications to the train or controller for it to work. The problems started surfacing as I tried to control the trains when they were behind buildings or in a tunnel. Since there is a subway station and track intersections, I need to be able to control the train at all times. The NodeMCU consists of a firmware and ESP8266 12-E development board. The system can be programmed using Lua script, but it can also be programmed using the Arduino IDE. Since many of my projects have been based on the classic Arduino dev boards, I will stick with what I know. The motor shield will provide a simple way to power the LEGO train motor. S




ince the microcontroller is not intended for higher voltages and current, a shield will be used to switch on the heavier loads. This version supports two motors and provides access to the remaining GPIO pins. Both the NodeMCU and the motor shield were purchased on eBay for around $10. The Raspberry Pi will be used to host Node-RED and run a Mosquitto MQTT broker/bridge. It’s a small, inexpensive, single board computer that runs Linux. I have a Pi at the center of my IoL city, and use it for most of the high-level logic. Although it does have its own GPIOs, I find it better to use a microcontroller like an Arduino/ESP8266 for embedded projects and use the Pi for orchestration. The LEGO Group have released various versions of LEGO train electronics over the years. The latest version uses a LiPo battery, infrared controller and 7.4v motor. This project will effectively replace the infrared controller with a NodeMCU WiFi controller. Build a LEGO train, then cram the components into it!




This is the high speed rail, Horizon Express, that I just acquired for the task. The train is hard to find, but is one of the few “expert” train sets released so I was happy to find one out of Hungary on Brick Owl! Here is the general flow for this entire system. Let’s start from the bottom up with the NodeMCU, which will control the train and define the API for the dashboard access. To program the NodeMCU with the Arduino IDE, first install the extra support for the development board. By using the Boards Manager in the Arduino IDE, search for ESP8266 and select install. Now you can select “NodeMCU 1.0” from the Tools –> Board menu. The aREST library provides an easy way to create a REST interface for exposed functions and variables. The ESP8266WiFi library takes care of all the WiFi connection mechanics. Once the code has been configured with your settings and uploaded to the NodeMCU, the serial monitor will show that it is connected and the IP address you can use to contact it.




Node-RED is “a visual tool for wiring the Internet of Things”, which is built on NodeJS. It is also now included with the default Raspberry Pi image, Raspbian “Jessie”. The basic concept is to create input nodes (buttons, PubNub, MQTT, Tweet, etc) and pass along the msg object. Function nodes (JavaScript function, JSON converter, switches) will then manipulate the object so that it can be formatted or be used to make decisions for the next flow step. HTTP request nodes will be used to send the GET requests to the NodeMCU. There are various green debug nodes, that will display the state of the msg object in the debug console. This Node-RED “flow” is pretty straight-forward. Since we built a REST interface for the train, we just need to send a command by hitting a web URL. The input nodes will inject a “topic” and “payload” corresponding to the device and command. There are also MQTT inputs and outputs so that this system can be managed from a cloud Pub/Sub model. T




his allows the Raspberry Pi to run in a private network with a random IP address and still be accessible from a dashboard server or other system in a different network. The http request node is how the command gets sent to the train. The topic will indicate the device (i.e. motor or lights) and the payload will indicate the command. There are several blue inject buttons, to control the direction, throttle and brake directly from Node-RED. This is handy for testing. By using the “node-red-contrib-ui” UI nodes, I can create a simple and attractive AngularJS interface to send these commands. This node will create a group of buttons using AngularJS material icons. In order to update the light switch and speed gauge, the current status needs to be known. To pull the status, we just need to go to the root URL. This status info will be used to update the state of the UI. Function nodes are used to extract the status variables I am concerned with and forward them on to the next node.

Report Page