Car
Courtesy Light
1.
Introduction
A car courtesy light in a standard car without a board
computer is often a very simple thing: you open the door, the interior light is
switched on, you close the door, the light is switched off.
For convenience, it is very nice to have the light
switched on a little longer after the door is closed, for instance to find your
keys and start the engine.
There are many car courtesy light schematics and
ready-to-use devices around on the internet, but this one has a few interesting
properties that I could not find on any of them, and that I really wanted. That’s
why I decided to build it myself.
This circuit is based around the 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 car courtesy light
extender/dimmer might look like overkill at first glance. A simple 555 timer or
a few transistors/resistors/capacitors also might do the job, but considering
the characteristics I wanted the device to have, a microcontroller really ended
up to be the way to go.
These characteristics are:
-
Zero power consumption in standby mode
-
Absolutely no change needed on the existing wiring, no
need to interrupt the wire from door-switch to the light bulb or from +12V to
light bulb. In fact, this device use only a one-wire interface to the existing
car courtesy light (plus 2 wires for power)
-
Possibility to add an optional extra switch for manual
control, with soft start and soft stop (auto fade in and fade out)
-
Possibility to immediately switch off the light when
an event takes place, for instance when the alarm system is armed or when the
car ignition is on
-
Adjustable period for extending the light-on time
after door is closed, and adjustable period for the dim-to-off and dim-to-on
time
-
Usable for LED lights or classic light bulbs
3.
Usage/connection
to existing car courtesy light
A typical car courtesy light schematic diagram looks
like this:
After adding this car courtesy light extender device,
the wiring will look like this:
As you can see only one wire is connected to the
existing wiring, this can be done at any convenient point (e.g. near the light
bulb, near the door sensor or anywhere in between). This connection is referred
to as PAD3 in the schematic diagram later on.
Optionally, an extra switch (S2, toggle type) can be
added for manually controlling the light (PAD4 in the schematic later on). Also
an extra signal coming from other systems (e.g. motor on, alarm armed, …) can
be used to immediately cut off the light (S3, PAD10 in the schematic). This
results in a schematic diagram like this:
4.
Schematic diagram
5.
Explanation of the schematic
diagram
(Refer to the schematic diagram).
The tricky thing is that we only have one wire to
interface with the existing car courtesy light, and that this one wire is
already connected to the light bulb and to the door switch. We don't want to
change anything on the existing wiring.
This is why we use relay K1. It is in fact connected
parallel to the light bulb (not considering blocking relay K3 at this moment).
This relay will be used to monitor the light bulb while it is lit (car door
open) and especially when it is unlit again because the door is closed. See later
on.
But first, let's have a look at power control to the
circuit. Since standby power must be zero, relays are used to accomplish this.
The voltage regulator (IC2) is normally not connected to the 12V car supply.
When the car door is opened, and thus relay K1 is activated, power is provided
to the voltage regulator and to the PIC. First thing the PIC software will do,
is to insure it will keep itself powered by activating relay K4 (by means of
port RA4).
As soon as the PIC is running, it will do nothing but
wait until the door is closed, by means of relay K1 and input port RB0. This is
referred to “DOOR MODE” in the software. When RB0 is on ground level, we know
the door is closed. The light will go out but immediately the PIC takes over
and puts the light back on by means of a PWM signal going out on port RC1 and
transistor Q1 (PWM on 100% duty cycle). Then the PIC will wait for 25 seconds
(this can be modified in software) and then start to dim the light bulb using
PWM (from 100% to 0% in 3 seconds). Before the dim-period is started, relay K3
is activated to prevent relay K1 buzzing because of the PWM voltage on it's
coil (remember K1 is parallel to the light bulb). After dimming is finished to
zero percent, all work is done and the PIC switches off all relays including K4
thus putting the whole device off.
The cycle of waiting 25 seconds while in “door mode”
will be interrupted if RB2 is put on ground level by an external system. In
this case the PIC will start the dim-period immediately.
Another way of activating the light bulb is by means
of the manual switch, which operates relay K2. This will do about the same
(activate the voltage regulator to put the PIC on power), but because this also
grounds input RB1 the software will go in another mode. This is referred to as
“manual mode” in the software. This mode will take care of a soft start of the
light bulb (dimming from 0% to 100% in 3 seconds), waiting until RB1 goes off
ground and then start to dim the light (100% to 0% in 3 seconds) and switch off
power.
6.
Prototype
The device was first prototyped on a Dwengo board and
its breadboard. Because of the 4 relays this looks a bit messy:
Below left is an automotive LED light bulb. Below
right the Dwengo programmer.
7.
The
printed circuit board
The pcb is designed for smd components.
It is single sided, with 8 connection wires. Actually
it was designed as a double sided board in Eagle (from Cadsoft), but I was too lazy to make a
double sided board so the bottom side became connection wires on the top side
(I put squares over the vias).
The big transistor (IRFZ34N) is actually not an SMD
component, therefore 3 holes must be drilled to fit this. It is best to fit it
at the bottom side.
PDF file (mirrored) to print on a transparent: Print-layout
PDF file showing PCB with components. The red lines
are the copper lines, the blue lines are the wire connections: Print-layout complete
8.
The final device
Below on the picture is the final device. Notice the
wires to the outside world: left top is ground and light-control, left centre
is +12V, the left bottom green wire is to the manual switch. The wire on the
right is for the external trigger.
The PCB could of course been made much smaller if I
put more effort on it.
The white squares are the relays. These are all Omron
G6K-2F 5V SMD type (polarized).
The connector marked “-+MCD” is the in-circuit
programming interface to connect with the programmer (connections: - =, ground
+ = +5V, M = reset, C = clock, D = data).
Built into a transparant plastic case (5 x 7 x 1 cm):
9.
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 final design). The first one also uses the Dwengo
library to show some debug messages on the Dwengo LCD, the second one 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 PIC18F2550
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.
10.
Customization
If you want to customize the software, have a look at CarCourtesyLight.c in which you can change
various defines:
TIMEOUT_SECONDS value in seconds: the higher the
value, the longer the extended cycle takes (time before light starts to fade
out)
SOFT_STOP_DOOR the higher the value, the longer it
takes to fade out the light (time of dim-cycle)
SOFT_START_MANUAL same but for soft starting (fade in)
with manual switch
SOFT_STOP_MANUAL same but for soft stopping (fade out)
with manual switch
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