In the last episode, I guided you on how to
choose the right led strip for you. And at the end, we went over the different types
of controllers out there. However, in this episode, I will teach you how controllers
work, and how you can build your own smart LED Strip controller for less than 10$. If
you missed last week’s episode you can find its link in the description below. Now, without
any further ado, let’s get started. First let’s start by understanding how the
simplest controller, controls the brightness of LED strips.
So we know that LEDs need 3V to turn on, and you might think that a controller would simply
change its voltage to control the brightness of the LED.
However, in real life, this would not work, and controllers use instead Pulse Width Modulation,
known as PWM.
PWM is a square signal that will turn the
LED strip on and off so quickly that it will give you the illusion of a change in brightness.
To understand how PWM works, let’s suppose that it has a period of one millisecond. If
in this millisecond, the PWM is HIGH for half of the millisecond, and LOW for the other
half it will give the illusion that the LED is on at 50% brightness. If instead, the PWM
was HIGH for one-quarter of the millisecond, and LOW for the other three quarters it will
give you the illusion that the LED is on at 25% brightness. This fraction of the Period
in which is PWM is HIGH is known as the duty cycle. And the larger the duty cycle the more
electrical power gets delivered to the LED which makes it brighter.
Next, let’s understand how colors are made. We know from the last episode that multi-colored
LED strips known as RGB, are formed of red, green and blue led strips merged together.
But how are we able to make other colors such as yellow, orange, or purple? Well actually,
you can mix the RGB colors together to create new ones.
If you want a specific color you
simply need the right recipe with the right amounts of red, green, and blue. For example,
if you want a purple light, you need to mix red and blue together, and to get different
shades of purple you simply need to change the amounts of red and blue.
In fact, all colored displays use RGB lights, even your TV, laptop, and smartphone.
Now in order to use different amounts of red, green, and blue you simply need to vary their
brightness, Oh and guess what! We just learned how to do that using PWM.
Now, let’s design hardware that can produce this PWM signal.
And to do so let’s go to
the workshop! The easiest microcontroller out there is the
Arduino, and for this project, since I want to make it as compact as I can I will be using
an Arduino Nano. But the Arduino can’t provide enough power to drive the LED strips because
it is a 5V device and can deliver a maximum current of 20mA per pin. This is why we need
something that would convert the 5V low current signal of the Arduino into a 12V high current
signal. The easiest way to do that is by using MOSFET
transistors. For those of you who don’t know what a transistor is, well actually it’s
an electronic component that works just like a switch, but the difference is that instead
of switching it using your finger, you use an electrical signal.
When selecting a Transistor, there are 3 things to look at.
First the Series of the transistor. For this project, we will be using an Arduino which
provides a 5V signal. This is why we need a Logic transistor known as IRL.
Next, we will need to choose between NPN and PNP transistors.
NPN transistors are normally
open and close when they receive an electrical signal while PNP transistors are normally
closed and open when they receive the electrical signal. Since in this project we will need
to mimic the PWM signal we will need an NPN transistor.
Finally, we need to make sure that the selected transistor can handle the voltage and current
requirements of our LED strip. For this project, I will be using the IRL 540 which is rated
at 100V and 28A. More than enough for my 12V 2amps led strip.
Now to control a LED using a Transistor you simply need to place it between the LED and
the Ground and connect its gate to one of the PWM pins of the Arduino. With this configuration,
the transistor will mimic the PWM signal of the Arduino by connecting and disconnecting
the ground from the LED. However, to prevent the transistor from floating we will also
need to place a very large resistor between its gate and the ground. For this project,
I used a 750 Kohm resistor but any resistor larger than 100K should be enough.
Finally, this simple circuit needs to be replicated three times, one time for every color of the
RGB LED strip. Now that we have designed the circuit let’s
build it on a breadboard and test it.
But before that, I will add a heat sink to
my transistors just to make sure that they don’t overheat. A small DIY tip I have for
you is to stick a magnet to your screwdriver, this will magnetize its tip and prevent the
screws from falling off. To test the circuit I already wrote a simple
Arduino sketch that will flash the three colors of the RGB. You can download this sketch and
the official Arduino software using the link in the description below. To upload a sketch
on the Arduino you need to select from the tools menu the type of board you are using
and the port it is connected to. After that simply press the upload button on the top
left of the ARDUINO IDE. You should now see your LED strip flashing.
If for some reason the circuit doesn’t work with you, test its continuity, I’ve spent
2 hours debugging my circuit to finally find that one of my jumper wires was broken.
Now that we know the circuit works, I will solder it on a perf-board since it is the
simplest and fastest way to solder the components together.
With the circuit is complete let's get back to my bedroom and replace the old led strip
with this new cool one.
I also need to place the controller somewhere accessible so that
I can still connect it to my laptop and upload new sketches to the Arduino.
Wow! This is much better! Look how continuous the light is! But the flashing is quite disturbing,
so, let's get to coding! After plugging a USB cable into your Arduino,
and getting comfortable on your laptop, Open the Arduino IDE. Once you open a new sketch
you will see that there are 2 main sections, the void setup, and the void loop. In the
void setup you initialize your code for example you tell it to make sure that all the lights
are off, and then in the void loop, you tell your Arduino what to do repeatedly, like flashing
one color after the other. For this project, we need to first tell the Arduino which pin
is what color. Then using the analogWrite function we can tell the Arduino the value
of the PWM that we want it to generate.
This value should range between 0 and 255, 0 turning
it completely off and 255 turning it completely ON. You can also use for loops and delays
to create special effects such as fading or flashing. To save you time and effort I already programmed
many common LED strip functions for you that you can download using the link in the description
below. Also, there is any specific function that you need help with share it with me in
the comment section and I would be glad to help you.
So the LED is installed and has cool animations, but there is still one problem, every time
I want to change the sequence of my led strip I need to connect the controller via a USB
cable. This is why, next week, I will show you how
to control your Arduino from your smartphone. So if you don’t want to miss out on this
video make sure to subscribe and push the notification bell. In the meantime, you should
enjoy one of the videos on the screen right now, and I will see you next week..