ESP32 UNO - LED Strip

Need your ESP32 Uno LED strip to blink, change color or fade? Hook a 12V LED tape to the ESP32 Uno form board through a relay, and a few lines of Arduino code take over the light. The same build works for a 12V RGB LED strip, which can show seven mixed colors. For smooth brightness control, swap the relay for a silent MOSFET module.

What you will do:

  1. Tell addressable and non-addressable LED ribbons apart
  2. Wire a relay module between the board and a 12V LED strip
  3. Run code that switches a single-color strip on a timer
  4. Mix red, green and blue relays into seven colors on an RGB strip
  5. Dim a 12V LED tape with PWM through a MOSFET module

https://newbiely.com/images/cover/esp32-uno-controls-led-strip.jpg

Components You Need

1×ESP32 Uno-form Board
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×Relay
1×Alternatively, MOSFET Module (AOD4184, LR7843 or FR120N)
1×12V 1-color LED Strip
1×12V RGB LED Strip
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires

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 .

LED Strip Basics

After this part, you know which kind of strip this guide drives.

An LED strip (LED tape, LED ribbon) is a bendable printed board with rows of LEDs glued along it. Makers stick it behind monitors, along stairs or inside shelves for accent light.

Strip Kind How It Is Controlled Covered Here?
Addressable each LED has its own address, so every LED gets its own color and level no
Non-addressable all LEDs share the same wires, so the whole strip changes together yes

Good to know: addressable strips (NeoPixel, WS2812B, DotStar) need a data signal and a library. This page only handles the simpler non-addressable 12V type.

To dim a non-addressable strip, a MOSFET module does the job. Its pins and its working are explained in the ESP32 Uno - MOSFET Module tutorial.

Relay or MOSFET Module?

Pick your switching part here, before you buy or wire anything.

Feature Relay MOSFET Module
What it can do full on or full off on, off and any level in between (PWM)
Sound audible click none
Switch time several milliseconds microseconds
Life span contacts wear out with use no moving parts, lasts long
Supply type AC or DC DC only
Strip supply voltage up to the relay rating around 6V and up (12V and 24V work)
Isolation coil and contacts are separate PC817 optocoupler
Pick it for mains lamps, plain switching DC strips with dimming or quick effects

For a 12V strip, the MOSFET module wins because you get brightness control. An RGB strip has three color wires, so it takes three MOSFET modules, just like it takes three relays.

Non-Addressable LED Strip Pins

By the end of this part, you can name every wire on your strip.

Single-color strip

The LED color is set in the factory. There are two pads:

Pad Goes To
12V/24V plus (+) side of the 12V or 24V DC adapter
GND minus (-) side of the 12V or 24V DC adapter

RGB strip

Three separate color lines let you build many colors. There are four pads:

Pad Goes To
12V/24V plus (+) side of the DC adapter
R red line. Pull it to the adapter minus (-) and red lights up
G green line. Pull it to the adapter minus (-) and green lights up
B blue line. Pull it to the adapter minus (-) and blue lights up
ESP32 Uno non-addressable LED strip pinout

The sections below drive each strip type from the ESP32 Uno, one after the other.

Switching a Single-Color Strip with a Relay

Here you see why a relay sits between the board and the strip.

A 12V strip glows the moment it meets a 12V supply. The ESP32 Uno pins give only 3.3V and a few milliamps, far too little for the strip. So the board only toggles the relay coil, and the relay contacts open or close the 12V line. Relay pins, wiring and coding are covered in the ESP32 Uno - Relay tutorial.

ESP32 Uno Pinout

Your code never uses the D3 or D7 labels printed on the board; it uses the GPIO number behind each Uno header pin. Find D3, D5, D6, D7 and D9 in the picture below before you plug in the relay wires.

ESP32 Uno pinout diagram

How to Connect

When this part is done, the 12V side and the 3.3V side are wired and kept apart.

The board touches only the relay input pins. The strip, the 12V adapter and the DC power jack all sit on the relay contact side.

Single-Color LED Strip Wiring

A single relay switches the whole strip. Its IN wire lands on D3.

The wiring diagram between ESP32 Uno 12V LED strip

This image is created using Fritzing. Click to enlarge image

Component Pin ESP32 Uno Pin
Relay VCC 5V
Relay GND GND
Relay IN D3 (GPIO25)

RGB LED Strip Wiring

One relay per color line, so three relays in total (a 4-channel relay board also works).

The wiring diagram between ESP32 Uno 12V LED strip

This image is created using Fritzing. Click to enlarge image

Component Pin ESP32 Uno Pin
Relay VCC (all three) 5V
Relay GND (all three) GND
Relay 1 IN (blue line) D5 (GPIO16)
Relay 2 IN (red line) D6 (GPIO27)
Relay 3 IN (green line) D7 (GPIO14)

Good to know: D3, D5, D6 and D7 are normal I/O pins on the ESP32 Uno, with no boot or input-only limits, so the relays will not block uploads.

※ NOTE THAT:

Feed the relay coil from the 5V pin, since most modules use a 5V coil. The IN pin only sees the 3.3V output, which most transistor-input modules accept. The ESP32 Uno pins are NOT 5V tolerant, so never route any 5V signal back into a GPIO.

ESP32 Uno Code

Two sketches follow, one per strip type. Both rely on digitalWrite() only, so you install no library.

Code for the Single-Color LED Strip

This sketch flips the relay on D3 (GPIO25) every 5 seconds and prints each change.

/* * This ESP32 Uno code was developed by newbiely.com * * This ESP32 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-uno/esp32-uno-led-strip */ #define LED_STRIP_PIN 25 // D3 (GPIO25) drives the relay IN pin that switches the LED strip void setup() { Serial.begin(9600); // make the relay pin an output pinMode(LED_STRIP_PIN, OUTPUT); } // loop() keeps repeating until the power is removed 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); }

Code for the RGB LED Strip

This sketch steps through red, green, blue, yellow, magenta, cyan and white, holding each color for 2 seconds.

/* * This ESP32 Uno code was developed by newbiely.com * * This ESP32 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-uno/esp32-uno-led-strip */ #define BLUE_PIN 16 // D5 (GPIO16) drives relay 1, which switches the blue channel #define RED_PIN 27 // D6 (GPIO27) drives relay 2, which switches the red channel #define GREEN_PIN 14 // D7 (GPIO14) drives relay 3, which switches the green channel void setup() { Serial.begin(9600); // set all three relay pins as outputs pinMode(BLUE_PIN, OUTPUT); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); } // loop() keeps repeating until the power is removed 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); }

Upload and Test

  1. First time with this board? Set it up with ESP32 Uno - Getting Started before you continue.
  2. Build the circuit by following the wiring table above.
  3. Plug in the USB Type-C cable between the ESP32 Uno and your computer.
  4. Select the board in Arduino IDE: pick ESP32 Dev Module and the COM port of the board (CH340).
  5. Paste the sketch that fits your strip into a new Arduino IDE window.
  6. Press Upload (Upload) and wait for "Done uploading".
  7. Plug in the 12V adapter only after the upload ends.
  8. Set the Serial Monitor to 9600 baud and compare its lines with the strip.
  9. Pro tip: test the relay side first with the 12V adapter unplugged. The relay LED should flash in time with the Serial Monitor lines; once that works, power the strip.

Sample output from the RGB sketch:

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32 Dev Module' on 'COM15')
New Line
9600 baud
The LED strip is turned cyan The LED strip is turned white The LED strip is turned red The LED strip is turned green
Ln 11, Col 1
ESP32 Dev Module on COM15
2

Video Tutorial

See the ESP32 Uno build in action in the video below.

How the Code Works

This table sums up the parts that matter in both relay sketches.

Code Part What It Does
#define LED_STRIP_PIN 25 names the GPIO behind D3 that feeds the relay
#define BLUE_PIN / RED_PIN / GREEN_PIN names GPIO16, GPIO27 and GPIO14 for the three color relays
pinMode(..., OUTPUT) turns each relay pin into an output in setup()
digitalWrite(pin, HIGH) energizes a relay, so that strip line gets 12V current
digitalWrite(pin, LOW) releases a relay, so that line goes dark
delay(5000) / delay(2000) keeps each state on screen for 5 or 2 seconds

Two or three relays on at once mix the colors, for example red plus green gives yellow.

A relay is always fully on or fully off. To get dimming or soft in-between shades, drive the strip with a PWM driver such as the L298N driver or the MOSFET module below.

ESP32 Uno vs UNO R4 for This Project

This table shows what moves when you port the LED strip build from the UNO R4 to the ESP32 Uno.

Item Arduino UNO R4 ESP32 Uno
Logic voltage 5V 3.3V
Single relay pin in code 3 25 (D3)
RGB relay pins in code 5, 6, 7 16, 27, 14 (D5, D6, D7)
MOSFET PWM pin in code 9 13 (D9)
Arduino IDE board Arduino UNO R4 WiFi ESP32 Dev Module
WiFi and Bluetooth WiFi only on the WiFi model WiFi and Bluetooth (Classic and BLE)

The wiring stays on the same header positions, so the same circuit works as-is. Only check that your relay module switches with a 3.3V IN signal.

Fade the Strip with a MOSFET Module

After this part, your single-color strip fades up and down with no click at all.

Take the relay out and put the MOSFET module in its place. The ESP32 Uno sends PWM on D9 (GPIO13), and the duty cycle sets the strip brightness.

MOSFET Module Wiring

The wiring diagram between ESP32 Uno LED strip MOSFET module

This image is created using Fritzing. Click to enlarge image

From To
ESP32 Uno D9 (GPIO13) module PWM pin
ESP32 Uno GND module GND pin
12V adapter plus (through the DC power jack) + terminal
strip 12V pad + terminal (shared with the adapter plus)
strip GND pad LOAD terminal
12V adapter minus (through the DC power jack) − terminal

Good to know: a strip is not a coil, so you skip the flyback diode.

Dimming Code

/* * This ESP32 Uno code was developed by newbiely.com * * This ESP32 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-uno/esp32-uno-led-strip */ const int MOSFET_PIN = 13; // D9 (GPIO13) sends PWM to the PWM input of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); analogWrite(MOSFET_PIN, 0); // the load stays off at startup } void setLoad(int percent) { int duty = map(percent, 0, 100, 0, 255); // scale the percent to an 8-bit duty value analogWrite(MOSFET_PIN, duty); Serial.print("Load power: "); Serial.print(percent); Serial.println("%"); } void loop() { // full power first, then no power Serial.println("Load: ON"); setLoad(100); delay(2000); Serial.println("Load: OFF"); setLoad(0); delay(2000); // ramp the PWM duty up in 10% steps for (int percent = 10; percent <= 100; percent += 10) { setLoad(percent); delay(500); } // ramp the PWM duty back down in 10% steps for (int percent = 90; percent >= 0; percent -= 10) { setLoad(percent); delay(500); } delay(1000); }
Code Part What It Does
const int MOSFET_PIN = 13 D9 (GPIO13) carries the PWM signal
map(percent, 0, 100, 0, 255) turns a 0 to 100 percent value into an 8-bit duty
analogWrite(MOSFET_PIN, duty) outputs PWM, so the strip gets that share of power
two for loops ramp from 10% up to 100%, then down to 0%, in 0.5 second steps

The strip runs at 100% for 2 seconds, sits dark for 2 seconds, fades up, fades down, and the cycle restarts.

Upload and Test the Dimmer

  1. Reuse the board setup from the relay steps above.
  2. Wire the module and strip with the 12V adapter unplugged.
  3. Upload the sketch to the ESP32 Uno.
  4. Connect the 12V adapter to the DC power jack.
  5. Start the Serial Monitor with 9600 baud selected.
  6. Watch the fade go up and down in 10% steps.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32 Dev Module' on 'COM15')
New Line
9600 baud
Load power: 60% Load power: 70% Load power: 80% Load power: 90% Load power: 100% Load power: 90% Load power: 80%
Ln 11, Col 1
ESP32 Dev Module on COM15
2

※ NOTE THAT:

The MOSFET module handles DC only, and it needs a strip supply of roughly 6V or more. A 5V strip will glow weakly or not at all. For mains lamps, stay with the relay.

Go Wireless: Switch and Dim the Strip from Your Phone

After this part, you know how to turn the strip into phone-controlled mood lighting.

The ESP32 Uno has WiFi and Bluetooth built in, so you can drop the timer and decide yourself when the strip lights up. Show ON and OFF buttons for the three color relays on a phone screen, or move a slider to set the MOSFET brightness. Keep the same pins as above: D3, D5, D6, D7 for the relays and D9 (GPIO13) for the PWM.

Troubleshooting

Problem Possible Cause Solution
Arduino IDE shows no COM port CH340 driver missing or a charge-only USB cable Install the CH340 driver and use a USB cable that carries data
Upload stops at "Failed to connect" or "Waiting for download" the board did not enter download mode Hold the BOOT button while the upload starts, then release it
Relay stays silent coil has no power or the GND wire is loose Feed relay VCC from 5V and recheck the shared GND
Relay LED glows but there is no click 3.3V IN signal too weak for that module Use a relay module rated for 3.3V input
Click is heard but the strip stays dark adapter off, or strip wired to the wrong contacts Check the DC power jack polarity and use the COM and NO contacts
Strip lights when the code says off low-level trigger relay or strip on the NC contact Move the wire to NO, or swap HIGH and LOW in the sketch
RGB strip shows the wrong color color lines swapped between relays Red to the D6 relay, green to D7, blue to D5
MOSFET strip never dims, only full or off PWM wire on the wrong pin Put the module PWM wire on D9 (GPIO13)
Board restarts when a relay switches supply dip from the relay coils Use a solid USB port or power supply and keep the strip on its own 12V adapter

FAQ

Is it safe to run the 12V strip off the ESP32 Uno 5V or VIN pin?

No. The strip draws far more current than the board can pass, and 12V must never reach the 3.3V GPIOs. Give the strip its own 12V adapter and let the relay or MOSFET module do the switching.

How much current can one relay handle for an LED strip?

Most hobby relay modules are rated about 10A at 30V DC. A typical 12V strip draws about 1A to 2A per 5 meters, so one relay is plenty. Check the label on your strip and adapter to be sure.

Does a 5V relay module accept the 3.3V output of the ESP32 Uno?

Usually yes, when the module has a transistor or optocoupler input. Power VCC from 5V and wire IN to the GPIO. If the module LED lights but nothing clicks, get a 3.3V relay module.

Why does the code use 25 when the wire goes to D3?

On the ESP32 Uno, each Uno label hides a different GPIO number. D3 is GPIO25, D5 is GPIO16, D6 is GPIO27, D7 is GPIO14 and D9 is GPIO13. The sketch must hold the GPIO number, never the D label.

Do I need a library or extra setup code on the ESP32 Uno compared with the UNO R4?

No library is needed. The sketches are the same as on the UNO R4 except for the pin numbers. analogWrite() works on the ESP32 Uno with the current esp32 by Espressif Systems core, so the MOSFET dimming code runs unchanged.

Can I make orange or purple on the RGB strip?

Not with relays, because each color line is only on or off, which gives seven colors. Use three MOSFET modules and analogWrite() on each line to mix any shade.

Will a 24V LED tape work with the same circuit?

Yes. Swap in a 24V adapter that matches the strip, and make sure the relay contacts or MOSFET module are rated for it. The code does not change.

Can I fit a Uno relay shield on the ESP32 Uno?

The headers match the Uno layout, so most shields plug in. Check which D pins the shield uses, map them to GPIOs, and make sure the shield works with a 3.3V control signal.

What if my project needs more pins than the Uno headers give?

The ESP32 Uno has extra holes near the power header. GPIO32 and GPIO33 offer I/O, PWM and analog on ADC1, so they still read analog values while WiFi is on. GPIO15 offers I/O, PWM and analog on ADC2. Solder pin headers to them and write the GPIO number in code; GPIO32 and GPIO33 are good spots for a fourth relay or a second MOSFET module. Two warnings: GPIO15 and GPIO0 (the IO0 pin at the unused Uno NC position) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code, so use GPIO32 and GPIO33 first. Never use the six holes under the digital header (SD0 to SD3, CMD, CLK = GPIO6 to GPIO11), because they are wired to the flash chip and using them crashes the board.

Can I turn the strip on at sunset or on a schedule?

Yes. Add a light sensor on an analog pin, or fetch the time over WiFi with NTP, and switch the relay in code when the condition is met. Keep the strip wiring exactly as it is.

※ 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!