Arduino - LED Module

In this tutorial, we are going to learn:

Arduino LED Module

Hardware Required

1×Official Arduino Uno
1×Alternatively, DIYables STEM V3, Fully Compatible with Arduino Uno R3
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×LED Module
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables STEM V3 Starter Kit (Arduino included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .

Buy Note: To simplify the wiring process, we recommend using the LED Module, which comes with a built-in resistor.

About LED Module

Think of the LED module as an LED that comes "ready to plug in". The 10mm diffused LED, its 330Ω resistor and a tiny transistor switch are all soldered on a small 20mm x 20mm board. Arduino only tells the transistor when to switch. The LED itself takes its power from the VCC pin, not from the Arduino output pin. This is why the wiring is short and you do not need to pick a resistor value.

The module is sold as a pack of five colors: red, yellow, blue, green and white. All five work the same way and use the same code.

LED Module
LED 10mm, diffused, round
Colors red, yellow, blue, green, white
Operating Voltage 3.3V to 5V DC
Control Logic active HIGH (HIGH = ON, LOW = OFF)
On-board Parts 330Ω LED resistor, 1KΩ input resistor, transistor switch
Header 3-pin, 2.54mm, right-angle, presoldered
Board Size 20mm x 20mm

Pinout

LED Module Pinout
image source: diyables.io

The three header pins are printed on the board in this order: GND, VCC, IN.

  • GND pin: needs to be connected to GND (0V)
  • VCC pin: needs to be connected to VCC (5V, or 3.3V). The LED current comes from this pin.
  • IN pin: needs to be connected to an Arduino output pin. HIGH turns the LED ON, LOW turns it OFF, and a PWM signal sets its brightness.

How is it different from a bare LED, like the one in the Arduino - LED - Blink tutorial?

  • A bare LED needs a series resistor (for example 220Ω). The module already has one on board.
  • A bare LED has an anode(+) and a cathode(-), and it does not light up if you turn it the wrong way. The module has clear labels, so you just match GND to GND, VCC to 5V and IN to the signal pin.
  • With a bare LED, the Arduino pin gives all the LED current. With the module, the pin only drives the transistor, so it gives a very small current.

Wiring Diagram

Connect the module's GND pin to Arduino GND, the VCC pin to the 5V pin, and the IN pin to digital pin 9, as shown in the image below.

Arduino LED Module Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Pin 9 is used because it has the "~" mark on the Arduino Uno board, which means it can create PWM. We need PWM for the fade example. If you only want ON/OFF, any digital pin works. Other PWM pins on the Uno are 3, 5, 6, 10 and 11.

How To Program For LED Module

  • No library is needed. The code uses only built-in Arduino functions.
  • Define the pin that goes to the IN pin of the module:
#define LED_MODULE_PIN 9
pinMode(LED_MODULE_PIN, OUTPUT);
digitalWrite(LED_MODULE_PIN, HIGH); // ON digitalWrite(LED_MODULE_PIN, LOW); // OFF
  • Set the brightness with analogWrite(). The value goes from 0 (OFF) to 255 (full brightness):
analogWrite(LED_MODULE_PIN, 64); // about one quarter brightness

Arduino Code - LED Module Fade

This sketch uses PWM to make the LED glow slowly brighter, then slowly dimmer. The brightness value goes up from 0 to 255 in steps of 15, then back down to 0. It works like a "breathing" status light.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-led-module */ #define LED_MODULE_PIN 9 // Arduino PWM pin (~9) connected to the IN pin of the LED module void setup() { Serial.begin(9600); pinMode(LED_MODULE_PIN, OUTPUT); } void loop() { // fade in: brightness goes up from 0 (OFF) to 255 (full) for (int brightness = 0; brightness <= 255; brightness += 15) { analogWrite(LED_MODULE_PIN, brightness); Serial.print("Brightness: "); Serial.println(brightness); delay(60); } // fade out: brightness goes down from 255 to 0 for (int brightness = 255; brightness >= 0; brightness -= 15) { analogWrite(LED_MODULE_PIN, brightness); Serial.print("Brightness: "); Serial.println(brightness); delay(60); } delay(500); // short pause while the LED is dark, then repeat }

Quick Steps

  • Keep the same wiring. The IN pin must stay on pin 9 (a PWM pin).
  • Copy the above code and paste it to Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Look at the LED module: it fades in, fades out, rests for half a second, and starts again.
  • Open the Serial Monitor (baud rate 9600). The part below shows the top of one cycle, where the fade-in ends and the fade-out begins.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
Brightness: 195 Brightness: 210 Brightness: 225 Brightness: 240 Brightness: 255 Brightness: 255 Brightness: 240 Brightness: 225 Brightness: 210 Brightness: 195
Ln 11, Col 1
Arduino Uno on COM15
2

※ NOTE THAT:

If the LED only blinks and does not fade, check that the IN wire is on a pin with the "~" mark. On a pin without PWM, analogWrite() gives only full ON (value 128 or more) or full OFF.

For a fade that does not block other code, see Arduino - LED - Fade. The same code works with the LED module; just keep the module on a PWM pin.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES