ESP8266 - LED Module
This tutorial instructs you how to use the ESP8266 NodeMCU to drive a 10mm LED module, a ready-made light that plugs in with three jumper wires. A bare LED on a 3.3V board brings two small worries: which leg is which, and what resistor to add. The LED module removes both, so it is a handy first output part for a NodeMCU project. In detail, we will learn:
- What sits on the small LED module board, and how its GND, VCC and IN pins work
- How to wire the module to the NodeMCU, with the IN pin on D5 (GPIO14)
- How to program the ESP8266 to switch the LED module on and off once per second and report each change on the Serial Monitor
- How to program the ESP8266 to brighten and dim the LED module smoothly with analogWrite()

We suggest:
- Utilizing a plain LED if you want to learn how a bare LED, its polarity and its series resistor work.
- Utilizing the LED fade tutorial to see fading without delay(), or the RGB LED tutorial if one color is not enough.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.
Overview of LED Module

Put simply, the LED module is an LED that already has its resistor and its driver soldered next to it. The board is a black 20mm x 20mm square with one 10mm diffused round LED on top. The diffused lens spreads the light evenly, so the LED is easy to see from the side and does not dazzle when you look at it head-on. DIYables sells it as a set of five colors: red, yellow, blue, green and white.
Behind the LED, the board carries three small parts: a 330Ω resistor that limits the LED current, a 1KΩ resistor on the IN line, and a tiny transistor that works as a switch. The LED takes its current from the VCC pin, not from the NodeMCU pin. The IN pin only tells the transistor to open or close. This matters on the ESP8266, because a GPIO pin of this chip can give only a small current. With the module, the pin does almost no work, and the LED is just as bright as it would be on a 5V board.
| LED Module | |
|---|---|
| LED | 10mm, diffused, round |
| Colors in the pack | red, yellow, blue, green, white |
| Board size | 20mm x 20mm |
| Operating voltage | 3.3V to 5V DC |
| On-board parts | 330Ω LED resistor, 1KΩ input resistor, transistor switch |
| Control logic | active HIGH (IN = HIGH turns the LED on) |
| Brightness control | yes, with PWM on the IN pin |
| Connector | 3-pin 2.54mm right-angle male header, presoldered |
The LED Module Pinout
The three header pins are printed on the board in this order: GND, VCC, IN.
- GND pin: must be connected to a G (GND) pin of the NodeMCU (0V)
- VCC pin: must be connected to the 3V3 pin of the NodeMCU (5V also works for the module, but 3.3V is the natural choice here)
- IN pin: must be connected to a NodeMCU output pin. Use a PWM-capable pin such as D5 so that fading also works
What the IN pin does to the LED:
- IN at LOW (0V): the transistor is off, and the LED is OFF.
- IN at HIGH (3.3V): the transistor is on, and the LED is fully ON.
- IN with a PWM signal: the LED switches on and off very quickly, so it looks dimmer. A higher PWM value gives a brighter light.
※ NOTE THAT:
The arrangement of pins on a module may differ from one manufacturer to another. It is essential to always refer to the labels printed on the module when using it. Take a close look!
Wiring Diagram
Only three wires are needed. The module gets its power from the 3V3 and G pins of the NodeMCU, and its IN pin listens to D5.

This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
| LED Module | ESP8266 NodeMCU |
|---|---|
| GND | → G (GND) |
| VCC | → 3V3 |
| IN | → D5 (GPIO14) |
Do you want another pin? D1, D2, D6 and D7 are also fine, and all of them can make PWM. Do not pick D0 (GPIO16), because it cannot output PWM. It is also wise to avoid D3, D4 and D8: the chip reads these pins at boot, so the LED may flash or the board may not start. Remember to change the pin name in the code as well.
How To Program For LED Module
No library is required. The ESP8266 core for Arduino IDE already has every function used below.
- The first step is to give a name to the NodeMCU pin that is wired to the IN pin of the module:
- Next, the pin is set up as a digital output with the pinMode() function:
- To set a brightness level, write a PWM value with the analogWrite() function:
On the ESP8266 core 3.x, analogWrite() takes a value from 0 to 255, where 0 is off and 255 is full brightness. Very old cores (2.x) used 0 to 1023, so if the LED never reaches full brightness, update the ESP8266 core in the Boards Manager.
ESP8266 NodeMCU Code for LED Module - Blink
This first sketch turns the LED module on for one second and off for one second, forever. It also counts the blinks and prints every change to the Serial Monitor, so you can follow the board even when the LED is out of sight.
Detailed Instructions
- If this is the first time you use ESP8266, see how to setup environment for ESP8266 on Arduino IDE.
- Wire the LED module to the NodeMCU as shown in the table and diagram above.
- Connect the ESP8266 NodeMCU board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Pick the board NodeMCU 1.0 (ESP-12E Module) and the COM port of your NodeMCU.
- Copy the code above and paste it into a new sketch in Arduino IDE.
- Press the Upload button and wait until the upload is done.
- Open the Serial Monitor and set it to 9600 baud.
- Look at the LED module. It lights up for one second, goes dark for one second, and keeps going.
- The Serial Monitor shows lines like these:
※ NOTE THAT:
The sketch uses delay(), which stops the ESP8266 from doing anything else while it waits. If your project must also read sensors or keep WiFi busy at the same time, see the non-blocking method.
ESP8266 NodeMCU Code for LED Module - Fade
The second sketch drives the IN pin with PWM. The value climbs from 0 to 255 in steps of 15, then falls back to 0 at the same pace, so the LED glows up and fades out like slow breathing. A short dark pause follows, and the cycle starts again.
Detailed Instructions
- Keep the same wiring. The IN pin stays on D5.
- Paste the code above into a new sketch and press Upload.
- Watch the LED module. Its light grows from off to full, then drops back to off, about once every two seconds.
- Open the Serial Monitor (9600 baud) to follow the PWM value. A shortened sample:
Try a smaller FADE_STEP (for example 5) for a smoother fade, or a larger STEP_DELAY for a slower one.
Additional Knowledge
LED Module vs Bare LED on the ESP8266
| Question | LED Module | Bare LED |
|---|---|---|
| Needs an external resistor? | No, 330Ω is on the board | Yes, in series with the LED |
| Polarity to check? | No, pins are labeled GND, VCC, IN | Yes, anode (+) and cathode (-) |
| Where does the LED current come from? | The VCC pin | The GPIO pin itself |
| Breadboard needed? | No, three jumper wires are enough | Usually yes, to hold the LED and resistor |
| Can it fade with PWM? | Yes | Yes |
It is evident that the LED module is the quicker and safer choice for a NodeMCU project, while the bare LED is better when you want to learn how the resistor and the polarity work.
Ideas for Using the LED Module
- WiFi status light: keep it on while the NodeMCU is connected, and blink it while it tries to reconnect.
- Fault or alarm light: turn on a red module when a sensor value goes out of range.
- Heartbeat light: a slow fade shows that the sketch is still running.
- Traffic-light model: use a red, a yellow and a green module on three pins.
The same IN-pin logic also works for a buzzer or a relay module. For devices that need more power than a GPIO pin, see ESP8266 - Relay.