Maker.io main logo

How to Control LED Intensity Using Node-RED

2023-06-12 | By Don Wilcher

Traditional approaches like potentiometers or solid-state dimming circuits have often been ‎used to control an LED’s intensity. Although those approaches work great for controlling an ‎LED’s intensity locally, a wireless method provides greater remote control. In this article, you’ll ‎learn how to use Node-RED to control the intensity of an LED.

If you are new to using Node-RED, here are a few articles to learn how to use the flow ‎programming language. Make sure to check them out so you can get the most out of this ‎article!

How to Install and Get Started with Node-RED

Create User Dashboards for IoT Projects using Node-RED

The Concept: Using Node-RED for LED Intensity

Node-RED provides a variety of IoT possibilities for home automation, smart sensor monitoring, ‎and wireless embedded control applications. The idea behind using Node-RED to operate an ‎LED is to be able to control its intensity wirelessly from a mobile device like a smartphone or ‎tablet. Connecting a Node-RED dashboard using your home Wi-Fi network allows the LED’s ‎intensity to be easily adjusted; a slider allows the LED’s intensity to be changed by sliding the ‎widget with your finger. This Node-RED LED dimmer controller requires only a few off-the-shelf ‎components.

How to Control LED Intensity Using Node-RED Node-RED LED Dimmer control concept drawing.

The Bill Of Materials

Building the Node-RED Dimmer controller requires three major components: a Raspberry Pi, a ‎‎220Ω resistor, and a red LED. To obtain the best operating results with Node-RED, a Raspberry ‎Pi 3 or later should be used for this project.

You can find the bill of materials (BOM) and schematic for this here. A solderless breadboard ‎and jumper wires will be needed to wire the 220Ω resistor and the red LED to the Raspberry Pi ‎General Purpose Input Output (GPIO) pin 19.

Wiring the LED Circuit

Wiring the LED circuit to the Raspberry Pi is quite easy to do -you will place the red LED and the ‎‎220Ω resistor on a solderless breadboard. The proper orientation of the red LED on a solderless ‎breadboard is important: if the LED’s orientation is incorrect, the circuit will not work. The ‎resistor’s orientation is not critical; therefore, the placement of the component is not a major ‎concern.

How to Control LED Intensity Using Node-RED The solderless breadboard electrical wiring diagram.

The Pi T Cobbler Plus extension board provides convenience for wiring the LED circuit to the ‎Raspberry Pi GPIO19 pin. If a Pi T Cobbler extension board is not available, you will need to ‎make the wire connections directly to the Raspberry Pi’s 40-pin connector.

How to Control LED Intensity Using Node-RED The completed Raspberry Pi – LED circuit on a solderless breadboard.

With the wiring completed, the Node-RED flow control nodes can be built.

Building the Node-RED Flow Control Nodes

Building the LED Intensity Controller requires three widget components: a slider node, a GPIO ‎out node, and a gauge node. The slider node will connect the GPIO and the gauge nodes. ‎Messages will be sent to the gauge and GPIO nodes to display the LED intensity level and ‎provide a dimming control signal; the dimming control is a pulse-width modulated (PWM) ‎signal to adjust the current flowing through the red LED.

How to Control LED Intensity Using Node-RED LED dimming flow control diagram.

The configuration (properties) of each node can be seen below.

How to Control LED Intensity Using Node-RED Slider node Configuration.

The GPIO out node properties are configured as shown next.

How to Control LED Intensity Using Node-RED GPIO out node configuration.

Finally, the configuration of the gauge widget properties is illustrated below.

How to Control LED Intensity Using Node-RED Gauge node configuration.

Testing the Wi-Fi LED Intensity Controller

With the flow control diagram nodes configured, you may enable the project by pressing the ‎Deploy button on the Node-RED editor. Once deployed, the dimming control dashboard and the ‎interactive widgets will be visible and ready to operate the LED intensity. The Node-RED gauge ‎will show the LED intensity level based on the slider widget’s adjusted position.

How to Control LED Intensity Using Node-RED Deployed and operational LED Dimming Control Dashboard

The dashboard can be viewed on a desktop personal computer (PC), smartphone, or tablet. I ‎used an Amazon Fire tablet to test out the Wi-Fi based controller. You can see the actual ‎dashboard controller in operation by clicking here for the video clip.

How to Control LED Intensity Using Node-RED Tablet setup to test the Node-RED Wi-Fi LED Dimmer (Intensity) Controller.

Summary

In this article, we saw how to wire an LED circuit to a Raspberry Pi’s GPIO pin and how to select ‎dashboard widgets and wire them to create an interactive Wi-Fi controller. Finally, we looked ‎at editing the properties of the dashboard widgets and how to deploy the flow control diagram ‎and test the operation of the intensity on an LED. Let us know how your project has come ‎together and what you would like us to work on next in the Node-RED ecosystem!

制造商零件编号 CF14JT220R
RES 220 OHM 5% 1/4W AXIAL
Stackpole Electronics Inc
LED RED DIFFUSED T-1 3/4 T/H
制造商零件编号 XLUR12D
LED RED DIFFUSED T-1 3/4 T/H
SunLED
制造商零件编号 1989
PI T-COBBLER PLUS KIT
Adafruit Industries LLC
制造商零件编号 SC0022
SBC 1.2GHZ 4 CORE 1GB RAM
Raspberry Pi
制造商零件编号 DKS-BBOARD6.5
DIGI-KEY BREADBOARD 6.5
DIGIKEY STANDARD
制造商零件编号 PRT-12795
JUMPER WIRE M/M 6" 20PCS
SparkFun Electronics
制造商零件编号 PRT-12794
JUMPER WIRE M/F 6" 20PCS
SparkFun Electronics
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum