Arduino Nano 33 IoT - LED Strip

This lesson will teach you how to code the Arduino Nano 33 IoT to control a 12V RGB LED light strip and single color 12V LED strip.

Two kinds of switches are used here: a relay and a MOSFET module. With the relay, the strip is either fully lit or dark. With the MOSFET module, the strip can also be dimmed to any brightness you like. You will learn to use both of them.

Arduino Nano 33 IoT 12V LED strip

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
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
1×Alternatively, 24V 1-color LED Strip
1×Alternatively, 24V RGB LED Strip
1×Alternatively, 24V Power Adapter
1×Optionally, 5V Power Adapter for Arduino Nano 33 IoT
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

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 .

Overview of LED Strip

An LED strip, sometimes called LED tape or LED ribbon, is a flexible board with tiny LED lights attached. These strips are very useful and are usually used for creative lighting in different areas. LED strips come in many colors and are often used to add soft light, highlight special spots, or create attractive decoration.

There are two main kinds of LED strips:

  • Addressable LED Strips: In these strips, you can change each LED's color and brightness separately because every LED has its own unique number.
  • Non-Addressable LED Strips: In these strips, you can change the color and brightness, but all LEDs change the same way.

This guide will talk about Non-Addressable LED Strips. For tutorials on Addressable LED Strips, please see the ones listed below.

Non-Addressable LED Strip Pinout

Non-addressable LED light strips come in two main types:

  • Basic single-color LED strip: The maker sets it to show only one color.
  • RGB LED strip: It can display many different colors.

A basic one-color LED strip that cannot be controlled individually normally comes with two pins.

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

A basic RGB LED strip that isn’t individually controlled usually has four pins.

  • 12V/24V pin: Connect this to the positive terminal of a 12V or 24V DC power supply.
  • R pin: This pin controls the red light. When you connect it to the negative terminal, the red light turns on.
  • G pin: This pin controls the green light. When you connect it to the negative terminal, the green light turns on.
  • B pin: This pin controls the blue light. When you connect it to the negative terminal, the blue light turns on.
Arduino Nano 33 IoT non-addressable led strip Pinout

We will learn how to control both types using the Arduino Nano 33 IoT, one at a time.

A MOSFET module is a good partner for these strips. If you have never used one, start with the Arduino Nano 33 IoT - MOSFET Module tutorial.

Relay vs MOSFET Module for LED Strip

Relay MOSFET Module
Light control Lit or dark Lit, dark, and dimmed to any brightness (PWM)
Click sound Yes None
Switch speed Milliseconds, slow Very quick
Life of the switch Limited, the contacts wear Long, no moving parts
Strip power AC or DC DC only
Strip voltage Whatever the relay is rated for 6V or more (12V and 24V strips are fine)
Isolation from the board Yes, coil and contacts Yes, PC817 optocoupler
Best for Simple ON/OFF lighting Dimming 12V/24V strips and soft light effects

For a single-color 12V or 24V strip, the MOSFET module is the easier way to get dimming. An RGB strip has three color channels (R, G and B), so it needs three MOSFET modules, one per color, in the same way it needs three relays.

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

When a 12V LED strip is connected to a 12V power supply, it lights up. To control the LED strip, we use a relay that sits between the Arduino Nano 33 IoT and the LED strip. The Arduino Nano 33 IoT sends commands through the relay to the LED strip. If you are not familiar with relays, their pins, how they work, or how to program them, check out the Arduino Nano 33 IoT - Relay tutorial.

Wiring Diagram.

Wiring Diagram between Arduino Nano 33 IoT and Non-Addressable 1-color LED strip.

The wiring diagram between Arduino Nano and 33 IoT 12V LED strip

This image is created using Fritzing. Click to enlarge image

Wiring Diagram between Arduino Nano 33 IoT and Non-Addressable RGB LED strip.

The wiring diagram between Arduino Nano and 33 IoT 12V LED strip

This image is created using Fritzing. Click to enlarge image

Arduino Nano 33 IoT Code

Arduino Nano 33 IoT Code for controlling Non-Addressable 1-color LED strip.

The following code repeatedly turns the LED strip on for 5 seconds and then off for 5 seconds.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-led-strip */ #define LED_STRIP_PIN 5 // The Arduino Nano 33 IoT pin controls to the LED strip via relay void setup() { Serial.begin(9600); // initialize Arduino Nano 33 IoT pins as digital output pins pinMode(LED_STRIP_PIN, OUTPUT); } // The loop function repeats indefinitely 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 Nano 33 IoT Code for controlling Non-Addressable RGB LED strip.

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

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-led-strip */ #define BLUE_PIN 6 // The Arduino Nano 33 IoT pin connects to the blue pin of LED strip via relay 1 #define RED_PIN 5 // The Arduino Nano 33 IoT pin connects to the red pin of LED strip via relay 2 #define GREEN_PIN 4 // The Arduino Nano 33 IoT pin connects to the green pin of LED strip via relay 3 void setup() { Serial.begin(9600); // initialize Arduino Nano 33 IoT pins as digital output pins pinMode(BLUE_PIN, OUTPUT); pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); } // The loop function repeats indefinitely 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

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the Arduino Nano 33 IoT.
  • Look at the LED strip to see its status.

Code Explanation

You can see the explanation in the comments above the Arduino code.

Remember, to change the brightness and colors of a regular LED strip, you need to use the L298N driver instead of a relay.

How to Dim a 1-color LED Strip with MOSFET Module

In this part, a MOSFET module switches the single-color LED strip in place of the relay. By changing the PWM value, the Arduino Nano 33 IoT makes the strip brighter or dimmer.

Wiring Diagram between Arduino Nano 33 IoT, MOSFET Module and 1-color LED Strip

The wiring diagram between Arduino Nano and 33 IoT LED strip MOSFET module

This image is created using Fritzing. Click to enlarge image

  • Arduino Nano 33 IoT D9 goes to the module PWM pin.
  • Arduino Nano 33 IoT GND goes to the module GND pin.
  • The 12V adapter + and the strip 12V/24V pin both go to the + terminal.
  • The strip GND pin goes to the LOAD terminal.
  • The 12V adapter − goes to the − terminal.

An LED strip has no coil, so you do not need a flyback diode. For a 24V strip, use a 24V adapter instead.

Arduino Nano 33 IoT Code for dimming Non-Addressable 1-color LED strip

The strip shines at full brightness for 2 seconds and goes dark for 2 seconds. Then it slowly gets brighter from 10% to 100%, and slowly gets dimmer back to off.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-led-strip */ const int MOSFET_PIN = 9; // Arduino Nano 33 IoT 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); }

Detailed Instructions

  • Get the Arduino IDE and the board ready, as in the Quick Steps for the relay above.
  • Wire the strip to the MOSFET module as in the diagram, with the adapter unplugged.
  • Paste the code into the Arduino IDE and upload it.
  • Plug in the power adapter of the strip.
  • Open the Serial Monitor at 9600 baud and compare the numbers with the brightness of the strip.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' 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 Nano 33 IoT on COM15
2

※ NOTE THAT:

The MOSFET module switches DC only, and the strip supply must be about 6V or more. Keep the relay if you want to switch an AC light.

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!