Arduino UNO R4 - LED Module

In this guide, we will learn how to use a 10mm LED module with the Arduino UNO R4. The module is a ready-made light: three labeled pins, no resistor to pick and no legs to get the wrong way round. In detail, we will learn:

Arduino UNO R4 and 10mm LED module

Overview of LED Module

The LED module is a small 20mm x 20mm black board with one big 10mm diffused LED on top. The diffused lens spreads the light, so the LED looks like an even glowing dot from any angle, not a sharp point. A pack comes with five colors: red, yellow, blue, green and white.

You can think of it as an LED that already has its helper parts on board. A 330Ω resistor limits the LED current, and a tiny transistor does the switching. The LED takes its power from the VCC pin. The IN pin only tells the transistor to open or close, so the Arduino UNO R4 pin gives almost no current.

This matters on the Arduino UNO R4. Its pins work at 5V, but each pin can give only about 8mA, which is less than the classic Arduino UNO. With a bare LED, the pin must feed the LED by itself. With the module, the pin only sends the signal, so the LED stays bright and the pin stays safe.

LED module pinout
image source: diyables.io

The module has a 3-pin header with right-angle pins, already soldered:

  • GND pin: connect to GND (0V) of the Arduino UNO R4.
  • VCC pin: connect to 5V (3.3V also works).
  • IN pin: connect to a digital output pin. HIGH turns the LED on, LOW turns it off. A PWM signal on this pin dims the LED.
LED Module
LED 10mm, diffused, round
Colors red, yellow, blue, green, white
Operating voltage 3.3V to 5V DC
Control active HIGH (IN = HIGH means LED ON)
Brightness control yes, with PWM on the IN pin
On-board parts 330Ω LED resistor, 1KΩ input resistor, transistor switch
Board size 20mm x 20mm

If you used a normal LED before, as in the Arduino UNO R4 - Blink LED tutorial, here are the main changes:

  • No 220Ω resistor is needed. The module has its own.
  • No polarity to check. You read the pin labels instead of looking for the long leg.
  • No breadboard is needed. Three jumper wires are enough.

Wiring Diagram

The module needs only three wires: GND to GND, VCC to the 5V pin, and IN to pin 9. We use pin 9 because it is a PWM pin (marked with ~ on the board), so the same wiring works for the blink code and the fade code.

LED Module Pin Arduino UNO R4 Pin
GND GND
VCC 5V
IN 9
The wiring diagram between Arduino UNO R4 LED module

This image is created using Fritzing. Click to enlarge image

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

How To Program For LED Module

No library is needed. Two built-in functions do all the work.

  • Set the pin on Arduino UNO R4 that connects to the IN pin of the module:
const int LED_MODULE_PIN = 9;
  • Make the pin an output:
pinMode(LED_MODULE_PIN, OUTPUT);
  • Turn the LED on or off:
digitalWrite(LED_MODULE_PIN, HIGH); // LED on digitalWrite(LED_MODULE_PIN, LOW); // LED off
  • Set a brightness level from 0 (off) to 255 (full):
analogWrite(LED_MODULE_PIN, 128); // about half brightness

Arduino UNO R4 Code - Fade LED Module

Now let's control the brightness. The sketch below uses analogWrite() on pin 9. The PWM value climbs from 0 to 255 in steps of 5, then falls back to 0. One full fade-in takes about 1 second, and one fade-out takes about 1 second too. A message is printed only at the two ends, so the Serial Monitor does not fill up.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-led-module */ const int LED_MODULE_PIN = 9; // Arduino UNO R4 PWM pin (~9) connected to the IN pin of the LED module int brightness = 0; // current PWM value: 0 (dark) to 255 (full brightness) int step = 5; // how much the brightness changes each time void setup() { Serial.begin(9600); pinMode(LED_MODULE_PIN, OUTPUT); } void loop() { analogWrite(LED_MODULE_PIN, brightness); // send the PWM value to the IN pin // print a message at both ends of the fade if (brightness == 255) Serial.println("Full brightness (255), now fading out"); else if (brightness == 0) Serial.println("LED module dark (0), now fading in"); brightness = brightness + step; // get the next brightness value // turn around at the ends: 0 -> 255 -> 0 if (brightness <= 0 || brightness >= 255) step = -step; delay(20); // a short pause so the eye can see the change }

Detailed Instructions

  • Keep the same wiring. The IN pin is already on pin 9, which supports PWM.
  • Copy the code above into a new sketch in the Arduino IDE.
  • Click the Upload button.
  • Watch the LED module: it slowly gets brighter, then slowly gets dimmer, like breathing.
  • Check the Serial Monitor:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
LED module dark (0), now fading in Full brightness (255), now fading out LED module dark (0), now fading in Full brightness (255), now fading out LED module dark (0), now fading in Full brightness (255), now fading out
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

※ NOTE THAT:

If the LED only turns fully on and off with no smooth fade, the IN wire is on a pin without PWM. Move it to pin 9 (or another pin marked with ~, such as 3, 5, 6, 10 or 11) and change LED_MODULE_PIN to match.

Want to know more about PWM fading, or a fade that does not use delay()? See the Arduino UNO R4 - Fade LED tutorial.

Project Ideas

Here are some ways to put the LED module to work with the Arduino UNO R4:

  • A Wi-Fi status light: on the Arduino UNO R4 WiFi, keep a green module on while the board is connected to your router, and blink a red one when the connection is lost.
  • A heartbeat light: let a white module fade in and out slowly, so you can see at a glance that your sketch is still running.
  • A traffic light model: put a red, a yellow and a green module side by side and switch them in turn.
  • A fault alarm: blink a red module fast when a sensor reading goes over a limit.

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!