Arduino UNO R4 - LED Strip

Discover how to program the Arduino Uno R4 to control 12V LED strips in this beginner-friendly tutorial. From single-color to RGB LED strips, learn to use relays for dynamic lighting projects. Here’s what you’ll learn:

A relay can only switch the strip fully on or fully off. A MOSFET module switches it too, without any click, and it can make the light brighter or dimmer.

Start your journey into Arduino programming and LED strip projects today!

Overview of LED Strip

A LED strip, also called LED tape or LED ribbon, is a flexible board with LEDs that shine light. These strips are flexible and used often for decorative lights in many places. LED strips are available in different colors and are mainly used to create a soft glow, highlight specific areas, or add decorative light effects.

LED strips are available in two primary varieties:

  • Addressable LED Strips: In this type, you can control the color and brightness of each LED separately. Each LED has its own unique address that allows this individual control.
  • Non-Addressable LED Strips: With these strips, you can change the color and brightness too, but the change affects all the LEDs on the strip at the same time.

This guide is about Non-Addressable LED Strips. For Addressable LED Strips, see the other guides provided.

To dim a non-addressable strip, you can use a MOSFET module. Its pinout and its working are in the Arduino UNO R4 - MOSFET Module tutorial.

Relay vs MOSFET Module for a LED Strip

Relay MOSFET Module
Light control on or off on, off, and brightness (PWM dimming)
Click sound yes no, silent
Reaction time a few milliseconds very short
Lifetime contacts wear with each switch long, no moving parts
Power type AC or DC DC only
Strip voltage as the relay allows 6V or more (12V and 24V strips are fine)
Isolation yes, coil and contacts yes, PC817 optocoupler
Best for AC lights, plain on/off DC strips that need dimming or fast effects

For a 12V strip, the MOSFET module is the nicer choice because you can set the brightness. An RGB strip has three color pins (R, G, B), so it needs three MOSFET modules, one for each color, in the same way that it needs three relays.

Non-Addressable LED Strip Pinout

There are two main types of Non-Addressable LED Strips.

  • Non-Addressable 1-color LED strip: Comes in only one color set by the manufacturer.
  • Non-Addressable RGB LED strip: Can show many colors.

A Non-Addressable 1-color LED Strip typically has two pins:

  • 12V/24V pin: Connect this to the positive pin of a 12V or 24V DC power supply.
  • GND pin: Connect this to the negative pin of a 12V or 24H DC power supply.

A Non-Addressable RGB LED Strip typically has four pins:

  • 12V/24V pin: Connect this to the positive pin of a 12V or 24V DC power supply.
  • R pin: Use this pin for red color control. Connect it to the power supply's negative pin to activate red color.
  • G pin: Use this pin for green color control. Connect it to the power supply's negative pin to activate green color.
  • B come: Use this pin for blue color control. Connect it to the power supply's negative pin to activate blue color.
Arduino UNO R4 non-addressable led strip Pinout

We will learn how to control both types using the Arduino UNO R4, one at a time.

How to Control a Non-Addressable 1-color LED strip.

When you connect a 12V LED strip to a 12V power supply, it will light up. To control this 12V LED strip using an Arduino UNO R4, you must use a relay. The Arduino UNO R4 controls the 12V LED strip through the relay. If you are not familiar with relays, such as their pinouts, functions, or programming, you can learn more by visiting the Arduino UNO R4 - Relay tutorial at Arduino UNO R4 - Relay tutorial.

Wiring Diagram.

Wiring Diagram between Arduino UNO R4 and Non-Addressable 1-color LED strip.

The wiring diagram between Arduino UNO R4 12V LED strip

This image is created using Fritzing. Click to enlarge image

Wiring Diagram between Arduino UNO R4 and Non-Addressable RGB LED strip.

The wiring diagram between Arduino UNO R4 12V LED strip

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 Code

Arduino UNO R4 Code for controlling Non-Addressable 1-color LED strip.

This code will continuously turn the LED strip on for 5 seconds and then off for 5 seconds.

/* * 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-strip */ #define LED_STRIP_PIN 3 // The Arduino Uno R4 pin controls to the LED strip via relay void setup() { Serial.begin(9600); // initialize Arduino pins as digital output pins pinMode(LED_STRIP_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { Serial.println("The LED strip is turned on"); digitalWrite(LED_STRIP_PIN, HIGH); delay(5000); Serial.println("The LED strip is turned off"); digitalWrite(LED_STRIP_PIN, LOW); delay(5000); }

Arduino UNO R4 Code for controlling Non-Addressable RGB LED strip.

The code below repeatedly changes the colors of the RGB LED strip (red, green, blue, yellow, magenta, cyan, and white).

/* * 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-strip */ #define BLUE_PIN 5 // The Arduino Uno R4 pin connects to the blue pin of LED strip via relay 1 #define RED_PIN 6 // The Arduino Uno R4 pin connects to the red pin of LED strip via relay 2 #define GREEN_PIN 7 // The Arduino Uno R4 pin connects to the green pin of LED strip via relay 3 void setup() { Serial.begin(9600); // initialize Arduino pins as digital output pins pinMode(BLUE_PIN, OUTPUT); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { Serial.println("The LED strip is turned red"); digitalWrite(BLUE_PIN, LOW); digitalWrite(RED_PIN, HIGH); digitalWrite(GREEN_PIN, LOW); delay(2000); Serial.println("The LED strip is turned green"); digitalWrite(BLUE_PIN, LOW); digitalWrite(RED_PIN, LOW); digitalWrite(GREEN_PIN, HIGH); delay(2000); Serial.println("The LED strip is turned blue"); digitalWrite(BLUE_PIN, HIGH); digitalWrite(RED_PIN, LOW); digitalWrite(GREEN_PIN, LOW); delay(2000); Serial.println("The LED strip is turned yellow"); digitalWrite(BLUE_PIN, LOW); digitalWrite(RED_PIN, HIGH); digitalWrite(GREEN_PIN, HIGH); delay(2000); Serial.println("The LED strip is turned magenta"); digitalWrite(BLUE_PIN, HIGH); digitalWrite(RED_PIN, HIGH); digitalWrite(GREEN_PIN, LOW); delay(2000); Serial.println("The LED strip is turned cyan"); digitalWrite(BLUE_PIN, HIGH); digitalWrite(RED_PIN, LOW); digitalWrite(GREEN_PIN, HIGH); delay(2000); Serial.println("The LED strip is turned white"); digitalWrite(BLUE_PIN, HIGH); digitalWrite(RED_PIN, HIGH); digitalWrite(GREEN_PIN, HIGH); delay(2000); }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the the LED strip to Arduino Uno R4 according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the code provided above and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to transfer the code to your Arduino UNO R4.
  • Observe the condition of the LED strip.

Code Explanation

The explanation is in the comments of the Arduino code above.

To adjust the brightness and colors of a non-addressable LED strip, we must use a driver like L298N driver instead of a relay.

Arduino UNO R4 Code - Dim LED Strip with MOSFET Module

Here a MOSFET module replaces the relay for the 1-color LED strip. The Arduino UNO R4 sends a PWM signal, and the strip gets brighter or dimmer.

Wiring Diagram between Arduino UNO R4, MOSFET Module and 1-color LED strip.

The wiring diagram between Arduino UNO R4 LED strip MOSFET 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.

  • Arduino UNO R4 pin 9 → PWM pin of the module
  • Arduino UNO R4 GND → GND pin of the module
  • 12V adapter + → + terminal
  • LED strip 12V pin → + terminal (shared with the adapter +)
  • LED strip GND pin → LOAD terminal
  • 12V adapter − → − terminal

An LED strip has no coil, so you do not need a flyback diode.

Arduino UNO R4 Code for dimming the 1-color LED strip.

/* * 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-strip */ const int MOSFET_PIN = 9; // Arduino UNO R4 pin connected to the PWM pin of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); analogWrite(MOSFET_PIN, 0); // start with the load OFF } void setLoad(int percent) { int duty = map(percent, 0, 100, 0, 255); // convert 0-100% to 0-255 analogWrite(MOSFET_PIN, duty); Serial.print("Load power: "); Serial.print(percent); Serial.println("%"); } void loop() { // turn the load fully ON, then fully OFF Serial.println("Load: ON"); setLoad(100); delay(2000); Serial.println("Load: OFF"); setLoad(0); delay(2000); // increase the power step by step (PWM) for (int percent = 10; percent <= 100; percent += 10) { setLoad(percent); delay(500); } // decrease the power step by step (PWM) for (int percent = 90; percent >= 0; percent -= 10) { setLoad(percent); delay(500); } delay(1000); }

The strip shines at full brightness for 2 seconds, then turns dark for 2 seconds. After that it fades up from 10% to 100% and fades back down to 0%, then the loop starts again.

Detailed Instructions

  • Set up the Arduino IDE as described in the relay Quick Steps above.
  • Wire the LED strip and the MOSFET module as in the diagram, with the 12V adapter unplugged.
  • Upload the code to the Arduino UNO R4.
  • Plug in the 12V adapter.
  • Open the Serial Monitor and choose 9600 baud.
  • Watch the strip become brighter and then dimmer, step by step.
∞
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
Load: ON Load power: 100% Load: OFF Load power: 0% Load power: 10% Load power: 20% Load power: 30% Load power: 40% Load power: 50% Load power: 60% Load power: 70% Load power: 80% Load power: 90% Load power: 100% Load power: 90% Load power: 80% Load power: 70% Load power: 60% Load power: 50% Load power: 40% Load power: 30% Load power: 20% Load power: 10% Load power: 0%
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

Note: the MOSFET module only works with DC power, and the strip supply must be about 6V or higher. A 5V strip will not work well with it, and AC lights need the 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!