An LED can be dimmed by quickly turning it on and off, several times a second. By varying the mark space ratio, the brightness is varied.
A simple implementation of a PWM system would be a clock feeding an LED and protective resistor to the ground.
The clock should ideally oscillate at a frequency of 50Hz to ensure that you will not see the oscillation. To test this, you can either use a signal generator to provide a square wave, as below, or create a circuit to do it for you.
Step 1: Relaxation Oscillator
The capacitor C1 charges and discharges through the resistor R1, and the time taken for this cycle to occur is the period of the waveform.
Step 2: Relaxation Oscillator
For the purposes of general PWM of LEDs, there is no need for absolute precision with the frequency. If there is a requirement for precision, then the potentiometer chosen should be as close to, but no more than 2R1, and a compensation resistor equal to R1-RP/2.
An alternate solution is to use two resistors in series with the two diodes, to give a fixed, and pre-defined duty cycle.
Step 3: Relaxation Oscillator Output
The potential divider on the input of the transistor is to reduce the output of the relaxation oscillator, since in it's off state, it will still output 2v. This needs to be reduced to below 0.7v in order to not to switch on the transistor, otherwise the LED will remain on constantly and cook.
Step 4: Increasing the Brightness
The limit of this current is defined on the manufacturer's data sheet for the LED, identified as the forward pulse current. There are also often details regarding the minimum pulse width and duty cycles. Using a white LED as an example, the following specifications are given as:
Forward Current = 30mA
Pulse Forward Current = 150mA
Pulse Width =< 10ms
Duty Cycle =< 1:10
Using the pulse width and duty cycle information, the relaxation oscillator can be recalculated with T=2ln(2)RC
Assuming a 10nF capacitor is used, and wanting TON = 10ms, and TOFF = 1ms, the following calculations can be made, and then the circuit diagram drawn.
Step 5: Power Increase
R = (VS - VLED) / (iMAX)
R = (5 - 3.6) / 0.15
R = 1.4 / 0.15
R = 9.3 = 10R
It is however likely that the LED supply source may not be able to provide a sufficient current of 100mA, even if it is for a very short time. It may be necessary to power the LED through the transistor, possibly controlled by another transistor in series also capable of carrying the current.
In this circuit, the supply voltage of the op-amp should be used, as the 5v logic supply will be too small. There is a 0.7v drop over both transistors, and 3.6v over the LED, totalling 5v, and leaving nothing for a protection resistor. However, for the torch, the control can be placed over the power supply for the circuit.
VR = 9 - (3.6 + 0.7)
VR = 4.7v
R = 4.7 / 0.15
R = 31 = 33R
Step 6: Final Circuit
Step 7: Test Circuit
You can also see from the power supply that only 24mA is being drawn, compared with the 30mA if the LED was connected normally.
From the third image containing two LEDs, it appears that both LEDs are of the same brightness. However very quickly, the direct driven LED becomes warm quickly giving good reason to PWM.
Step 8: Finished Torch
Connecting the power supply to the battery connector to test the circuit, the average current reading was approximately 85mA. This is significantly smaller than 180mA (6*30mA) that a direct drive system would require.
I have not gone into great detail with transferring the circuit from the breadboard, onto veroboard as I have aimed to concentrate on the theory behind this project, rather than specifically it's production. However as a general guide, you should test the circuit and get it to work on the breadboard, then transfer the components to the veroboard, starting with the smaller components. If you are competent and quick at soldering, you may be able to safely solder a chip directly to board, otherwise you should use a chip holder.