Arduino Nano ESP32 - NeoPixel LED Strip

The NeoPixel strip is like a strip of colorful RGB LEDs, and you can control each LED's color and brightness on its own. In this guide, we'll discover how to use an Arduino Nano ESP32 to control the NeoPixel RGB LED strip. To control all the LEDs on the NeoPixel strip, you only need a single pin on the Arduino Nano ESP32.

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-C
1×NeoPixel RGB LED Strip
1×1000uF Capacitor
1×470Ω resistor
1×5V Power Adapter
1×(Optional) DC Power Jack
1×Jumper Wires
1×Breadboard
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
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. We appreciate your support.

Overview of NeoPixel RGB LED Strip

Pinout

The NeoPixel RGB LED strip has three pins:

  • GND pin: needs to be connected to GND (0V)
  • VCC pin: needs to be connected to 5V of external power supply
  • Din pin: is pin that receives the control signal. It should be connected to an Arduino Nano ESP32 pin.
NeoPixel Pinout

Wiring Diagram

The wiring diagram between Arduino Nano ESP32 and NeoPixel RGB LED strip

This image is created using Fritzing. Click to enlarge image

How To Program For NeoPixel RGB LED Strip

  • Declare a NeoPixel object
#define PIN_NEO_PIXEL D2 // The Arduino Nano ESP32 pin connected to NeoPixel #define NUM_PIXELS 30 // The number of LEDs (pixels) on NeoPixel Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);
  • Initializes the NeoPixel
NeoPixel.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  • Set color of each individual LED (called pixel).
NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 0, 0));
  • Set brightness of all strip.
NeoPixel.setBrightness(200); // a value from 0 to 255

※ NOTE THAT:

  • NeoPixel.setBrightness() is used for all pixel on LED strip. To set the brightness for each individual pixel, we can scale the color value.
  • The values set by NeoPixel.setBrightness() and NeoPixel.setPixelColor() only take effect when NeoPixel.show() is called.

Arduino Nano ESP32 Code

The following code accomplishes the following tasks:

  • It sequentially changes pixels to green, with a pause between each pixel.
  • It turns off all pixels for a duration of two seconds.
  • It simultaneously sets all pixels to red, maintaining this state for 1 second.
  • This entire process is then repeated indefinitely.
/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-neopixel-led-strip */ #include <Adafruit_NeoPixel.h> #define PIN_NEO_PIXEL D2 // The Arduino Nano ESP32 pin connected to NeoPixel #define NUM_PIXELS 30 // The number of LEDs (pixels) on NeoPixel LED strip Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800); void setup() { NeoPixel.begin(); // initialize NeoPixel strip object (REQUIRED) } void loop() { NeoPixel.clear(); // set all pixel colors to 'off'. It only takes effect if pixels.show() is called // turn pixels to green one-by-one with delay between each pixel for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel NeoPixel.setPixelColor(pixel, NeoPixel.Color(0, 255, 0)); // it only takes effect if pixels.show() is called NeoPixel.show(); // update to the NeoPixel Led Strip delay(500); // 500ms pause between each pixel } // turn off all pixels for two seconds NeoPixel.clear(); NeoPixel.show(); // update to the NeoPixel Led Strip delay(2000); // 2 seconds off time // turn on all pixels to red at the same time for two seconds for (int pixel = 0; pixel < NUM_PIXELS; pixel++) { // for each pixel NeoPixel.setPixelColor(pixel, NeoPixel.Color(255, 0, 0)); // it only takes effect if pixels.show() is called } NeoPixel.show(); // update to the NeoPixel Led Strip delay(1000); // 1 second on time // turn off all pixels for one seconds NeoPixel.clear(); NeoPixel.show(); // update to the NeoPixel Led Strip delay(1000); // 1 second off time }

Detailed Instructions

To get started with Arduino Nano ESP32, follow these steps:

  • If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
  • Wire the components according to the provided diagram.
  • Connect the Arduino Nano ESP32 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano ESP32) board and its corresponding COM port.
  • Open the Library Manager by clicking on the Library Manager icon on the left navigation bar of Arduino IDE
  • Search “Adafruit NeoPixel”, then find the NeoPixel library by Adafruit
  • Click Install button to install NeoPixel library.
Arduino Nano ESP32 NeoPixel library
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
  • Check out the effect of the LED strip

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!