ESP8266 Controlling WS2812 Neopixel LEDs Using Arduino IDE - a Tutorial

122,591

210

19

Introduction: ESP8266 Controlling WS2812 Neopixel LEDs Using Arduino IDE - a Tutorial

Hi everybody,

If you're like me, you've been looking around the internet for a good tutorial on using the ESP8266 with neopixel LEDs (AKA the WS2812 or WS2812b), programmed via the Arduino IDE. I haven't found it all in one place, in English, but it turns out it's pretty easy now - much better than a few months ago. First, props to sabas1080 for his instructable, which does a nice job of this in Spanish. I'm documenting it here in English in case this helps others.

This is a basic breadboard demonstration. It's not meant to be a "final product" but consolidates instructions for this basic setup. If you haven't used the ESP8266 yet, it's an awesome little wifi board that you can get for a few bucks. Even the fancy version is only $10.

Note that this DOES NOT require a separate Arduino board, it's running the neopixels directly from the ESP8266 and just programming it with the Arduino IDE. And thanks to the hard work of many people it's now very easy!

Come see...

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Parts and Assembly

Parts you'll need:

  1. an ESP8266, I used Adafruit'sHuzzah breakout, http://www.adafruit.com/product/2471
  2. 3.7v LiPo battery such as https://www.adafruit.com/products/1317
  3. FTDI programmer such as http://www.adafruit.com/product/284 or USB-to-serial cable
  4. small switch such as https://www.adafruit.com/products/805
  5. Neopixels (aka WS2812 LEDs) such as https://www.adafruit.com/products/1463
  6. Capacitor to protect your neopixels - I have a 1000 uF here.
  7. ~470 ohm resistor
  8. Breadboard
  9. Wire

Note: using the Huzzah breakout board makes things easier because it has buttons built in for reset and bootloader mode. if you're using a bare ESP8266 board, you'll want a couple additional buttons to use for reset and putting the ESP8266 in the bootloader mode (to upload your code to it).

Assembly:

Assemble as shown in the diagram above. The capacitor and resistor help protect your neopixels. I'm using a neopixel ring because that's what I happen to be working on, but you can test with a strip or a single pixel or whatever you have. If you are using the Adafruit Huzzah breakout, solder it as shown on their nice page here: https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide using your breadboard.

You'll need the FTDI cable or USB for programming. After the programming is finished, you can remove it. Speaking of which, let's program this thing.

Step 2: Code and Programming

First, you need to make sure you have a version of the Arduino IDE that is at least 1.6.4. Get it here:

https://www.arduino.cc/en/Main/Software and install it.

Then go to File --> Preferences and at the bottom under "Additional Board Managers", enter:

http://arduino.esp8266.com/versions/2.0.0/package_...

Use the Board Manager to install that ESP8266 (Following Adafruit's Arduino ESP8266 setup instructions here: https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide)

Tools --> Board select generic ESP8266 (Or Adafruit Huzzah ESP8266 if you're using that) and use these settings:

  • CPU Frequency: 80 MHz
  • Upload speed: 115200
  • When you plug in your FTDI, select the correct COM port for it.

Make sure you also install the neopixel library for Arduino if you haven't already. Get it using the library manager

  1. In the Arduino Go to Sketch --> Include Library --> Manage Libraries (it's at the top of the list)
  2. Type "neopixel" in the search box
  3. select the Adafruit neopixel library and install

Now get your sketch ready. You can use the generic StrandTest sketch in the examples menu under the Adafruit NeoPixel folder. Set the number of pixels you're using and set the data pin - I'm using pin 14.

[NOTE: DON'T USE PIN 16 FOR NEOPIXELS].

Put the board in bootloader mode.

  • If you're using the Huzzah breakout, this means holding down the GPIO0 button, pressing and releasing the resent button, then releasing the GIO0 button.
  • If you're using a bare ESP8266 instead, then temporarily connect GPIO0 to ground, toggle power to the reset pin,then disconnect GPIO0 from ground.
  • If you've done one of the above correctly, the on-board LED should be dimly on.

Now upload the sketch using the Arduino IDE. This will take a while and you will probably see the on-board LED flicker during transfer.

Now that you've uploaded the sketch, let's see if it works. Flip the switch on your battery and you should see your neopixels light up.

Congratulations, you're halfway to making the next big IoT device! Have fun making things light up from afar with your ESP8266.

Hope this saves you time scouring multiple sites to put it all together. Thanks to Adafruit, http://www.esp8266.com/, and http://www.whatimade.today/esp8266-easiest-way-to-program-so-far/ for all the original source material.

2 People Made This Project!

Recommendations

  • Trash to Treasure Contest

    Trash to Treasure Contest
  • Raspberry Pi Contest 2020

    Raspberry Pi Contest 2020
  • Wearables Contest

    Wearables Contest

19 Discussions

0
freefox
freefox

3 days ago

I don't think that the cap is necessary. If so please explain why.
It works with 330 Ohm resistor as well as your goal here is to interface a 3.3V circuit with an 5V one, the communication is only one way as well as you just sending commands to the leds but not reading anything back.


0
Rocktakon
Rocktakon

Reply 2 days ago

Hi and thanks for your comment. The capacitor is a protection measure. You can do without the capacitor and everything may be fine, especially if you're just using a few neopixels. My inclusion of the cap is based in large part on the neopixel guidance from Adafruit here: https://learn.adafruit.com/adafruit-neopixel-uberg...

As Adafruit's guide says, "The capacitor buffers sudden changes in the current drawn by the strip." It also notes "Any project with a lot pixels or a large power source should definitely include the power capacitor and data line resistor."

0
freefox
freefox

Reply 1 day ago

I see, other guides also recommend the cap and resistors like yours. https://starthardware.org/viele-leds-mit-arduino-s...
I have actually tried this build with and without the cap also using a 3V-to-5V TTL level converter with ESP8266 didn't make any difference to me.
It's strange that he recommends using a resistor with an Arduino when that is an 5V system.

I did some measurements tho with multimeter and the average voltage on the Din line is only 0.96-1V which makes me think you wouldn't even need a resistor either.

As I mentioned you only communicate, sending pulses from the Arduino or ESP to the LED strips/rings, there should be no incoming data on the D line so I don't understand the protection there either but who knows with weird led strips from china...

1
JuliusB12
JuliusB12

2 years ago

I'm trying to set this up with the first ESP-01 Module. Please could you help with how the pins should be hooked up?

IMG_20170411_200845400_HDR.jpg
0
krisferrari
krisferrari

Reply 6 weeks ago

Did you try ESP01s and ws2812b?

0
cookie monster.
cookie monster.

1 year ago

When I connected the capacitor, the led strip stopped working.Was it burned?

0
JasperV19
JasperV19

2 years ago

I have a 5v 9A ledstrip, which transistor and capacitor do i need to use?

0
MaciekM15
MaciekM15

2 years ago

Grat project! What about battery life? How long it can last on batteries?

0
MarcoM219
MarcoM219

3 years ago

Good job Sir its very Cool project ,very interesting!! i'll make it!!!

0
shack351
shack351

3 years ago

Cool project. Thanks for putting forth the effort to help people learn. One question though, since your using the ESP8266, it seems as though the article would include info on how to actually control the pixels via wifi. Am I missing something?

0
The Expert Noob
The Expert Noob

Reply 3 years ago

Working on it. But I seem to be running out of space. Trying to consolidate code to get it to fit. Look into the ESP8266 example sketches(ive started with captive portal for a direct connection when no wifi router is around). if/then/else; ive programmed in based on the indexOf url (ex /rainbow/ or /red/ or /redc/ for red chasing ect) and buttons to pass it to the url. Code is sloppy right now, but hopefully I'll have something soon.

0
Rocktakon
Rocktakon

Reply 3 years ago

Glad you're doing that. Thanks for pitching in!

It wasn't my intent with this one, since there many different ways you can do this depending on what you want and I had other plans for the control and just needed to figure out the ESP8266 interface w/ the neopixels.

I'm glad others are contributing, and I'd be glad to update this instructable to point to another that demonstrates how to control via wifi.

0
The Expert Noob
The Expert Noob

Reply 3 years ago

...and started
https://github.com/TheExpertNoob/ESP8266-Wifi-NeoPixel/blob/master/README.md

0
GreenMoon
GreenMoon

3 years ago

I thought nexopixels require 5V power and 5V signal

0
Rocktakon
Rocktakon

Reply 3 years ago

Thanks for checking: they can actually be powered by lower voltages. Too low and you might lose color fidelity. See here for more info: https://learn.adafruit.com/adafruit-neopixel-uberguide/power

0
finalvalue
finalvalue

3 years ago

Why I can't finish, gpio output is Unlike the arduino

0
Rocktakon
Rocktakon

Reply 3 years ago

Hi finalvalue,

I'm sorry that you're having trouble. Can you be more specific about exactly what problem you're having?

Thanks!

0
finalvalue
finalvalue

Reply 3 years ago

I tested, control individual leds by Blink can be normal operation!But, with 12 for the lamp ring cannot normal control, lamp ring no response

0
Rocktakon
Rocktakon

Reply 3 years ago

Double-check that you are using the same pin and matching pin assignment in the software. Also double check that you have enough power for the LEDs. you might want to add a large-ish capacitor (like 1000 uF) across the + and - power rails, as both the ESP8266 and the LEDs can have large and spikey current draw.