Getting set up with Node-RED on the Raspberry Pi

Updated 22 April 2022

What is Node-RED?

Node-RED is a tool originally created by IBM for flow-based programming, and has built-in support for the Raspberry Pi and it's GPIO capabilities. It runs on top of Node.js, and can be accessed with just a web browser to create a visual programming environment. This allows you to see an overview of what your program is doing, rather than having to understand all the lines of code needed to run it, which means you can get on with creating your project faster! You can then use it to connect to a plethora of devices and services, from IoT and GPIO pins to social media and creating your own dashboards.

How to install the server on Raspbian

Doing this is really simple. If you're using Raspbian with Desktop version 2018-04-18 or before, you don't need to do anything as it's already installed. In 2018-06-27 though, the Raspberry Pi Foundation removed Node-RED and a few other programs by default to reduce the image size. In this case, it's pretty simple to get it back: Click the Menu button (Raspberry symbol) and go to Preferences > Recommended Software. In there, you will find Node-RED (under Programming, or just search for "node"). Just tick the box, click Ok, and wait for it to install:

node-red-install

For any other Raspberry Pi distro you want to install Node-RED on, you just need to run this command in a terminal:

bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

Once the server is installed, you can get it to run by going to Menu > Programming > Node-RED, or by the command node-red-start in a terminal. When it has finished starting up, you will see Server now running at http://127.0.0.1:1880/ near the bottom:

node-red-running

You can then just minimise the window and start working with it. If you'd like to run the server in the background every time the Pi turns on, you can open a Terminal window and run sudo systemctl enable nodered.service. To stop it running on boot, you can run sudo systemctl disable nodered.service. Reboot the Pi to commit those service changes.

How to connect to your server

If you're going to be developing on the Raspberry Pi directly like I am, you can open up the Web Browser and navigate to either http://127.0.0.1:1880/ or http://localhost:1880/. If you want to develop on a different computer on the same network, just navigate to http://raspberrypi:1880 (assuming "raspberrypi" is the hostname of your Pi; some connections might need "raspberrypi.local"). You should be greeted with the web interface, which hides the JSON layout of nodes underneath (you'll be able to access this later if you really want to).

node-red-web-interface

Making sure it's working

Let's make a quick breadboard circuit to make sure that Node-RED can connect to our Pi's GPIO pins. It will look like this:

node-red-test-circuit

We will then be creating a simple flow to turn the LED on and off.

  1. Click and drag an "inject" node from the "input" section on the left. It should appear as a timestamp node.
    node-red-step-1

  2. Double click it. Change the Payload type to "number" and give it a value of "1". Change the Name to "LED On".
    node-red-step-2

  3. Click Done. Create another inject node. Double click it. Change the Payload type to "number" and give it a value of "0". Change the Name to "LED Off".
    node-red-step-3

  4. Click Done. Scroll down the sections on the left, and drag a "rpi gpio" output node (dot on the left, raspberry logo on the right) to the flow.
    node-red-step-4

  5. Double click it. Change the Pin to "12 - GPIO18". Tick the "Initialise pin state?" box, and make sure it's set to "initial level of pin - low (0)". Change the Name to Blue LED.
    node-red-step-5

  6. Click Done.
    node-red-step-6

  7. Click and drag from the dots on the right of the inject nodes to the ones on the left of the rpi gpio node to join them.
    node-red-step-7

When you're done, click deploy in the top right corner. It should tell you that it was successful.

node-red-deployed

The big buttons on the left of the inject nodes should become clickable. Clicking on them should then send the values you specified to the Blue LED node, turning the LED on and off.

node-red-led-on

node-red-live-led-on

node-red-led-off

node-red-live-led-off

hello


Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.