Have an awesome project in mind using some LEDs. In that project I will be using some LED Fading Effect and few LED Chaser Circuits. But before jumping onto that, I thought I should create a short tutorial and show you guys how to fade a LED with or without an Arduino automatically or manually using a potentiometer.
Have an awesome project in mind using some LEDs. In that project I'll be using some LED fading
effect and few LED chaser circuits. But before jumping into that I thought I should create a
short tutorial and show you guys how to fade an LED with or without an Arduino,
automatically or manually using a potentiometer.
This video is sponsored by PCBWay. PCBWay specializes in manufacturing of very high
quality low volume colored PCBs at a very budgetary price. In addition to standard PCBs
you can order advanced PCBs, aluminum PCBs, rigid flex PCBs. They also provide PCB assembly and
other related services which can meet your need at the greatest extent. Let's first create the
fader circuit without an Arduino. The base of the circuit is an operational amplifier IC named LM358.
In this circuit initially the LED slowly glows with increasing brightness and after reaching
its maximum brightness the LED slowly dims its brightness and the process continues.
For the non-Arduino bit we need one LM358 IC, one BC547 transistor, 1.47 micro farad capacitor,
two 4.7 kilo ohm resistors, one 22 kilo ohm resistor, one 10 kilo ohm resistor,
one 4.7 mega ohm resistor, one 220 ohm resistor, one LED and a 9 volt battery. To get the fading
effect we need to generate a series of triangular waves. Because of the triangular waves the LED
starts glowing slowly and then slowly dims off and the cycle continues. This setup is done using
the LM358 IC. LM358 is a dual operational amplifier IC integrated with two op-amps
powered by a common power supply. Pin number 1, 2 and 3 are one op-amp channel and pin number 5,
6, 7 are the second op-amp channel. As the capacitor charges and discharges the state of
the pin number 3 switches from high to low and based on that the pin number 2 of the op-amp
obtains the desired output. If you want to know more about this IC please check out my tutorial
21 DIY IR module. The link is in the description below. So basically the op-amp here is used for
voltage level detection. In our circuit we are applying a voltage on the positive pin, pin number
3 and the voltage to be detected is applied on the negative pin, pin number 2. The transistor
acts as a signal amplifier. You will need this if you are attaching a cluster of LEDs. However,
just for one LED you can simply remove it. So this is how my board looks like in 2D and 3D.
There are 15 breakout boards in this 100 cm by 100 cm assembly. Now let's solder all the
components to the board. Let's first solder all the resistance to the board. Then let's
solder the transistor followed by the capacitor to the board. After that let's solder the LED
and the female pin header. To conclude the setup let's solder the IC base and then install the IC
into it. So this is how it looks like. Good thing about LEDs is that they can be easily controlled
as compared to the traditional light bulbs which means you can easily change their intensity based
on your need. Just by making a slight modification to the circuit you can change the brightness of
the LED lamp when someone walks in or out of the room. Now if you want to get the same dimming
effect but want to manually control the intensity you'll have to find a way to modulate the pulse
sent to the LEDs or group of LEDs using a potentiometer. I'm going to do this by generating
a PWM signal. What is PWM? Pulse Width Modulation or PWM is a technique for generating analog results
with digital means. PWM varies between 0 to 255. The bigger the value of PWM the brighter the LED
is and vice versa. If PWM equal to 0 it's same as ground so the LED will be off. If PWM equal to 255
it's same as VCC so the LED will be fully on. To get varying analog values you change or modulate
the pulse width. If you repeat this on-off pattern fast enough with an LED the result is as if the
signal is steady voltage between 0 and 5 volt controlling the brightness of the LED. In this
setup we are going to use the 555 timer IC in A-stable mode to generate the PWM signal. 555
timer IC will vary the voltage delivered to the LEDs to achieve the dimming effect of the LEDs.
For this setup we need one 555 timer IC, one LED, one 220 ohm resistor, two 1N4007 diodes,
one 50 kilo ohm potentiometer, one 10 nanofarad and a 100 nanofarad capacitor and a 5 volt battery.
Based on the charging and discharging timings of the capacitor a PWM signal is generated at the
pin number 3 of the 555 timer IC. The output is then sent to the LED to produce the dimming effect.
So this is how it looks like. By rotating the knob of the 10k pot we can adjust the brightness of the
connected LED. Now let's repeat this setup using an Arduino. The beauty of Arduino is that it has
six digital pins that can be used as PWM outputs. Pin number 3, 5, 6, 9, 10 and 11. PWM signals are
sent using the analog write function by passing a value between 0 and 255. Analog write 255
requests a 100 percent duty cycle which means always on and analog write 127 is a 50 percent
duty cycle. For this setup we need an Arduino Uno Nano whatever is handy, a breadboard, a LED,
a 220 ohm resistor and a 10k potentiometer. Connect the positive leg of your LED to the
digital output pin number 9 of Arduino through a 220 ohm resistor. Connect the negative leg
directly to the ground. That's it. That's how simple it is. After declaring pin number 9 as
LED pin and setting up the pin mode in the setup section we are going to loop through and dim the
LED in the loop section. By gradually increasing the PWM value from 0 to 255 and then back to 0
we can get the fading effect. In this sketch the PWM value is set using a variable called brightness.
Each time in the loop it increases by the value of the fade amount. If brightness is at either
extreme of its value 0 or 255 then the fade amount is changed to its negative. So if it is 5 it's set
to minus 5 and if it is minus 5 it is set to 5. The next time through the loop this change causes
the brightness to change its direction. A delay is added to control the speed of the fading effect.
So this is how it looks like. Connect the positive leg of your LED to the digital output pin number
6 of the Arduino through a 220 ohm resistor. Connect the negative leg directly to the ground.
Connect the left pin of the 10k pot to VCC and the right one to the ground. Now connect the data pin
to the A0 pin of Arduino. In this circuit the potentiometer is working as a voltage divider.
One of the outer pin is connected to ground and the other one to VCC and the middle pin is the
voltage output. The wiper position in this setup determines the output voltage. Now let's have a
look at the code. Based on my setup I set the LED pin as 6 and the potentiometer pin pot as A0.
Another variable knob is used to read and store the value of the potentiometer. Pin mode of the
LED pin is set to output and we don't have to do anything with the pot as its default value is
already set as input. In the loop section I'm first reading the value of the pot using the
analog read function and then mapping its value between 1 to 255. A potentiometer intakes a value
between 1 and 1024 but in our setup it has to be between 1 to 255. The map function divides the
value read from the potentiometer into equal intervals of 1 by 255 which is then sent to the
LED using the analog write function. So this is how it looks like. Thanks again for watching this
video. I hope it helps you. If you want to support me you can subscribe to my channel and watch my
other videos. Thanks. See you again in my next video. Bye now.