Raspberry Pi Node-RED Tutorial: From Installation to Automation

Raspberry Pi Node-RED Tutorial: From Installation to Automation

May 19th, 2025

图片 1.png__PID:a6651b38-bfee-4d9a-a2e8-3e098f9c9f54

What is Node-RED?

The Node-RED platform is a visual programming tool specifically designed to simplify the development of data-driven and event-based applications. It is commonly used in areas such as automation, the Internet of Things (IoT), and system integration. Through a user-friendly, browser-based editor, individuals including developers, engineers, and hobbyists can link together devices, web services, and APIs to create custom flows. Its design philosophy focuses on lowering technical barriers by reducing the need for extensive programming skills.

Key Features:

▪ Visual Flow Editor:
The platform offers a canvas-based interface that lets users construct applications by connecting logic blocks known as nodes. Each node represents a specific operation—such as input handling, data processing, or output generation—and the connections between them define the application's logic flow.

图片 2.png__PID:e10e8e5e-818f-46dd-b108-faf32aad398c

▪ Broad Integration Capabilities:
Node-RED provides out-of-the-box support for a variety of protocols, including HTTP, MQTT, WebSockets, TCP/UDP, and CoAP. This makes it highly adaptable for integrating with a wide range of connected devices, services, and platforms.

It works seamlessly with hardware such as Raspberry Pi GPIO, Arduino, and Zigbee-based devices, as well as smart home ecosystems like Home Assistant. On the enterprise side, it supports integration with cloud platforms like AWS IoT, Microsoft Azure, and Google Cloud, along with connections to ERP and CRM systems.

▪ Extensible with JavaScript Functions and npm Packages:
For tasks that require more than built-in nodes, you can write your own logic using JavaScript in Function Nodes.

Node-RED supports the full Node.js ecosystem, allowing you to install and use npm packages for extended capabilities (e.g., image processing, machine learning libraries, advanced data manipulation).

Why Use Node-RED on Raspberry Pi?

图片 3.png__PID:f5aefd24-6faf-4df9-8005-10f8256b6eed


✔ Minimal Setup
✔ PIO Control
✔ Local Data Processing
✔ Offline Capability

Raspberry Pi is an ideal platform for running Node-RED due to its low cost, small size, and sufficient processing power for most edge computing tasks. The simplicity of installation, combined with built-in hardware interfaces like GPIO, I2C, and SPI, makes it a preferred choice for rapid prototyping and IoT development. Node-RED runs efficiently even on entry-level Pi models and allows local data processing without relying on external servers, which enhances performance and reduces latency.

Common Use Cases of Node-RED on Raspberry Pi

图片 4.png__PID:7436ed4a-e64e-4f62-b5b3-2940e3c633b2

▪  Home Automation :
Smart Lighting: Automate light controls based on motion detection, time of day, or user presence.
Environmental Control: Use temperature and humidity sensors to manage fans, heaters, or air conditioners.
Security: Connect cameras, motion sensors, and door/window detectors, and send alerts via email or messaging apps.

▪  Industrial IoT (IIo
T):
Real-Time Monitoring: Collect and track data such as temperature, vibration, or system pressure from industrial sensors.
PLC Communication: Interface with programmable logic controllers using standards like Modbus or OPC-UA.
Predictive Maintenance: Analyze sensor outputs to detect wear or anomalies before failures occur.

▪  Data Storage and Dashboards:
Environmental Logging: Capture air quality, CO₂ levels, or temperature over time, storing results in databases like InfluxDB or MySQL.
Visualization: Use dashboard tools in Node-RED to create real-time charts and status indicators.

▪  IoT Gateway Functions:
MQTT Handling: Receive and publish data between devices and servers.
 Protocol Conversion: Bridge communication across MQTT, HTTP, and WebSockets for device compatibility.
 Edge Analytics: Process data on the Pi before forwarding summaries to cloud services.

▪  API Automation:
Web Integration: Trigger workflows based on data from external APIs such as weather or payment gateways.
Webhook Reactions: Respond to updates from services like GitHub or IFTTT with automated flows.

Installation Steps

Requirements

- All Raspberry Pi’s (3 or newer)
- Raspberry Pi OS installed on an SD card (minimum 8 GB).
- Internet access and basic terminal access (via monitor or SSH).

First, ensure your Raspberry Pi system is fully updated. Open a terminal and run:
sudo apt update && sudo apt upgrade -y

Next, install the official Node-RED package. The easiest way is to use the official installation script provided by the Node-RED team, which also sets up Node.js:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

图片 5.png__PID:8e833cad-cf90-41b5-8dec-edcd85523ad1图片 6.png__PID:3e3189fb-8e46-4828-a863-b0151df47f0e

During installation, the script will:
• Set up Node-RED to run as a system service (optional but recommended).
After installation is complete, enable Node-RED to start automatically at boot:
sudo systemctl enable nodered.service
 Start Node-RED manually:
node-red-start
By default, Node-RED runs on port 1880. Access the interface in a browser at:
 http://<ip-address>:1880

图片 7.png__PID:96cb28b8-b572-4f7d-a8ae-84eab698befe

Basic Configuration

Using GPIO Nodes (Optional for Raspberry Pi Projects)

图片 8.png__PID:6e6efee8-9254-4e91-8dbe-25b612925967

To control hardware:
1. Add an Inject node and a rpi-gpio out node (for output like LEDs).
2. Configure the GPIO node with a pin number (e.g., GPIO17) and set it to output mode.
3. Connect and deploy – clicking the inject node will turn the pin high (on).
4. Add another Inject node set to 0 to turn it off.

图片 9.png__PID:482f023c-ffeb-487b-97ba-b64f948576bb

You can also use rpi-gpio in nodes to read from buttons or sensors.

Saving and Exporting Flows
• To export a flow, click the menu (top right), then Export → Clipboard.
• To import a flow, click Import → Paste your JSON → Click Import.
• Flows are saved automatically, but it’s good practice to export backups for reuse or sharing.
Managing Flows
• You can create multiple flow tabs for different projects or parts of a system.
• Name flows meaningfully to keep them organized (right-click tab → Rename).
• Use the comment node to add notes or explain sections of your flow.

Popular Nodes and Extensions

GPIO Nodes (for direct hardware control)

These nodes allow you to interface with the GPIO pins of the Raspberry Pi to control and monitor physical components. You can:
    • Turn LEDs on and off.
    • Read data from buttons, motion sensors, or temperature sensors.
    • Control relays, motors, or other actuators. GPIO nodes are typically provided by the pre-installed node-red-node-pi-gpio package, and are essential for physical computing projects.

图片 13.png__PID:b0f02232-2e97-45e7-8ce3-9bfe097ab7a2
MQTT Nodes (IoT messaging protocol)

MQTT is a lightweight publish/subscribe protocol ideal for IoT communications. These nodes enable you to:
    • Subscribe to topics from other devices or services.
    • Publish sensor data or commands to a broker (like Mosquitto).
    • Integrate with cloud platforms like AWS IoT, HiveMQ, or local MQTT brokers.
These nodes are part of the node-red-node-mqtt package and support secure connections (TLS), authentication, and wildcard topics.

图片 14.png__PID:86bf4ad2-3e2c-4dd5-9271-be5f4ee87d5e
Dashboard Nodes (UI elements: charts, switches)

The node-red-dashboard module adds a powerful set of UI components that allow you to create real-time web dashboards.

You can build user interfaces to:
• Display live data in charts, gauges, or text indicators.
• Control GPIO devices through buttons, sliders, and switches.
• Create interactive forms and status panels. The dashboard is accessible via a browser (typically at /ui, e.g., http://<ip-address>:1880/ui), making it ideal for monitoring and control on tablets, phones,or desktops.

图片 12.png__PID:f107bd72-a3cd-4ec0-b2c5-80501fa7e266
Security Best Practices

▪  1. Enable User Authentication
By default, Node-RED has no login.To secure the editor:
    • Open the settings file:
 ~/.node-red/settings.js
    • Uncomment and configure the adminAuth section to add a username and hashed password:
adminAuth: {
  type: "credentials", users: [{
     username: "admin",
    password: "$2b$08$eW5...hashedPasswordHere...",
    permissions: "*"
  }]
}

    • Generate a hashed password using:
 node-red-admin hash-pw

▪  2. Use HTTPS Instead of HTTP
To avoid transmitting credentials and data in plain text:
    • Obtain or create SSL certificates (e.g., with Let's Encrypt or self-signed).
    • Modify settings.js to enable HTTPS:
https: {
  key: fs.readFileSync('/path/to/privatekey.pem'),
  cert: fs.readFileSync('/path/to/certificate.pem')
},


▪  3. Restrict Network Access
• Bind Node-RED to localhost if it doesn’t need to be accessed remotely:
uiHost: "127.0.0.1"
• Or use a firewall (e.g., ufw or iptables) to restrict access to port 1880 from specific IPs only.

▪  4. Limit Permissions and Access
    • Run Node-RED with a non-root user.
    • Use least-privilege principles: don’t give unnecessary sudo access to your Pi.

Conclusion

Node-RED transforms the Raspberry Pi into a powerful, flexible automation hub—perfect for IoT, smart home projects, and API-based workflows. Its intuitive, flow-based interface allows both beginners and advanced users to build complex systems without heavy coding. From controlling GPIO devices to integrating cloud services, Node-RED makes prototyping and deployment fast and efficient. Whether you're automating your home, building a data dashboard, or bridging multiple protocols, Node-RED on Raspberry Pi offers an accessible, extensible, and secure platform to bring your ideas to life.

Back to News Raspberry Pi VPN Server Setup Guide (2025): Protect Your Online Privacy