How to use node red for automation?


Aug 5, 2022

Reading Time: 3 Min

Node-RED is a visual programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.

It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.

Node-RED is used by developers to create event-driven applications, which can be deployed on-premises, in the cloud or even on Raspberry Pis.

In this tutorial, we will show you how to use Node-RED to create a simple automation that will turn a light on when motion is detected.

You will need:

– A Raspberry Pi

– A breadboard

– An LED

– A PIR motion sensor

– Jumper wires

1. Set up your Raspberry Pi

If you haven’t already done so, set up your Raspberry Pi with a Raspbian operating system.

2. Install Node-RED

Node-RED can be installed on your Raspberry Pi using apt:

sudo apt install nodered

3. Start Node-RED

Once Node-RED is installed, you can start it with the following command:


4. Access the Node-RED editor

Once Node-RED has started, you can access the editor by pointing your browser to http://localhost:1880.

5. Create a flow

In the Node-RED editor, create a new flow by clicking on the “+” icon in the top right-hand corner.

6. Add nodes

To the flow, add the following nodes:

– An Inject node, to trigger the flow

– A Debug node, to output the message

– A PIR motion sensor node, to detect motion

– An LED node, to control the LED

7. Wire the nodes together

Wire the nodes together as shown in the image below.

8. Configure the PIR motion sensor node

Double-click on the PIR motion sensor node to open the configuration dialog.

In the “GPIO pin” field, enter the GPIO pin that the PIR motion sensor is connected to.

In the “Sensor type” field, select “NC”.

Click “OK” to save the configuration.

9. Configure the LED node

Double-click on the LED node to open the configuration dialog.

In the “GPIO pin” field, enter the GPIO pin that the LED is connected to.

Click “OK” to save the configuration.

10. Deploy the flow

Click on the “Deploy” button in the top right-hand corner to deploy the flow.

11. Test the flow

To test the flow, trigger the

Other related questions:

Can I use Node-RED in production?

Node-RED can be used in production, but there are some important considerations to take into account.

Node-RED is designed to be run on a server with a persistent connection to the internet. If your server is not always connected, you may want to consider using a service like Heroku which will provide a free server that will stay up even if your laptop is turned off.

Node-RED uses a lot of RAM and CPU when processing flows. If you are using flows that are particularly complex or use a lot of nodes, you may want to consider running Node-RED on a more powerful server.

It is also worth noting that Node-RED is not a traditional application server. It does not provide any built-in security mechanisms and it is not designed to be used behind a firewall. If you are planning to use Node-RED in a production environment, you will need to take security considerations into account.

What can I use Node-RED for?

Node-RED can be used for a wide variety of applications, from simple data
logging to complex event processing and data visualization.

How do I make Node-RED automatically start?

There are many ways to make Node-RED automatically start.

The most common way is to use a process manager like PM2.

Another way is to use a systemd service.


  • Was this Helpful ?
  • YesNo

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *