Maker.io main logo

Control a DC Motor with an LED Indicator from Node-RED Dashboard

2023-05-11 | By Don Wilcher

License: See Original Project DC Motor

In this project, we’ll show you how to build a Node-RED Dashboard to operate a ‎DC Motor with an LED. Using a slide switch widget, the Node-RED Dashboard will ‎turn on a DC motor using a basic transistor as an electronic switch, and an LED will ‎turn on with the DC motor when the slide switch widget is on. Besides being ‎accessible online, the dashboard can be accessed using mobile devices like ‎smartphones or tablets.‎

project_1

This article builds off a previous Maker.io project discussing how to build a Node-‎RED dashboard. The approach to controlling a DC motor and LED makes the ‎project interactive, allowing Node-RED to control various devices in your home or ‎workshop. We have the parts list, schematics, and step-by-step processes you ‎need to follow along, and make this project for yourself, so let’s get started!‎

The Project’s Components

The Node-RED DC Motor and LED controller is made up of several components: a ‎Raspberry Pi, a DC motor, an LED, and a few discrete components. The controller ‎is built using a Raspberry Pi, an NPN transistor, two resistors, an LED, a general-‎purpose diode, and a small 5VDC electric motor. The NPN transistor operates the ‎DC motor when the Raspberry Pi provides the proper control signal. ‎‎

Raspberry-Pi-DC-Motor-Controller-LED-Indicator

The Node-RED Electronic Circuit Schematic Diagram

A 470-ohm series resistor protects the NPN transistor from excessive current. The ‎proper control signal is 3.3VDC to turn on the NPN transistor. The LED also turns ‎on with the control signal produced by the Raspberry Pi. Like the NPN transistor, a ‎‎220-ohm resistor is wired to the LED to protect it from excessive current. A ‎‎3.3VDC voltage will turn on the LED wired to the Raspberry Pi. The general-‎purpose diode prevents the back electromotive force (EMF) voltage, which is ‎created when the motor turns off, from damaging the NPN transistor. ‎

The parts list to build the Node-RED controller can be found here!

Node_RED_DC_Motor_LED_Motor_Cont-Elec_Wiring_Diagram

The Node-RED DC Motor-LED Controller solderless breadboard prototype ‎electrical wiring diagram.

Working with the Node-RED Editor

The Raspberry Pi is the wireless gateway for accessing the Node-RED editor. If ‎you’re unfamiliar with Node-RED, this article is a great place to learn about low-‎code event-driven programming environments. The Node-RED URL address can ‎be accessed using any web browser to allow the Raspberry Pi to operate the DC ‎Fan motor and the LED. The web browser URL address will be found in the Node-‎RED Terminal window. ‎

The Node-RED terminal can be accessed by selecting the software application ‎through the programming category found on the Raspberry Pi. Selecting the ‎Node-RED icon will open the terminal.‎

Node_RED_software

Selecting and opening the Node-RED software application. ‎‎ ‎

Accessing_the_Node_RED_editor

Accessing the Node-RED web Editor using the terminal.‎‎

Node_RED_Editor

The Node-RED web editor.

Building the Node-RED DC Motor-LED Controller Dashboard

With the solderless breadboard controller prototype built and the Node-RED ‎editor accessible, you can start building the dashboard! ‎

The first step is to have the dashboard node available within your node palette. ‎Traditionally, the dashboard and the Raspberry Pi nodes are pre-installed with the ‎Raspberry Pi distro operating system. (Check out the article on installing and ‎setting up a test dashboard-it’s a must-read if you haven’t done this before!).‎

You’ll need to construct a Node-RED flow diagram to build the dashboard. The ‎network flow diagram will control the DC motor and the LED, and the binary ‎message payloads will be passed within the Node-RED network flow diagram. The ‎message payloads to pass through the network flow diagram are true and false. ‎The image below shows what the network flow diagram looks like:‎

The_Node_RED_DC_Motor_LED_Controller_network

The Node-RED DC Motor-LED Controller network

By double-clicking on each node, you can edit the node’s property and the data ‎parameter to pass the appropriate message payload. The image below shows the ‎DC Fan Switch being configured to display a dashboard slide switch. ‎

DC_FAN_Switch_Node_configuration

Configuring the dashboard DC Fan slide switch

The Group is the main container that manages the widgets for the specified ‎dashboard. To edit the Group, select the pencil icon, and a new window will ‎appear. You will then type Wireless Controller for this project’s dashboard in the ‎textbox, then click Done to complete the edit task. ‎

As illustrated in the following diagrams, you will next configure the DC FAN, the ‎LED, and the DC Motor status network nodes.‎

DC_FAN_Node_configuration

Configuring the DC FAN node

LED_Node_configuration

Configuring the LED node

DC_Motor_Status

Configuring the DC Motor Status node

With the Node-RED nodes configured for the dashboard, the next step is to test ‎the User Interface (UI) controller. As a final note, the Group and the dashboard ‎node elements are established within the Node-RED’s network flow diagram. This ‎hidden feature allows the UI dashboard controller to be configured for ‎engagement and human interaction. (If you want ideas on different UIs, make ‎sure to read this article!) ‎

After configuring the network flow diagram nodes with the Wireless Controller ‎Group designator, the dashboard design will be visible in a new web browser. ‎

After initiating deployment, the web browser will display the DC Motor-LED ‎controller UI dashboard. To initiate deployment, click the Deploy button with ‎your mouse.‎

The_Node_RED_DC_Motor_LED_controller_dashboard

The completed DC Fan Controller dashboard

When sliding the on-screen slide switch, the DC FAN and the LED will turn ON, and ‎the DC Motor Status message will switch from false to true. With the LED circuit ‎being wired to a separate GPIO pin on the Raspberry Pi, an additional widget can ‎be added. ‎

Another slide switch widget can be provided for independent control by ‎placement of a web-based interactive device on the dashboard. An LED Status ‎message can be provided as well. The dashboard can easily be viewed on a ‎smartphone or tablet on the same network by typing the UI’s address within a ‎web browser. This feature demonstrates the mobile capabilities of remotely ‎controlling the DC motor and the LED.‎

What else can we do with this Dashboard?‎

Although a 2N3904 NPN transistor was used as the main driver component to ‎operate the DC FAN, a power Metal Oxide Semiconductor Field Effect Transistor ‎‎(MOSFET) can be used as well. A P-MOSFET provides efficiency to an ‎electromechanical load like a DC motor by reducing the power dissipation of the ‎control switching function. This low power dissipation effect is because of the P-‎MOSFET’s low drain-to-source resistance (Rds). Typical Rds values for P-MOSFETs ‎are in the micro-ohms (µΩ) to milli-ohms (mΩ) range. As a dashboard controller ‎experiment, replace the single-transistor motor driver with a two-transistor stage ‎switching circuit. The two-transistor switching driver circuit is shown below.‎

Two_Stage_Transistor_DC_Fan_Motor_driver_circuit

A two-stage switching DC Fan driver circuit

You will notice that the DC Motor status and slide switch widgets are opposite to ‎the operation of the DC Fan. The LED circuit will work normally. Can you think of ‎an application for such a reversal motor operation? ‎

Summary

This project illustrated how easy it is to make a home wireless controller using an ‎off-the-shelf-embedded single-board computer (SBC) and a few discrete ‎electronic components. The DC Fan-LED controller’s IoT design was developed ‎using the Node-RED web editor. An M5Stack Core 1 and 2 controllers can easily ‎be integrated to provide aesthetically appealing output UI status for human ‎interaction and engagement.

Watch this short video to see the DC Fan Controller ‎dashboard in action!

 

Recommended Reading

How to Install and Get Started with Node-RED

Create User Dashboards for IoT Projects in Node-RED

How to Use Variables in Node-RED

How To Connect an Arduino to Node-RED

What is Back EMF in DC Motors? - Another Teaching Moment

制造商零件编号 CF18JT220R
RES 220 OHM 5% 1/8W AXIAL
Stackpole Electronics Inc
制造商零件编号 2N3904BU
TRANS NPN 40V 0.2A TO92-3
onsemi
制造商零件编号 1N4007G-T
DIODE GEN PURP 1KV 1A DO41
Diodes Incorporated
制造商零件编号 MF40200V3-1000U-A99
FAN AXIAL 40X20MM VAPO 5VDC WIRE
Sunon Fans
制造商零件编号 SC0193(9)
RASPBERRY PI 4 B 2GB
Raspberry Pi
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