1.
Introduction
This LED dimmer works with PWM and can be used to dim
LED strips rated at 12V up to 2 amps. The LEDs are driven by a FET transistor.
The dimmer can be configured to operate in several
ways: with a rotary button (potmeter), with one pushbutton or with two
pushbuttons.
The dimmer features soft start in all modes, and soft
stop + dim memory in one or two pushbutton mode.
It also contains a low drop voltage limiter which
limits the voltage on the LED strip to 12V, making it suitable for use in
motorhomes, boats and so on because when charging the batteries the voltage can
rise up to 15V.
I made four versions of the PCB layout: a square
version, a slim-line version, both for PIC18F4550 and PIC18F2550.
This circuit is based around the PIC18F4550 or
PIC18F2550 microcontroller. This chip is actually a small computer contained in
a single chip, including RAM memory,
EEPROM, I/O ports, CPU and so on. When you buy this chip, it comes empty
with no program on it. You have to compile the source code and download the
resulting machine code into it, using a
PC and a small programmer attached to the PC and the chip. To get yourself
familiar with this stuff, I suggest you first read this link: Getting started with microcontrollers.
2.
Description
Using a microcontroller to design a LED PWM dimmer
might look like overkill at first glance. The reason for using a
microcontroller is mainly for implementing things like soft start, soft stop
and dim memory.
The characteristics of the device are:
- 3 operating modes (choosen with dip-switches or
wired connections):
+ pushbutton
operation with 1 pushbutton
+ pushbutton
operation with 2 pushbuttons
+ operation
with potentiometer
- Soft start
- Soft stop (some configurations only)
- Remembers last dim setting (push button operation
only)
- Slide switch for direct access to 100% light
- For use with 12V systems (input 12-16V, output 12V)
- LED strips up to 2A
3.
Usage
Default operation mode is with a potentiometer. To use
the device with one push button operation, connect PAD8 to PAD5. To use the
device with two push buttons operation, connect PAD9 to PAD5. Pads 5, 8 and 9
can be found on the ICSP connector.
One button operation:
Alternatively mount jumper S3 and set to ON.
To operate:
Press button for a short while to lit the LED. Keep
button pressed to increase light. Release button and hold button again to dim
light. Press button shortly again to set the light off (soft stop). Press
shortly again to put light on again, the light will soft start to last dim
level.
Last dim level is stored in EEPROM at each change of dim
level.
Two button operation:
Alternatively mount jumper S4 and set to ON.
To operate:
Press UP button for a short while to turn the light on
(to last dim level). Keep the UP button pressed to increase the dim level. Keep
the DOWN button pressed to decrease the dim level. Press the DOWN button for a
short while to turn off the light.
Shortcut to 100 percent:
If desired, connect a switch between X and Y or solder
a switch on the PCB. Operating this switch bypasses the current dim level and
directly lights to 100 percent.
Connect power, LEDs and potmeter:
Solder in/out directly to the power regulator and
mosfet leads (- = 12V ground, + = 12V, Led- and Led+ to LED strip – and +). If
desired, solder a potmeter to green, yellow and orange wires or solder an SMD
potmeter on the PCB:
4.
Schematic diagram
To support multiple versions of the PCB (see later)
also multiple versions of the schematic diagram were created. These can all be
found in the Eagle zip file later on.
5.
Explanation of the schematic
diagram
(Refer to the schematic diagram).
The diagram is really simple. A potmeter is connected
to an ADC port (RA0) as a voltage divider. The PIC constantly reads the value
and translates it (using a gamma table) to a PWM value on port RC1. The PWM
output is connected to the gate of MOSFET transistor Q1 which drives the LEDs.
In stead of a potmeter one or two pushbuttons can be
used as a user interface. The PIC constantly reads the buttons and how long
they are pressed (as described above in “Usage”) and translates this to a
suitable PWM value. Every 5 seconds the value of the PWM is stored in EEPROM (unless
it didn’t change) so that the light comes up to the last dim level the next
time it is used.
6.
The
printed circuit board
The pcb is designed for smd components.
It is single sided and designed with Eagle (from Cadsoft).
Below is only one version of the PCB. Other versions
can be found in the Eagle zip file later on.
The big transistor (IRLZ24N) and the power regulator
(LT1085-12) are actually not SMD components, therefore 6 holes must be drilled
to fit these. It is best to fit it at the bottom side.
PDF file (mirrored) to print on a transparent: Print-layout
Link to Eagle files zip file containing all versions of the PCB, schematic and pdf files.
7.
The final device
Below some pictures of different versions of the final
device.
The connector marked “-+MCD” is the in-circuit
programming interface to connect with the programmer (connections: - =, ground
+ = +5V, M = reset, C = clock, D = data).
PIC18F2550 Slimline version (left is the potmeter):
PIC18F4550 square version:
PIC18F4550 Slimline version (PIC not yet mounted):
8.
Programming
The software is written in C (PIC
C18 from Microchip).
It was first prototyped on a Dwengo experimental board
(http://www.dwengo.org).
Since this board uses a PIC18F4550, I designed two projects: one for PIC18F4550
and one for PIC18F2550. The first can, if desired (uncomment #define DWENGO), use
the Dwengo library to show some debug messages on the Dwengo LCD. The
PIC18F2550 version of the project does not need the Dwengo library.
You do not need the Dwengo board and library to build
this project, just the Microchip
MPLAB IDE and a PICkit2 compatible programmer will do.
The software uses the PWM feature of the PIC18Fx550
to dim the light. It uses 64 steps to do so.
Zip file containing all source code, header files and
project files: Link to MPLAB projects
Connection to a PIC programmer.
Pad 5-6-7-8-9 must be (temporary) wired to a PIC
programmer (5=-, 6=+, 7=VPP, 8=clock, 9=data), e.g. a PICkIt2 compatible
programmer.
Gamma-table:
The software uses a gamma table (g[] in the source
code) to translate percentage to a correct duty cycle for the light that
visually corresponds to that percentage. This table is suitable for LEDs, I
don't know what it will look like on classical light bulbs. It might be needed
to change the table in this case.
Home Back to Electronic
Projects