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.
PCBway: only $5 for 10 pcbs from https://www.pcbway.com/?from=CZcouple
Lets first create the fader circuit without an Arduino. The base of this circuit is an operational amplifier IC named LM358. In this circuit, initially, the LED slowly glows with increasing brightness & after reaching its maximum brightness, the LED slowly dims its brightness and the process continues.
For the Non-Arduino bit we need:
- 1 x LM358 IC
- 1 x BC547 Transistor
- 1 x 0.47µF Capacitor
- 2 x 4.7KΩ Resistors
- 1 x 22KΩ Resistor
- 1 x 10KΩ Resistor
- 1 x 4.7MΩ Resistor
- 1 x 220Ω Resistor
- 1 x LED
- and a 9V Battery
How This Circuit Works
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 (Op-Amp) IC, integrated with two op-amps powered by a common power supply. Pins 1, 2, and 3 are one op-amp channel, and pins 5, 6, and 7 are the 2nd op-amp channel.
As the capacitor charges and discharges the state of the PIN 3 switches from high to low and based on that the PIN 2 of the op-amp obtains the desire output. If you want to know more about this IC, please check out my "Tutorial No 21 : DIY - IR Module" : https://youtu.be/_M8FQIPi1qk.
So, basically the op-amp here is used for voltage level detection. In this circuit, we are applying a voltage on positive pin (PIN-3) and the voltage to be detected is applied at negative pin (PIN-2).
The transistor acts as a signal amplifier. You will need this if you are attaching a cluster of LEDs however for just 1 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 100cm x 100cm assembly.
Now, lets solder all the components to the board. Lets first solder all the resistances to the board. Then lets solder the transistor followed by the capacitor to the board. After that lets solder the LED and the female pin header. To conclude the setup, lets 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 this circuit you can change the brightness of a LED Lamp when someone walks in or out of a room.
Manual Fading Using PWM
Now, if you want to get the same dimming effect but want to manually control the intensity, you will have to find a way to modulate the pulse sent to the LED or group of LEDs using a potentiometer. I am going to do this by generating PWM Signals.
What is PWM?
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means.
PWM value varies from 0 to 255. The bigger the value of PWM, the brighter the LED is and vice versa.
- If PWM = 0, it is same as GND, so the LED will be OFF
- If PWM = 255, it is same as VCC, so the LED will be fully ON
To get varying analog values, you change, or modulate, that pulse-width. If you repeat this on-off pattern fast enough with an LED, the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED.
In this setup, we are going to use the 555 Timer IC in Astable mode (A free-running multivibrator that has NO stable states but switches continuously between two states this action...