Arduino Nano - LED Strip
In this tutorial, we are going to learn how to program Arduino Nano to control a LED strip to emit the light.
You can switch the LED strip with a relay or with a MOSFET module. A relay can only turn the strip ON and OFF. A MOSFET module turns it ON and OFF as well, and it can also dim the strip, so you choose how bright it shines. We will go through both options.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of LED Strip
A LED strip, also known as LED tape or LED ribbon, is a flexible circuit board with surface-mounted LEDs that emit light. These strips are versatile and commonly used for decorative lighting in various applications. LED strips come in a range of colors and are often used to provide ambient lighting, accent lighting, or decorative lighting effects.
LED strips come in two main types:
- Addressable LED Strips: In this type, the color and brightness of each individual LED on the strip can be independently controlled. This capability is due to the fact that each LED is assigned a specific address.
- Non-Addressable LED Strips: In contrast, non-addressable LED strips allow control over the color and brightness, but this control applies uniformly to all LEDs on the strip.
This tutorial will focus on the Non-Addressable LED Strips. For Addressable LED Strips, please refer to the following tutorials:
- Arduino Nano - NeoPixel LED Strip tutorial
- Arduino Nano - WS2812B LED Strip tutorial
- Arduino Nano - Dotstar LED Strip tutorial
Non-Addressable LED Strip Pinout
Non-Addressable LED Strip has two main types:
- Non-Addressable 1-color LED strip: Only one color defined by manufacturer.
- Non-Addressable RGB LED strip: any colors
A Non-Addressable 1-color LED Strip usually has two pins:
- 12V/24V pin: needs to be connected to the positive pin of 12V or 24V DC power supply
- GND pin: needs to be connected to the negative pin of 12V or 24V DC power supply
A Non-Addressable RGB LED Strip usually has four pins:
- 12V/24V pin: needs to be connected to the positive pin of 12V or 24V DC power supply
- R pin: This pin is used to control the red color. Connecting this pin to the negative pin of the power supply enables the red color
- G pin: This pin is used to control the green color. Connecting this pin to the negative pin of the power supply enables the green color
- B pin: This pin is used to control the blue color. Connecting this pin to the negative pin of the power supply enables the blue color

We will learn how to control the both types by Arduino Nano one-by-one.
Relay or MOSFET Module for a LED Strip?
To learn the MOSFET module itself (pins, inside parts, code), see the Arduino Nano - MOSFET Module tutorial.
| Relay | MOSFET Module | |
|---|---|---|
| Light control | ON/OFF | ON/OFF and brightness (PWM dimming) |
| Sound | a click on every switch | silent |
| Speed | slow, milliseconds | very fast |
| Life | contacts wear with use | no moving parts to wear |
| Type of power | AC or DC | DC only |
| Strip voltage | any within the rating | 6V or more (12V and 24V strips are fine) |
| Isolation | yes, coil vs contacts | yes, PC817 optocoupler |
| Pick it for | AC lights, plain ON/OFF | 12V/24V strips that need dimming or fast switching |
If you want to dim a 1-color 12V or 24V strip, choose the MOSFET module. For an RGB strip, each color channel (R, G, B) needs its own MOSFET module, so you need three modules, just like you need three relays.
How to Control a Non-Addressable 1-color LED strip.
If 12V LED strip is powered by 12V power supply, it emits light. To control a 12V LED strip, we need to use a relay in between Arduino Nano and 12V LED strip. Arduino Nano can control the 12V LED strip via the relay. Unfamiliar with relay, including their pinouts, functionality, and programming? learn about relay in the Arduino Nano - Relay tutorial
Wiring Diagram.
Wiring Diagram between Arduino Nano and Non-Addressable 1-color LED strip.

This image is created using Fritzing. Click to enlarge image
Wiring Diagram between Arduino Nano and Non-Addressable RGB LED strip.

This image is created using Fritzing. Click to enlarge image
Arduino Nano Code
Arduino Nano Code for controlling Non-Addressable 1-color LED strip.
The below code repeatedly turns the LED strip ON in 5 seconds and OFF in 5 seconds,
Arduino Nano Code for controlling Non-Addressable RGB LED strip.
The below code repeatedly control the color of the RGB LED strip (red, green, blue, yellow, magenta, cyan and white)
Detailed Instructions
- Wire the components according to the provided diagram.
- Connect the Arduino Nano board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano) board and its corresponding COM port.
- Connect Arduino Nano to PC via USB cable
- Open Arduino IDE, select the right board and port
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino Nano
- Check out the LED strip's state
Code Explanation
Read the line-by-line explanation in comment lines of code!
Please note that, to control the brightness an other colors of non-addressable LED strip, we need to use the L298N driver instead of relay
How to Dim a LED Strip with MOSFET Module
This section uses a MOSFET module in place of the relay to control a 1-color LED strip. With PWM, the Nano can make the strip brighter or dimmer.
Wiring Diagram between Arduino Nano, MOSFET Module and 1-color LED strip

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
| Arduino Nano / Power / Strip | MOSFET Module |
|---|---|
| Nano pin D9 | PWM pin |
| Nano GND | GND pin |
| 12V adapter + | + terminal |
| LED strip + (12V) | + terminal, shared with the adapter + |
| LED strip − (GND) | LOAD terminal |
| 12V adapter − | − terminal |
A LED strip has no coil, so you do not need a flyback diode here.
Arduino Nano Code for Dimming 1-color LED strip
The strip is fully bright for 2 seconds and dark for 2 seconds. Next, the brightness climbs from 10% to 100% in steps, and then it goes back down to 0%.
Quick Steps for MOSFET Module
- Get the Arduino IDE ready as described in the Quick Steps above.
- Wire the Nano, the MOSFET module and the strip as in the diagram, but keep the 12V adapter unplugged.
- Upload the code to the Arduino Nano.
- Plug in the 12V adapter.
- Open the Serial Monitor with baud rate 9600 and watch the strip get brighter and dimmer:
Remember: the MOSFET module switches DC only, and the strip supply must be at least about 6V. For AC lights, use the relay.