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:

ESP8266 NodeMCU NodeMCU LED module

We suggest:

Hardware Preparation

1×ESP8266 NodeMCU ESP-12F
1×Alternatively, ESP8266 D1 Mini NodeMCU ESP-12F
1×Alternatively, ESP8266 NodeMCU ESP-12E (Uno-form)
1×Micro USB Cable
1×Alternatively, ESP8266 NodeMCU ESP-12F (SMD-form)
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×LED Module
1×Jumper Wires
1×Breadboard
1×Recommended: Screw Terminal Expansion Board for ESP8266

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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

LED module pinout
image source: diyables.io

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.

The wiring diagram between ESP8266 NodeMCU and NodeMCU LED module

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:
#define LED_MODULE_PIN D5 // D5 = GPIO14
  • Next, the pin is set up as a digital output with the pinMode() function:
pinMode(LED_MODULE_PIN, OUTPUT);
  • To switch the LED module ON or OFF, write HIGH or LOW with the digitalWrite() function:
digitalWrite(LED_MODULE_PIN, HIGH); // LED ON digitalWrite(LED_MODULE_PIN, LOW); // LED OFF
  • To set a brightness level, write a PWM value with the analogWrite() function:
analogWrite(LED_MODULE_PIN, 128); // about half brightness

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 - 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.

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-led-module */ #define LED_MODULE_PIN D5 // ESP8266 pin D5 (GPIO14) connected to the IN pin of the LED module #define FADE_STEP 15 // how much the PWM value changes each step #define STEP_DELAY 60 // milliseconds to wait between steps void setup() { Serial.begin(9600); pinMode(LED_MODULE_PIN, OUTPUT); } void loop() { // fade in: PWM value goes from 0 (off) to 255 (full brightness) for (int value = 0; value <= 255; value += FADE_STEP) { analogWrite(LED_MODULE_PIN, value); Serial.print("Fade in, PWM = "); Serial.println(value); delay(STEP_DELAY); } // fade out: PWM value goes from 255 back down to 0 for (int value = 255; value >= 0; value -= FADE_STEP) { analogWrite(LED_MODULE_PIN, value); Serial.print("Fade out, PWM = "); Serial.println(value); delay(STEP_DELAY); } delay(500); // short dark pause before the next cycle }

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:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Nodemcu 1.0 (ESP-12E Module)
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Nodemcu 1.0 (ESP-12E Module)' on 'COM15')
New Line
9600 baud
Fade in, PWM = 0 Fade in, PWM = 15 Fade in, PWM = 30 Fade in, PWM = 45 ... Fade in, PWM = 240 Fade in, PWM = 255 Fade out, PWM = 255 Fade out, PWM = 240 Fade out, PWM = 225 ... Fade out, PWM = 15 Fade out, PWM = 0
Ln 11, Col 1
Nodemcu 1.0 (ESP-12E Module) on COM15
2

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.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!