ESP8266 in conjunction with Node-RED and MQTT
442.ESP8266 in conjunction with Node-RED and MQTT In this post, we are going to demonstrate how you can use Node-RED to control the outputs of an ESP8266 and display sensor data received…

Know the mission before touching a wire.
Understand what you are making, prepare the right tools, and make the workbench safe.
Project details
ESP8266 in conjunction with Node-RED and MQTT is a iot project. 442.ESP8266 in conjunction with Node-RED and MQTT In this post, we are going to demonstrate how you can use Node-RED to control the outputs of an ESP8266 and display sensor data received…
- Source pages
- 1109-1116
- Named parts
- 5
- Build goal
- Working, tested prototype
Tools you need
- Digital multimeter
- Wire stripper and side cutters
- Soldering iron with a fine tip
- Current-limited bench supply
- Computer with a data-capable USB cable
Use eye protection, good lighting, and a clean insulated surface throughout the build.
Safety precautions
- Disconnect every power source before changing a connection.
- Check component polarity, pinout, and supply voltage twice.
- Use a current limit for the first power-up.
- Keep liquids, loose metal, and uninsulated wires away from the bench.
Gather, identify, and understand every part.
Use the standardized inventory, then open What's this? to learn each part's role, advantages, limitations, handling, and specifications.
What's this?Image, role, pros, cons, handling & specifications

To construct the circuit, you will need the following components
A named project component whose exact role is defined by the source circuit and build guide.
What it does hereIt performs a documented electrical, control, interface, or construction function in this project.
Buy / compare this part ↗Advantages
- Selected for this project
- Can be checked independently
- Supports modular troubleshooting
Limitations
- Substitutes may differ
- Generic names can hide variants
- Pinouts and ratings vary
Handling
- Compare the received part with the source
- Keep it labelled
- Do not force connectors or adjusters
Specifications to verify
- Use the exact model, value, package, and rating listed for To construct the circuit, you will need the following components; similar-looking parts are not always interchangeable.
- Confirm dimensions, ratings, connection method, polarity, and environmental limits.
What's this?Image, role, pros, cons, handling & specifications

Raspberry Pi
A programmable controller that reads inputs, makes decisions, and drives the project's outputs.
What it does hereIt is the control centre and must use the documented board, pin map, supply, and logic level.
Buy / compare this part ↗Advantages
- Reprogrammable and reusable
- Large learning ecosystem
- Complex behaviour remains changeable
Limitations
- GPIO voltage and current are limited
- Some pins affect boot or communication
- Loads normally need a driver
Handling
- Disconnect power before rewiring
- Avoid static discharge
- Never power motors, relays, or pumps directly from GPIO
Specifications to verify
- Use the exact model, value, package, and rating listed for Raspberry Pi; similar-looking parts are not always interchangeable.
- Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
What's this?Image, role, pros, cons, handling & specifications
MODULE LEARNING VIEWESP8266 (ESP-12E Nodemcu)
A programmable controller that reads inputs, makes decisions, and drives the project's outputs.
What it does hereIt is the control centre and must use the documented board, pin map, supply, and logic level.
Buy / compare this part ↗Advantages
- Reprogrammable and reusable
- Large learning ecosystem
- Complex behaviour remains changeable
Limitations
- GPIO voltage and current are limited
- Some pins affect boot or communication
- Loads normally need a driver
Handling
- Disconnect power before rewiring
- Avoid static discharge
- Never power motors, relays, or pumps directly from GPIO
Specifications to verify
- Use the exact model, value, package, and rating listed for ESP8266 (ESP-12E Nodemcu); similar-looking parts are not always interchangeable.
- Confirm operating voltage, logic level, pinout, memory, USB interface, and maximum GPIO current.
What's this?Image, role, pros, cons, handling & specifications

DHT11 temperature and humidity sensor Breadboard resistors 330
A sensor converts a physical condition into an electrical signal the circuit can measure.
What it does hereIt provides project input as an analogue, digital, resistive, frequency, or calibrated signal.
Buy / compare this part ↗Advantages
- Adds real-world awareness
- Can usually be tested independently
- Often supports calibration
Limitations
- Readings can drift
- Placement affects results
- Some sensors need warm-up or calibration
Handling
- Protect the sensing surface
- Observe supply voltage and polarity
- Keep signal leads away from noisy power wiring
Specifications to verify
- Use the exact model, value, package, and rating listed for DHT11 temperature and humidity sensor Breadboard resistors 330; similar-looking parts are not always interchangeable.
- Confirm supply range, output type, measurement range, accuracy, response time, and pin order.
What's this?Image, role, pros, cons, handling & specifications
PART LEARNING VIEWohm and 4700-ohm LED resistor
An output component turns an electrical control signal into light, sound, motion, switching, or displayed information.
What it does hereIt presents the circuit result or acts on the physical world.
Buy / compare this part ↗Advantages
- Makes system state visible
- Can be tested separately
- Supports clear troubleshooting
Limitations
- Loads may exceed controller current
- Polarity or driver direction can matter
- Inductive loads create voltage spikes
Handling
- Use the documented driver stage
- Check polarity and load current
- Add flyback protection for inductive loads
Specifications to verify
- Use the exact model, value, package, and rating listed for ohm and 4700-ohm LED resistor; similar-looking parts are not always interchangeable.
- Confirm voltage, current, polarity, interface, driver requirements, and duty cycle.
Connect one verified path at a time.
Explore the named components and standardized signal flow, then use Source Check to verify exact physical pins, values, and topology before applying power.
Trace this circuit.
ESP8266 in conjunction with Node-RED and MQTT: interactive parts, standardized terminals, responsive anchored wires, student explanations, and the original circuit reference in one shared system.
Trace before wiring
Follow power, ground, inputs, processing, and outputs in that order. Never guess a pin from package shape alone.
Connect with power off
Make short, labelled connections and share a common ground only where the schematic requires it.
Inspect every joint
Check continuity, polarity, adjacent shorts, and loose connections before the first power-up.
Open all source diagrams and build views 2 visuals


Confirm the hardware-only control path.
This project does not include firmware in the source. The circuit itself provides the required behaviour.
How to connect
- Match every controller label to the circuit view and source pin map.
- Join grounds before signal wires when separate low-voltage supplies are used.
- Keep motors, relays, pumps, and other loads on a suitable driver and external supply.
Common mistakes
Reversed VCC/GND, board-label versus GPIO-number confusion, missing common ground, and charge-only USB cables.
Troubleshoot
Disconnect loads, continuity-test one path at a time, then test with a current limit.
Software preparation
No IDE, board package, library, or firmware upload is required for this project.
If you add a programmable controller as an extension, document its pin map separately.
How to upload code
The original design is implemented entirely in hardware, so proceed after verifying the circuit and supply.
Assemble, deploy, test, and troubleshoot.
Use the complete source notes in build order, then pass the final checks before calling the project finished.
Build in functional stages
- Power and regulation
- Controller or processing stage
- Inputs and sensors
- Outputs and loads
- Enclosure and strain relief
Power up safely
- Inspect unpowered continuity first
- Apply the lowest safe current limit
- Measure supply rails before signals
- Add one load at a time
- Record expected and actual results
Work from simple to complex
- Confirm power, ground, polarity, and orientation
- Compare each pin with the source
- Test inputs separately from outputs
- Replace only one variable at a time
- Power off before every correction
Follow the documented instructions.
These notes come from this project's source and remain in their original order.
Project overview
Project build note442.ESP8266 in conjunction with Node-RED and MQTT In this post, we are going to demonstrate how you can use Node-RED to control the outputs of an ESP8266 and display sensor data received from an ESP8266. The Node-RED software is being run on a Raspberry Pi, and the MQTT communication protocol is being used to facilitate communication between the ESP8266 and the Node-RED software. Node-RED and Node-RED Dashboard It is necessary for your Raspberry Pi to have Node-RED and the Node-RED Dashboard application installed. The blog posts listed below are helpful if you are just getting started with Node-RED and the Node-RED dashboard: MQTT Protocol
Using MQTT, we are going to connect an ESP8266 to a Raspberry Pi that is operating the Node-RED software. The goal of this tutorial is to enable two- way communication between the two devices. MQTT is an acronym that stands for " MQ Telemetry Transport." It describes a system that allows clients to both send and receive messages, and it is a nice, lightweight publish and subscribe system. It is a straightforward messaging protocol that was developed for devices that have limited resources and bandwidth. Therefore, it is an ideal option for use in applications related to the Internet of Things. Installing Mosquitto Broker In MQTT, it is the broker's primary responsibility to receive all messages, filter those messages, determine which clients are interested in a particular message, and then publish that message to all clients who have subscribed to it. There are many different brokers available for your use. In this guide, we are going to make use of the Mosquitto Broker, which requires the Raspberry Pi to have the appropriate software installed.
Testing
Project build noteExecute the following command to determine whether or not the Mosquitto
broker was successfully installed
Project build notepi@raspberry:~ $ mosquitto -v This gives you the version of Mosquitto that is currently installed and operating on your Raspberry Pi. It should be 1.4 or higher at the very least. Note that in addition to returning the Mosquitto version that is currently installed, the Mosquitto command attempts to initialize Mosquitto once
more. Due to the fact that Mosquitto is already active, an error message is displayed. If you see a message like this, you don't need to worry because Mosquitto has been installed and is running correctly. Establishing a MQTT communication with Node-RED Using the Node-RED nodes, we are going to set up a communication using the MQTT protocol in this section. Dashboard Layout The first thing you need to do is design the layout for the dashboard. In this demonstration, we will make use of a button to control an ESP8266 output, as well as a chart and a gauge to display the temperature and humidity readings collected by the DHT11 sensor. Choose the Layout tab from the drop-down menu that appears after you click the dashboard tab in the Node-RED window's upper right corner. Make a tab labeled Room, and then inside that tab, make two groups: one labeled Lamp, and the other labeled Sensor. Preparing your Arduino IDE We will use the Arduino IDE to write the code for the ESP8266. In order to use the Arduino Integrated Development Environment (IDE) to upload code to your ESP8266, you will need to install the ESP8266 add-on (How to Install the ESP8266 Board in Arduino IDE). In order for everything to be prepared for your ESP8266, you will additionally need to install two additional libraries. Installing the PubSubClient Library A client for performing straightforward publish/subscribe messaging with a server that supports the MQTT protocol is made available by the
PubSubClient library (basically allows your ESP8266 to talk with Node- RED). 1. Save the PubSubClient library to your computer. Within your Downloads folder, there should be a folder labeled ".zip." 2. After you have unzipped the.zip folder, you should see a folder named pubsubclient-master. 3. Rename your folder's current name, which is pubsubclient-master, to just pubsubclient. 4. Transfer the pubsubclient folder to the libraries folder that was created during the installation of your Arduino IDE. 5. Next, reopen the Arduino IDE on your computer. The library includes several different examples in the form of sketches. Within the Arduino IDE software, navigate to the File > Examples > PubSubClient menu option. Installing Support for DHT Sensors in the Library Your ESP8266 or Arduino boards will be able to read temperature and humidity with ease when you use the DHT sensor library. This library makes it simple to use any DHT sensor. 1. Save the DHT sensor library to your computer. Within your Downloads folder, you ought to have a.zip folder. 2. After you have unzipped the.zip folder, you should have access to the DHT-sensor-library-master folder. 3. Rename your folder's current name, which is DHT-sensor-library- master, to simply DHT. 4. Transfer the DHT folder to the libraries folder that was created during the installation of your Arduino IDE. 5. Once you have done that, reopen your Arduino IDE.
Selecting the right board on Arduino IDE You also need to make sure that you select the appropriate board when using
the Arduino IDE
Project build note1. Navigate to the Tools menu and select "NodeMCU 1.0 (ESP-12E Module)" from the drop-down menu. 2. Under Tools > Port > COM4, choose the port number that corresponds to your ESP (in my case) Uploading code You are now able to upload the code that is listed below to your ESP8266. This piece of code publishes messages containing the temperature and humidity from the DHT11 sensor on the room/temperature and room/humidity topics using the MQTT protocol. The room/lamp topic is subscribed to by the ESP so that it can receive the messages that are published on that topic by the Node- RED application. These messages contain instructions for turning the lamp on and off. The areas of the code that require modifications have detailed comments attached to them. It is necessary for you to edit the code to include your personal RPi IP address, SSID, and password. This code is also compatible with other DHT sensors; all you need to do to select the appropriate sensor for your application is uncomment and comment the appropriate lines of code.
After you have uploaded the code and ensured that your Node-RED application and the Mosquito broker are both running on the Raspberry Pi, you can open the serial monitor in the Arduino IDE and set the baud rate to 115200 in order to view the events as they occur in real time. This is a useful method for determining whether or not the ESP has successfully established a connection to both your router and the Mosquito broker. You are also able to view the messages that the ESP is publishing as well as receiving. Building the Circuit The components and diagrams of the circuit that you will need to construct for this project are presented in the following sections.
Parts required
Project build noteTo construct the circuit, you will need the following components Raspberry Pi ESP8266 (ESP-12E Nodemcu) DHT11 temperature and humidity sensor Breadboard resistors 330 ohm and 4700-ohm LED resistor
Demonstration
Project build noteCongratulations! The work on your project is now finished. To control the ESP using the Node-RED application, navigate to the http://your-pi-ip- address/ui website address. You are able to use any web browser, as long as it is connected to the same network as your Raspberry Pi. The application should look something the figure below.
In this project, we showed you how to use Node-RED and MQTT to control ESP lights and sensors. You can construct more complex projects by building on top of these fundamental steps.
You built ESP8266 in conjunction with Node-RED and MQTT.
You followed the full workflow from understanding the mission to testing the finished project. That is a real engineering achievement - well done.
Browse all 500 projects