Building Arduino Projects for the Internet of Things

(Steven Felgate) #1
CHAPTER 4 ■ COMPLEX FLOWS: NODE-RED

You can add this threshold check within Arduino code as well, but consider a real-
life implementation of this same project. Instead of tweeting you can also use same logic
to build an application that conserves energy by opening window blinds and turning
lights inside the house off if it is sunny outside. If you hard-code such checks in Arduino
code, then individual users might not be able to set their light preferences, because they
cannot directly update the code. Taking such logic away from sensors will enable you to
build something that can be customized by individual users.
Drag and drop a switch node from the function category and place it in the Flow tab
after the Convert to Number node. Your flow should look similar to Figure  4-15 at this
point.


Figure 4-15. S w i t c h n o d e


A switch node lets you follow a certain path in the flow based on a condition.
Double-click the switch node to open its properties dialog box and set the conditions
shown in Figure  4-16.

Free download pdf