Have you ever tried to use WS2812 LEDs with Arduino? Well, that may be easy, but have you ever tried adding a IR remote? Now it gets complicated!
This tutorial is not of me building a specific project per se, but rather a How To on using WS2812 and IR together on Arduino!
The ProblemAs I have explained in one of my other tutorials, using WS2812 LEDs and a IR remote is a bit complicated.
WS2812 is a LED 5050 chip that is an individually addressable LED. So each of these LEDs on one strip, can be a different color and brightness all at the same time! The different colors work because each chip has 3 LEDs inside; a Red, Green, and Blue! To get white, you just turn all three LED chips on, and the resulting color appears to be white, when its really just red, green, and blue light combined. This type of LED requires precise timing to work correctly.
IR (InfraRed) is a wavelength of light just beyond what the human eye can see; it has a longer wavelength than visible light. A IR remote works by encoding pulses of IR light, which are then received and decoded by a IR receiver. This process also requires precise timing.
Seeing that IR and WS2812 both need precise timing, we have an issue. During my testing, I found that if I am displaying something on the LEDs, the Arduino will still "receive" IR codes, but they turn out as a bungled mess! So the Arduino cannot be controlled while displaying something.
The FixThere are a couple ways around this problem:
- Use Multiple Arduinos
- Accept any received IR code as an interruption (i.e. act like a on/off button)
- Not use functions that require constant updating (that wouldn't be fun though!)
I decided on using the second method; accepting any IR codes as a on/off button while the LED strip is running.
This method has a few obvious drawbacks though:
- TV remotes and other IR remotes will shut the display off also
- Cannot update display with IR remote while it is running
Even though these drawbacks are not very good at all, these are the only options I could think of. If you have a different idea, post in the comments and I'll try it out!
Edit:
I found another method; using non-blocking code! My first library utilizes the second method, but my second library ("_NB") utilizes non-blocking code, so it is much better.
The PartsThis project uses only a few parts:
DFRobot was the sponsor for this project! They have many awesome components and modules for building any electronic project you can think of! I personally buy from them and love all of their parts. The quality is very good!
Check them out here.
Or click this link:
PowerWS2812 LEDs, as I explained, really are three separate LEDs! A standard LED uses roughly 20mA, so if we had all three fully on (white), each pixel would be needing 60mA.
I have a 180 pixel strip, so 180 * 0.06 = 10.8A
Wow! That is a lot of power for a 9' LED strip.
So... to provide this amount of power, you can use a caged AC to DC converter as pictured below:
Make sure to get a 5V version that can handle the amount of LEDs you have. If you have less LEDs, for example, 40, then you can use a 2.4A power supply, which some USB wall warts can do.
The SetupThe setup is fairly simple, seeing that we only need a couple parts to get us in action!
I borrowed the schematic picture from howtomechatronics.com. They're an awesome website for building Arduino projects too!
The 330Ω resistor on the data line is used to reduce noise, so there is less flickering or missed pixels.
The CodeI wrote two libraries and many, many sketches to perfect a setup that works pretty reliably. In my GitHub repository, I have two working libraries, one of which works with timing and IR interruption, and the other with non-blocking code. I also have two working sketches (besides the libraries); one with modes and the other without! By looking at the sketches, you can understand how non-blocking code works.
All of the libraries and sketches in my GitHub repository have been tested on an Arduino Nano, and they all work!
Github Repository:
https://github.com/Kgray44/WS2812IR
I also made a `doc` directory for my WS2812IR_NB library, which explains what all of the functions do! https://github.com/Kgray44/WS2812IR/tree/main/WS2812IR_NB/docs
Wrapping UpThat was all for this project. If you have any suggestions, comments, questions, please post in the comments section below!
Check out more of my projects here:
Comments
Please log in or sign up to comment.