Arduino Nano ESP32 - LED Module

In this guide, we will learn how to use a 10mm LED module with the Arduino Nano ESP32. A bare LED on a breadboard needs a resistor and the right polarity, and the 3.3V pins of the Nano ESP32 can only push a small current. The LED module solves both problems on its own small board. In detail, we will learn:

Arduino Nano ESP32 and 10mm LED module

The Nano ESP32 has WiFi built in, so one small light like this is a handy way to show a status later on: connected, waiting, or error.

Hardware Preparation

1×Arduino Nano ESP32
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×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano ESP32

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

Look at the module and you will see a big 10mm diffused round LED sitting on a small black board, about 20mm x 20mm. Put simply, it is an LED that already has its resistor and its driver on the board. A 330Ω resistor limits the LED current, and a small transistor turns the LED on and off. The LED takes its power from the VCC pin, not from the signal pin. The IN pin only tells the transistor what to do, through a 1KΩ resistor, so the Nano ESP32 pin gives just a tiny current. That is why the light stays bright and even, though the board's pins work at 3.3V.

LED module pinout
image source: diyables.io

The module comes in a pack of five colors: red, yellow, blue, green and white. A 3-pin male header (2.54mm pitch, right-angle pins) is already soldered on. From one side to the other, the pins are labeled GND, VCC and IN:

  • GND pin: connect to GND (0V)
  • VCC pin: connect to 3.3V or 5V. On the Nano ESP32, the 3V3 pin is the easy choice.
  • IN pin: connect to a digital output pin of the Arduino Nano ESP32. Pick a PWM pin if you want to dim the LED.

How the IN pin controls the light (active HIGH):

  • IN is HIGH → the LED is ON.
  • IN is LOW → the LED is OFF.
  • IN gets a PWM signal → the LED glows at part brightness. A bigger duty cycle gives a brighter light.

Quick specs:

  • Supply voltage: 3.3V to 5V DC
  • LED: 10mm, diffused, round
  • Board size: 20mm x 20mm
  • Control: active HIGH, PWM accepted

The module is not only for learning. You can use it as a power or WiFi status light, a fault or alarm lamp, a "heartbeat" that shows your sketch is still running, or as one of the lights in a small traffic-light model.

Wiring Diagram

Only three short wires are needed and nothing else goes on the breadboard: GND to GND, VCC to the 3V3 pin, and IN to pin D5. D5 is the same pin used in the Arduino Nano ESP32 - LED - Blink tutorial, and it supports PWM, so both sketches below work without moving any wire.

The wiring diagram between Arduino Nano ESP32 and LED module

This image is created using Fritzing. Click to enlarge image

Wiring table of LED Module and Arduino Nano ESP32

LED Module Arduino Nano ESP32
GND → GND
VCC → 3V3
IN → D5

If your Nano ESP32 is powered from USB, you can also feed VCC from the VBUS pin (5V). The LED gets a bit brighter, and the IN pin still works fine with the 3.3V signal from D5.

How To Program For LED Module

No library is needed. The sketches use only functions that are built into the Arduino core for the Nano ESP32.

  • Give the IN pin a name:
const int LED_MODULE_PIN = D5;
  • Make the pin an output in setup():
pinMode(LED_MODULE_PIN, OUTPUT);
  • Turn the LED ON and OFF:
digitalWrite(LED_MODULE_PIN, HIGH); // ON digitalWrite(LED_MODULE_PIN, LOW); // OFF
  • Set a brightness level from 0 (off) to 255 (full):
analogWrite(LED_MODULE_PIN, 128); // about half brightness

Arduino Nano ESP32 Code - LED Module Fade

Now let's control the brightness, not just ON and OFF. The sketch below raises the PWM value from 0 to 255 in steps of 17, one step every 100 milliseconds, then brings it back down to 0. One full breath takes about three seconds.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-led-module */ const int LED_MODULE_PIN = D5; // Arduino Nano ESP32 PWM pin connected to the IN pin of the LED module const int FADE_STEP = 17; // brightness change per step (255 / 17 = 15 steps) const int STEP_DELAY = 100; // time between two steps, in milliseconds void setup() { Serial.begin(9600); pinMode(LED_MODULE_PIN, OUTPUT); } void loop() { // get brighter: 0 -> 255 for (int brightness = 0; brightness <= 255; brightness += FADE_STEP) { analogWrite(LED_MODULE_PIN, brightness); // PWM duty cycle sets the brightness Serial.print("Brightness: "); Serial.println(brightness); delay(STEP_DELAY); } // get dimmer: 255 -> 0 for (int brightness = 255 - FADE_STEP; brightness >= 0; brightness -= FADE_STEP) { analogWrite(LED_MODULE_PIN, brightness); Serial.print("Brightness: "); Serial.println(brightness); delay(STEP_DELAY); } }

Detailed Instructions

  • Keep the same wiring. D5 already supports PWM.
  • Copy the fade code above, paste it into the Arduino IDE and click Upload.
  • Look at the LED: it slowly gets brighter, then slowly fades out, and repeats.
  • Open the Serial Monitor (9600 baud) to follow the brightness values.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano ESP32
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano ESP32' on 'COM15')
New Line
9600 baud
Brightness: 0 Brightness: 17 Brightness: 34 Brightness: 51 Brightness: 68 Brightness: 85 Brightness: 102 Brightness: 119 Brightness: 136 Brightness: 153 Brightness: 170 Brightness: 187 Brightness: 204 Brightness: 221 Brightness: 238 Brightness: 255 Brightness: 238 Brightness: 221 Brightness: 204
Ln 11, Col 1
Arduino Nano ESP32 on COM15
2

Want a smoother fade? Make FADE_STEP smaller (for example 5) and STEP_DELAY shorter (for example 20). For a fade that does not block other code, see the Arduino Nano ESP32 - LED - Fade tutorial. It also works with this module, since you only change the pin.

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!