Create a streetcar with Lego Mindstorms components and a Raspberry Pi
Node-RED Automatic Control
We found the automatic control logic to be a little trickier than the manual logic. Our first step was to see if we could read the Lego Mindstorms touch sensors, so we connected an Explorer HAT
input node to a debug
node (Figure 7), manually pushed each touch sensor, and clicked the debug tab to check the results.
To catch when the streetcar hits the touch sensor at station 1, we needed to create a function (Figure 8) that looked at the topic explorerhat/input.1
. If this topic's payload is 1
(i.e., touched), then the Explorer HAT motor can be stopped by sending a message with the topic motor.one
and payload = 0
. A similar function is created for the touch sensor at station 2, except the topic explorerhat/input.2
is monitored.
After the streetcar hits a touch sensor, we want it to pause and then move in the opposite direction. A delay
node was used for the pause, followed by a function
node to send a message payload with the new speed and direction (Figure 9). For this project, station 1 restarted with a speed of -70
, and station 2 restarted with a speed of 70
(i.e., +70). The complete logic with both manual and automatic control is shown in Figure 10.
Summary
The combination of Lego Mindstorms components, the Explorer HAT Pro, Node-RED, and a Raspberry Pi can be the starting point for many interesting projects. Here, we created a streetcar that runs its route automatically, but also allows manual intervention – such as for those ubiquitous summer street repair projects.
Some future ideas for this project are:
- writing the code in Python
- adding a speed adjustment
- creating an elevator instead of a streetcar
Infos
- Lego Mindstorms: https://en.wikipedia.org/wiki/Lego_Mindstorms
- Dexter Industries breadboard adapter: https://www.amazon.com/Breadboard-Adapter-for-LEGO-MINDSTORMS/dp/B00A0P5FY6/
- Explorer HAT Pro: https://shop.pimoroni.com/products/explorer-hat
- Node-RED library: http://flows.nodered.org
« Previous 1 2 3 Next »
Buy this article as PDF
Pages: 6
(incl. VAT)