Arduino NeoPixel LED Tutorial!

LeMaster Tech
183 followers
17 Video Views·Apr 20, 2025
This video covers how to use the WS2812B Integrated Circuit (IC) programmed by an Arduino to create a customizable LED project!
This project was a ton of fun to make and huge thanks to PCBWay for sponsoring the video! Get a $5 order credit just for signing up at this link! https://pcbway.com/g/2Zlh7L
The 8x8 LED Grid I Used: https://amzn.to/4cvG3JK
The LED Strip Light I Used: https://amzn.to/3WYeov0
Super Cheap Arduino Nanos: https://amzn.to/3AxERYV
Capacitive Touch Sensors: https://amzn.to/3Mmrxcp
A Huge Thank You to my Patreon Supporters!! https://www.patreon.com/LeMasterTech
Don't forget to leave a like on the video, subscribe to the channel and comment what you want to see next time on the channel! Thanks for watching!
what's up you guys welcome back to the
channel in today's video I'm going to
show you how to use individually
addressable RGB strip lights so that you
can do things like customizable signs or
a lightsaber project or anything else
where you want a lot of LEDs controlable
from an Arduino or a microcontroller of
any kind and you want customization over
things like what color they display a
sequence of events that they fire in I'm
going to show you how to do all of that
in this video
[Music]
now the lightsaber is one kind of fun
kind of cool application and I left this
one pretty barebone so it'd be kind of
easy to see what's going on here but you
could totally package this into like
some pretty simple plastic tubing and
get like a pretty fun basic DIY
lightsaber build going the actual meat
and potatoes of this is just a little
Arduino Nano and then a capacitive touch
sensor which basically operates like a
push button it's just a little bit more
fun because it senses the presence of
your finger rather than you actually
depressing a button uh and then the rest
of this project is just a little bit of
code which I put on the Nano and then a
strip of these individually addressable
LED lights so you might have heard of
these kind of as neopixels but this
specific chip or driver integrated
circuit is a
ws2812b any pin capable of doing pulse
width modulation or PW m is capable of
controlling a whole strip of these up to
like 120 LEDs making awesome custom
electronic components like this uh
homemade lightsaber or this 3D printed
enclosure that can be a customizable LED
sign has never been easier thanks to the
sponsor of today's video PCB way and
more about them later in the video now
like I talked about in the beginning
these could really not be any simpler
they're a series of individually uh
addressed integrated circuits which do
talk in a chain using pulsewidth
modulation so basically as you send a
signal down a chain of these strings
you're telling it data RGB data and
brightness data about the state of each
individual LED and you can control it in
a sequence or a series by just one pulse
with modulation pin so it has plugs for
chaining the data outbound so you can
send this to another strip of LEDs like
I could plug this directly into this and
I could control 128 LEDs rather than
just 64 or any other number in
customization then these bigger pieces
also come with additional power uh wires
so in this case 5 volts in ground and
rather than jumper them together or tie
them all into my breadboard I just have
these super convenient wo uh lever nuts
where I can land multiple wires for
jumping purposes it's basically like
using a breadboard but in midair and
then I use another one just to connect
the signal wire off of the uh
individually addressable lights to the
Arduino but as you can see at the
Arduino Nano there is only ground 5
volts and then uh digital pin three in
use on the Nano and then everything else
is software based so right now I just
have a little script that just turns all
the lights on and then has them snake in
from the middle and then leave that one
light on till I clear it out as you can
see we're going to take a look from the
very beginning at how to actually
program these we're going to look at the
software right now all right let's get
started by uh including the fast L.H
Library so this is the um library to
control a string or grid so really a
grid is just a string of lights that are
arranged in a square a rectangular
pattern instead of in a linear pattern
but in terms of how they're wired
together it's still linear it's still a
um and this specifically works for the
2812b integrated circuits I don't know
for certain that it works with other uh
like neopixel style RGB drivers so it
might I just haven't looked into it but
we want fast led. if you don't know how
to uh add libraries you go to tools you
go to manage libraries and then you
should be able to do fast led. you're
going to include fast L.H and then I'm
going to define the LED pin that I have
it plugged into and as you probably saw
uh in the intro I have it plugged into
pin 3 but you can use any pin capable
can use any pin capable of pwm so then
another thing you're going to want to
Define in the beginning and this will be
specific to your application is how many
LEDs you're using and then what I want
to do is I want to Define c
RGB and then LEDs and then num of LEDs
and what you'll see is we use this in
just a second to set up some of the
specific uh context for using this
specific kind of um driver so we'll go
into our setup our void setup Loop and
we want fast led. add LEDs so we're
basically loading in the number of LEDs
that we need we say what uh the circuit
for them is and in this case we're using
ws2812 uh integrated circuits and then
the pin that we wanted on and in this
case we defined it as LED pin and then
the coloring scheme so grb uh which is
just RGB I'm honestly not sure why they
inverted the letters like that don't
worry about it too much um and then what
we want to say is uh the LEDs to load in
and then how many so numb LEDs then the
next thing I like to do because one
thing to keep in mind is driving this
many LEDs even though yes the brains can
handle it um you're drawing a lot of
amperage when you pull 6 four LEDs all
at the same time off of your little
dinky Arduino the Arduino can only
Supply like maybe two amps then
something that you don't have to do but
because these are using like sort of
simple pwm technology it's not a bad
idea to just clear and then show the
LEDs in your setup Loops we're going to
uh use fast led. show and then just in
case we want to do any debugging I'm
going to do serial begin 9600 and then I
think what we'll do here as a first
basic test to show you how to use um how
to use this is we will just set um One
LED red one led to green and one led to
Blue so to do this you don't need fast
LED again you actually now are just
going to say LEDs and then the index
that you want to set equal to a
different color so in my case why don't
I take LEDs zero and then
crgb is how you tell it that you're
going to pass it a new color and then
I'm going to say 255 and then zero and
then zero so that should be all red and
now I'm just going to take a random one
LEDs 13 and I'm going to set that equal
to
crgb
0255 0 so that should give me a decent
green and then let's say LEDs 61 so not
all the way to 64 but you'll get the
idea is going to be equal to C RGB
0255 and now I'm not even going to put
anything in the loop code yet the loop
code is just going to pass but what I
want to do is compile it verify it and I
want to make sure that when this starts
up it's just going to turn on three LEDs
and actually so that it looks kind of
sequential I think what I'll do is I'll
put a 1 second delay in between turning
on each of these uh lights and so here
you're just seeing the most basic way
you can take one light in that string
and you can command it to any color that
you want um and I'm already realizing
that I forgot something I just told you
guys about which is fast led. show so
we're going to update the uh colors but
we have to actually say okay I updated
the color now show it all right and let
me get my other camera going so you can
see what the lights are doing and we are
going to hit
upload all right so I still had the old
code on there and now it's
compiling red green blue there you go so
uh what you saw there red one kicks on
first then green then blue 1 second
later and if you remember the numbers we
used we used zero for red so that's down
here and then what's actually happening
here is it's snaking in this order so
this is 0 through 7 this light is 8 9 10
11 12 13 is where we got green and then
it's snaking back and forth so it's uh a
continuous string it just looks like a
grid and so we get to 61 and remember we
have 64 lights starting with zero so 63
is right here so let's go ahead and get
rid of all of the defining LEDs to do
things in the setup Loop and let's just
settle for this setup Loop which is
going to turn the thing on Set
brightness to 70 and then clear and show
the lights and let's go down to void
Loop and let's put put something
interesting in here to run repeatedly
why don't we say why don't we do a
simple Runner circuit and we'll just say
four uh I less than and then the number
of LEDs so as long as our index variable
is less than 64 why don't we just run
through this circuit and turn them all
on with a slight delay in between them
and of course I've caught myself in
Python syntax world so what we need to
do is we need to say int I is equal to
Zer to start and then we want I and
that's a semicolon not a comma and then
we want I while it's less than the
number of LEDs and then what we want to
happen each Loop is I to add one so it's
just an increment variable and then we
open up curly brackets and what I'll say
in here is what I want is uh just
LEDs at I equal to and you could make
this a random color or Dynamic Color but
what I'm going to do is I'm just going
to use a red and a green and no blue
it's not going to show unless we say
fast led. show and then it's going to
all happen immediately back to back to
back unless we also say delay some
amount of time and this is in
milliseconds so a 50 millisecond delay
still means we'll do all of this in 3
seconds and then because current ly this
is going to give us a uh full board we
need something to go through and turn
them back off and to do that we could
clear but we could also just write zeros
to them and do it in the same order
let's
verify and it does not compile which is
why you verify because I forgot some
semicolons because C++ syntax is silly
let's verify
now there we go so let's upload it and
let's see what we get on our
board here
goes please there we go we're getting
yellow which is what red and green
combined for that's sweet and then you
get this Runner behind it kind of
turning them off which is pretty fun um
so and because it's in the loop section
of our code as soon as it finishes a
cycle it's going to restart immediately
so let's go back to the code and let's
take a look at how to maybe take this
one step further right after it's yellow
then we'll do something that is purple
um and then we'll turn them back off and
so all you're going to see here I copied
the exact same code but uh ra and then
I'm going to get rid of this middle one
what we'll have now is we'll have yellow
fill the screen and then be chased by
purple and then be cleared out so that's
just a simple example of how quickly you
can iterate on these things let's just
upload that quickly and see what that's
changed and it resets real briefly and
then yellow filling the screen Here
Comes purple right behind it hopefully
that shows up okay on the phone and then
it gets cleared out whoop so that is
some of the most basic conceptual code
behind how you set LEDs how you turn
them on how you turn them off hopefully
this gave you what you were looking for
this was really meant to be a tutorial
on how to use the
ws2812 uh integrated circuit
individually addressable l strip with an
Arduino microcontroller um the
possibilities are endless these are
super super cool components and I have a
ton of fun using them and programming
them into things like that lightsaber
and speaking of that lightsaber it's a
great time to talk to you about the
sponsor of today's video PCB way PCB way
is one of the best resources for makers
who are looking to take their hobby
builds and turn them into professional
grade official legit looking pcbs with
little to no electrical design
experience I was able to design a cool
uh Arduino Nano compatible 12 LED board
that is able to take four capacitive
touch sensors as inputs control a Servo
and a bank of 12 LEDs they look awesome
could not be more impressed with their
quality how easy it is to generate
design files for Custom Electronics and
PCB tech support is super responsive and
their engineers and design team review
every job that's submitted on top of
that they have great support for 3D
printing and metal prototyping as well
so they're an awesome One-Stop shop for
your maker needs to take your designs to
the next level so a huge thank you to
PCB way for sponsoring this video and be
sure to check their page out Linked In
the description below I'll also leave a
couple useful links to some of the
components I used in this video
including the uh cheap Arduino Nanos
that I get the capacitive touch sensors
and the string form and the 8 by8 grid
form of the uh LEDs that I use in this
video so if you want the exact
components that I show here you can get
them also linked in the description
below but keep in mind
ws2812 is the type of integrated circuit
that we used in this video and I used
the Arduino Nano uh they there are other
forms of individually addressable rgbs
and there are plenty of other forms of
microcontroller as well as raspberry pie
and other standard ways of controlling
these strip lights so the world is your
oyster this should help hopefully get
you going I really appreciate you guys
watching the videos I appreciate all of
the continued support on L Master Tech
it's kind of crazy to think that we're
going to crack 15,000 subscribers this
uh month because since moving to Texas
and having a baby and starting a new job
uh I have not had the time for YouTube
that I previously had and the channel
has just continued to grow and the
comments have kept pouring in for
support so I really want to get back on
a consistent build schedule um and so
thank you everyone for watching the
videos and continuing to support me and
continuing to grow L Master Tech even
when L Master Tech is struggling to
consistently produce videos so thank you
everyone for watching be sure to let me
know what you'd like to see next on the
channel a huge thank you as always to my
patreon supporters and good luck with
your projects thanks for watching see
you next time bye
