Arduino Nano - LED Module

This tutorial instructs you how to use Arduino Nano to control a 10mm LED module, a small board that is ready to plug in. Because the resistor and the driver are already on the board, the Nano needs only three wires to it. In detail, we will learn:

Arduino Nano LED module

We suggest:

Hardware Preparation

1×Official Arduino Nano
1×Alternatively, DIYables Nano V3.0 Development Board
1×USB A to Mini-B USB cable
1×LED Module
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

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

The LED module is a 10mm diffused round LED, mounted on a small black PCB of 20mm x 20mm. The pack comes with five colors: red, yellow, blue, green and white. Think of it as an LED that already has its resistor and its driver on the board. A 330Ω resistor limits the LED current, a 1KΩ resistor sits on the IN line, and a small transistor works as a switch. The LED takes its power from VCC, and the IN pin only tells the transistor to open or close. So the Nano pin gives only a tiny current, and you do not need to add any resistor.

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
Control logic active HIGH (IN = HIGH → LED ON)
Brightness control yes, with PWM on the IN pin
Header 3-pin, 2.54mm, right-angle, presoldered

The LED Module Pinout

LED module pinout
image source: diyables.io

The 3-pin header is labeled GND, VCC and IN, in this order:

  • GND pin: must be connected to GND (0V)
  • VCC pin: must be connected to 5V (or 3.3V). This pin feeds the LED
  • IN pin: must be connected to a digital output pin of Arduino Nano. HIGH turns the LED ON, LOW turns it OFF, and a PWM signal sets the brightness

※ 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

The module gets its power from the 5V pin of the Nano, and its IN pin goes to pin D5, which is a PWM pin (marked with ~), so the same wiring works for both the blink code and the fade code.

The wiring diagram between Arduino Nano and LED module

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Nano and other components.

LED Module Arduino Nano
GND GND
VCC 5V
IN D5

How To Program For LED Module

No library is needed. Only the built-in Arduino functions are used.

  • The first step is to specify the Arduino Nano pin that is connected to the IN pin of the module:
#define LED_MODULE_PIN 5
  • Configure that pin as an output in setup() with pinMode():
pinMode(LED_MODULE_PIN, OUTPUT);
digitalWrite(LED_MODULE_PIN, HIGH); // LED ON digitalWrite(LED_MODULE_PIN, LOW); // LED OFF
  • To set a brightness level, write a value from 0 (off) to 255 (full) with analogWrite():
analogWrite(LED_MODULE_PIN, 128); // about half brightness

Arduino Nano Code for LED Module - Fade

The second sketch uses PWM on pin D5. The brightness climbs from 0 to 255 in steps of 5, then drops back to 0 in the same steps. The LED stays dark for half a second, and the cycle starts again.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-led-module */ #define LED_MODULE_PIN 5 // The Arduino Nano PWM pin (~D5) connected to the IN pin of the LED module // The setup function runs once on reset or power-up void setup() { Serial.begin(9600); // start the Serial Monitor at 9600 baud pinMode(LED_MODULE_PIN, OUTPUT); // set the pin as an output } // The loop function repeats indefinitely void loop() { // fade in: brightness goes up from 0 (OFF) to 255 (full) Serial.println("Fading in..."); for (int brightness = 0; brightness <= 255; brightness += 5) { analogWrite(LED_MODULE_PIN, brightness); // PWM value on the IN pin delay(20); // short pause to see the change } // fade out: brightness goes down from 255 (full) to 0 (OFF) Serial.println("Fading out..."); for (int brightness = 255; brightness >= 0; brightness -= 5) { analogWrite(LED_MODULE_PIN, brightness); delay(20); } delay(500); // stay dark for half a second before the next cycle }

Detailed Instructions

  • Keep the same wiring. Nothing needs to change, because D5 already supports PWM.
  • Copy the fade code above and paste it into Arduino IDE.
  • Click the Upload button.
  • Watch the LED: it slowly gets brighter, then slowly gets dimmer, in a smooth "breathing" effect.
  • The Serial Monitor shows when each half of the cycle starts:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano' on 'COM15')
New Line
9600 baud
Fading in... Fading out... Fading in... Fading out... Fading in...
Ln 11, Col 1
Arduino Nano on COM15
2

※ NOTE THAT:

If the LED only blinks ON and OFF and does not fade, check that the IN wire is on D5 (or another pin marked with ~, such as D3, D6, D9, D10 or D11). On a pin without PWM, analogWrite() can only give fully ON or fully OFF.

Additional Knowledge

LED Module vs Bare LED

LED Module Bare LED
Series resistor on the board you must add one (for example 220Ω)
Polarity labeled pins (GND, VCC, IN) you must find the anode (+) and cathode (-)
Current from the Nano pin very small (the transistor drives the LED) the full LED current
Brightness fixed by the board, does not depend on the pin depends on the pin and the resistor
Pins 3 2

It is evident that the LED module is easier and safer for a quick indicator, while a bare LED is better when you want to learn the basics or save space.

Project Ideas

  • A power or "system ready" light on the front of a box
  • An alarm or fault light that turns red when a sensor reads a bad value
  • A small traffic-light model with the red, yellow and green modules
  • A heartbeat light that fades slowly while the Nano is running

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!