Silicon ChipAutomatic Car Headlight Controller - October 2013 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Electronic voting is not needed
  4. Feature: Fit Your Cordless Drill With A Lithium Battery Pack by Leo Simpson
  5. Project: SiDRADIO: An Integrated SDR Using A DVB-T Dongle, Pt.1 by Jim Rowe
  6. Project: "Tiny Tim" Horn-Loaded Speaker System by Allan Linton-Smith & Ross Tester
  7. Feature: Narrow-Band Digital Two-Way Radio by Kevin Poulter
  8. Project: "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.1 by Nicholas Vinen & Leo Simpson
  9. Project: Automatic Car Headlight Controller by Nicholas Vinen & John Clarke
  10. Subscriptions
  11. Vintage Radio: A rare 1929 AWA C54 Radiola set rescued from oblivion by Leith Tebbit
  12. PartShop
  13. Book Store
  14. Market Centre
  15. Advertising Index
  16. Outer Front Cover
  17. Outer Back Cover

This is only a preview of the October 2013 issue of Silicon Chip.

You can view 22 of the 96 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "SiDRADIO: An Integrated SDR Using A DVB-T Dongle, Pt.1":
  • SiDRADIO main PCB [06109131] (AUD $20.00)
  • SMD parts for SiDRADIO (Component, AUD $27.50)
  • SiDRADIO front & rear panels [06109132/3] (PCB, AUD $20.00)
  • SiDRADIO PCB pattern (PDF download) [06109131] (Free)
  • SiDRADIO panel artwork (PDF download) (Free)
Articles in this series:
  • SiDRADIO: An Integrated SDR Using A DVB-T Dongle, Pt.1 (October 2013)
  • SiDRADIO: An Integrated SDR Using A DVB-T Dongle, Pt.1 (October 2013)
  • SiDRADIO: Integrated SDR With DVB-T Dongle, Pt.2 (November 2013)
  • SiDRADIO: Integrated SDR With DVB-T Dongle, Pt.2 (November 2013)
Items relevant to ""Tiny Tim" 10W/Channel Stereo Amplifier, Pt.1":
  • Mini Regulator PCB (MiniReg) [18112111] (AUD $5.00)
  • Tiny Tim Power Supply PCB [18110131] (AUD $10.00)
  • Hifi Stereo Headphone Amplifier PCB [01309111] (AUD $17.50)
  • "Tiny Tim" Amplifier Power Supply PCB pattern (PDF download) [18110131] (Free)
  • Hifi Stereo Headphone Amplifier PCB pattern (PDF download) [01309111] (Free)
Articles in this series:
  • "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.1 (October 2013)
  • "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.1 (October 2013)
  • "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.2 (December 2013)
  • "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.2 (December 2013)
  • "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.3 (January 2014)
  • "Tiny Tim" 10W/Channel Stereo Amplifier, Pt.3 (January 2014)
Items relevant to "Automatic Car Headlight Controller":
  • Automatic Car Headlight Controller PCB [03111131] (AUD $10.00)
  • PIC16F88-E/P programmed for the Automatic Car Headlight Controller [0311113A.HEX] (Programmed Microcontroller, AUD $15.00)
  • IRS21850S High-Side Mosfet Driver (Component, AUD $3.00)
  • Firmware (ASM and HEX) files for the Automatic Car Headlight Controller [0311113A.HEX] (Software, Free)
  • Automatic Car Headlight Controller PCB pattern (PDF download) [03111131] (Free)
  • Automatic Car Headlight Controller panel artwork (PDF download) (Free)

Purchase a printed copy of this issue for $10.00.

Automatic Car Headlight Controller Make sure that you’re visible to other drivers at all times Many modern cars have automatic headlights and daytime running lights for great vehicle visibility. Now you can have the same feature on your car and it is a straightforward installation. You will never have to worry about accidentally driving at night with your headlights off and they will turn off automatically after you switch off the engine. By NICHOLAS VINEN & JOHN CLARKE H AVING THE headlights automatically come on at night is good but it also works as you drive through tunnels or if the ambient light drops below a certain level, as it can in late afternoon or during heavy rain. And if that doesn’t convince you of the worth of automatic headlight switching, consider that driving without lights on at night can bring a heavy fine and loss of points from your licence. In essence, this Automatic Headlight Controller monitors the ambient light using an LDR (light-dependent resistor). Once the light drops below a preset level, the low-beam headlights 70  Silicon Chip come on. The unit can also provide operation of the headlights during the day (daytime running) to make your vehicle more visible to others without producing excessive glare. The lights are run with reduced brightness which also lessens the load on the alternator. While the unit will take care of headlight switching most of the time, you can still override it, should you want to. This means that you can turn the lights on at any time but if they are already switched on by the controller, you cannot switch them off manually. Many late-model vehicles with automatic headlights also generally turn the lights on when you unlock the doors (so you can see your way to the car) and leave them on for a short while after turning the ignition off (so you don’t trip over something in the dark) and this unit can do that too. We’ve already mentioned that the Automatic Headlight Controller operates the low-beam headlights and it is effectively connected in parallel with the existing relay or switching for low-beam operation. If you have an older car with dual-filament headlamps (ie, high-beam/low-beam filaments) the circuit is arranged so that when you flash the headlights or siliconchip.com.au The circuit is built into a rugged diecast metal case which can be mounted in the engine compartment (prototype shown). switch to high beam, the Automatic Headlight Controller is switched off. This effectively duplicates the existing headlight switching, to switch off the low beam. If you have a car with dual headlamp bulbs, switching to high-beam operation normally leaves the low beams on as well and the Automatic Headlight Controller can have that arrangement too. The unit is based on a Mosfet driven by a microcontroller. This can switch the low-beam lamps on and off or drive them at reduced power with pulse width modulation for daytime running. Note that we do not recommend the Automatic Headlight Controller for use with cars that have HID (high intensity Xenon discharge) lamps. If you have a late-model car with HID lamps, it probably already has full automatic headlight operation in any case, so this project would be superfluous. However, if you have retrofitted HID lamps to your car, they will not be compatible as the PWM operation of the headlight controller will not function correctly when feeding the high-voltage drivers for the HID lamps. If your car has LED headlights, again it probably already has automatic headlight operation. But if you have managed to do a LED retrofit, it will not work correctly with the Automatic Headlight Controller. Circuit description The full circuit is shown in Fig.1. It uses an IRF1405 N-channel Mosfet (Q1), an IRS21850S high-side Mosfet siliconchip.com.au driver (IC2) and a PIC16F88 microcontroller (IC1). Let’s start by looking at the function which varies the brightness of the low beam lamps from off to full. IC1 provides a PWM (pulse width modulation) signal from its pin 6 and this is fed to pin 2 of IC2. When pin 2 of IC2 is low, pin 7 pulls the gate of Mosfet Q1 low and the low beam lamps are off (unless, off course, they have been switched on separately via the car’s headlight switching). For daytime running mode, IC1 supplies a PWM signal at 25kHz with a typical duty cycle of 75-80% and IC2 feeds this gate signal through to Q1 to turn it on, each time pin 2 of IC2 goes high. However, IC2 is not simply a pass-through switch; it is a high-side Mosfet driver. It’s needed because Mosfet Q1 is used in “high side” switching. Let’s see what this means. High side switching. Simply put, Mosfet Q1 is in series with the +12V line from the car’s Specifications Operating voltage: 11.5-15V DC Operating current: approximately 25mA Quiescent current: typically <1µA Total light power: 1-12A, 12-150W nominal (up to 175W <at> 14.4V) Voltage drop: typically <0.25V Dissipation: typically <3W Under-voltage lockout: ~10.5V battery to the headlights. When Q1 is switched on, its source must go to +12V (or very close to it), in order to feed +12V to the low-beam lamps. However, to turn on fully, the Mosfet needs a gate signal of about 10V. This means that when Q1 is feeding +12V to the lamps, its gate voltage needs to be about +22V. So how do we get a 22V gate signal when the main supply voltage is only 12V? That is the function of IC2. When IC1 feeds a 5V signal to pin 2 of IC2, the high-side driver charges the gate of Mosfet Q1 to about +11.7V, via output pin 7 and the 2.2Ω resistor. This 11.7V comes from its pin 8, which is labelled “VB” (voltage boost). It’s less than the nominal 12V supply because of the voltage drop across Schottky diode D1 which supplies this pin. As soon as Q1 starts to switch on, it allows current to flow through inductor L2 and the car’s headlights and this causes its source voltage to rise. This reduces Q1’s effective gate-source voltage so IC2 must therefore raise the gate voltage further to keep Q1 in a conducting state, up to a maximum of about 22V with the source at 12V as stated above. This is well above IC2’s 12V supply so it must generate a higher voltage rail and it does this using the 1µF boost capacitor, connected between the Mosfet’s source pin and the aforementioned VB supply pin (pin 8). This capacitor starts off charged to +11.7V and as the Mosfet source voltage increases, this is coupled to VB via the capacitor, increasing the boost voltage which ultimately reaches about 23.5V. This drops slightly due to the current which goes into charging the Mosfet’s gate capacitance of about 5.5nF. This boost capacitor recharges the next time Q1 switches off, as the source voltage drops to around 0V, pulled down by the load, ie, the headlights via L2. Note that this means that Q1 can not be driven with a 100% duty cycle as the boost capacitor would have no opportunity to recharge and would eventually discharge, causing Q1 to switch off. Also, we rely on the load being low impedance so that the Mosfet’s source is pulled to 0V fairly rapidly once it switches off. For full brightness, we use a duty cycle of 99.5%, leaving only a small period (<1μs) for the boost capacitor to recharge. In practice, any incandescent or halogen globe has a October 2013  71 72  Silicon Chip siliconchip.com.au JP3 JP2 JP1 8 9 11 10 1 17 18 12 Vdd RB2 RB3 RB5 RB4 AN2 AN0 AN1 RA3 RA7 AN4 Vss 5 RB1 RA6 RB0/CCP1 IC1 PIC16F88 PIC1 6F8 8 PGC/RB6 PGD/RB7 RA5/MCLR 1 µF 7 15 6 2 16 3 100k + 1.5k 3.3k 10k 100 µF PIEZO BUZZER B1 AUTOMATIC HEADLIGHT CONTROLLER VR3 10k DELAY 5 4 13 4 14 1 µF 5 2 3 NC Hin NC 1 Vcc 7 8 1 µF K A ZD2 18V 10nF 10Ω 1 µF ZD1 18V 2.2Ω D1 1N5819 L1 100 µH A K A K E A K G K A D2 1N5819 S D K A K ZD1, ZD2 A D1–D5 8 B L2 3.3 µH 1 IRS21850S 10k 10k 4 100k B E C Q3 BC547 A K IN OUT LM2940T-5V GND 1 µF 100k D5 1N4004 100k F1 15A 47Ω Q1 IRF1405 D3 1N4004 K Q2 A BC557 C D4 1N4004 47Ω L2 = 15 TURNS OF 1.25mm ECW ON A PLASTIC BOBBIN COM 4 Vs Vb 100 µF IN IC2 Hout IRS21850S 6 1 µF GND OUT 10k GND G E LDR D C S IRF1405 B D * SEE TEXT HIGH BEAM* HEADLIGHTS +12V +12V IGNITION +12V CENTRAL LOCKING* λ BC547, BC557 7 6 5 4 3 2 Fig.1: the Automatic Headlights Controller circuit. Microcontroller IC1 monitors the LDR and pot/jumper settings while IC2 drives Mosfet Q1 which acts as a high-side switch, controlling power to the headlights. IC2 & Q1 are driven using PWM with a duty cycle ranging from 0% up to 99.5%. Inductor L2 acts as an EMI filter while L1 filters the power supply for the unit itself. 2013 SC  +5V VR2 10k DAYTIME BRIGHTNESS VR1 10k LIGHT SENSITIVITY EXTERNAL RELAY + DRIVE + 3 2 1 ICSP SOCKET CON1 10k +5V REG1 LM2940CT-5 1 µF 22k TO CASE CON2 1 low enough filament resistance to do the job. ZD1 protects Q1’s gate from voltage spikes which may exceed its 20V gatesource rating, while the 2.2Ω resistor also helps by forming an RC low-pass filter with Q1’s gate capacitance. A snubber network (10Ω/10nF) limits the slew rate of the voltage at Q1’s source to reduce generated electromagnetic interference (EMI). The low-pass filter formed by inductor L2 and the 1µF capacitor eliminates most of the harmonics of the 25kHz square-wave drive, smoothing out the PWM square-wave into a more sinusoidal/triangular waveform. This is virtually identical in configuration to a DC/DC step-down (buck) converter. We aren’t trying to get a completely smooth DC output in this case, hence the relatively low filter component values. Schottky diode (D2) has a similar role to the diode in a buck converter, so that when Q1 switches off, there is a path for current to continue to flow in coil L2 while its magnetic field collapses. Ambient light sensing Light level monitoring is done using an externally mounted light-dependent resistor (LDR) connected between pins 1 & 2 of CON2. This forms a voltage divider in combination with a 100kΩ resistor from the 5V rail. The voltage at pin 3 of IC1 (analog input AN4) varies between a high level of about 4.6V when the LDR is in the dark (high resistance) and a low level of about 0.2V when the LDR is in direct sunlight (low resistance). This voltage is digitally filtered by IC1 and then compared to a voltage threshold set using potentiometer VR1. Some hysteresis is added to this calculation in order to prevent the lights from continually switching on and off at dawn or dusk when the general light level is near the threshold. It also prevents the headlights from switching on and off rapidly as you drive past very bright street lamps. When the result of this comparison changes, after a delay, we change the light brightness by controlling the PWM drive to IC2. The delay in going from daytime running to full brightness is more or less fixed (and short) while the delay in switching back to the daytime running is controlled by trimpot VR3, which varies the voltage fed to the AN2 analog input of IC1. siliconchip.com.au Auto Headlight Controller: Main Features •  Works with incandescent or halogen lights •  Suits majority of vehicles made in the last 25 years without automatic lights (lights switched on high side) •  Optional daytime running lights •  Adjustable light sensitivity •  Adjustable switch-off delay •  Adjustable daytime running brightness from zero up to nearly full brightness •  Under-voltage cut-out, to prevent battery over-discharge and to allow engine starting in cold weather/with a weak battery •  25kHz PWM drive with EMI filtering to minimal radio interference •  Optional ‘leaving home’ feature turns lights on for 30 seconds (adjustable) after doors unlocked (requires central locking) •  Optional ‘coming home’ feature leaves lights on for 30 seconds (adjustable) after ignition is switched off •  •  Virtually no battery drain with lights and ignition off •  Protected against load dumps and other voltage spikes •  Can drive external relay for separately wired tail or instrument lamps •  Fits in a compact metal box, 111 x 60 x 30mm Warning buzzer to indicate if lights have been left on (optional) Trimpot VR2 varies the voltage at analog input AN0 of IC1 and this simply determines the duty cycle at which Q1 is driven for daytime running. This can be set all the way from zero (off) up to maximum brightness. A typical setting is about 75-80% but VR2 is provided for fine-tuning. Power supply The car’s switched +12V ignition line is wired to pin 4 of CON2 so that the unit is switched on with the vehicle. Current flows via a 47Ω resistor and diode D4. This resistor and the following 100µH axial inductor L1 and a 100µF electrolytic capacitor smooths out voltage spikes from the vehicle’s power system (eg, caused by the windscreen wiper motors). Larger spikes are clamped by 18V zener diode ZD2. IC2 runs from this nominal 12V filtered rail while the rest of the circuitry operates from 5V, derived using automotive low-dropout (LDO) regulator REG1. Now if you are trying to start a car with a weak battery (old and/or low ambient temperature), the battery voltage can drop significantly and having the headlights on only makes this worse. IC2 has an internal undervoltage lockout circuit which causes its output to switch off when the supply drops below 8-9V. Taking into account voltage drops in its power supply, this kicks in once the battery voltage drops below about 10.5V. So that the lights can remain on for a time after the ignition is switched off, IC1 can be powered from a permanent 12V rail via PNP transistor Q2. This is switched on by NPN transistor Q3 which is in turn controlled by IC1’s RB2 output (active-high). Extra features IC1 monitors the ignition state via input RA7 and a voltage divider/filter and after the ignition has been off for a certain time period, brings output RB2 low to power itself down completely. In this powered-down state, it consumes virtually no current – just the leakage currents through Mosfet Q1 and transistor Q2, both of which are negligible (typically <1µA). If the car has central locking and the door unlock solenoid is wired to pin 3 of CON2, then when the doors are unlocked, diode D5 becomes forward biased and thus transistor Q2 is switched on, powering up the circuit. IC1 can then check the state of the ignition via input RA7 and, finding it off, will know that it was triggered by the central locking and act accordingly; it normally turns the headlights on for 30 October 2013  73 12V 12V BATTERY POSITIVE 1 µF 10nF 10Ω D2 5819 15T x 1.25mm ECW ZD1 5819 JP3 22k D1 1 µF 1 µF 03111131 VR1 1 µF JP1 ICSP 18V 2.2Ω Brightness 1 1 µF Sensitivity Q1 (UNDER PCB) VR2 10k 100 µF 100 µF REG1 LM2940 VR3 10k ZD2 L2 GND HIGH BEAM POSITIVE 18V D4 47Ω SILICON © 2013 CHIP HL LOW BEAM POSITIVE 100µH 4004 D5 Ign. 1 µF FI 15A FUSEHOLDER Delay 100k 10k 547 10k SWITCHED IGNITION +12V CON2 Lck 4004 LDR 100k + LOW SIDE OF DOOR UNLOCK SOLENOID L1 Q3 10k 557 + D3 4004 1 0 0k Q2 47Ω TO LDR IC1 PIC16F88-E/P (SHIELDED CABLE) IC2 10 0 k JP2 1.5k 3.3k Piezo Buzzer 1 µF GND Fig.2: all parts except for the LDR mount on this PCB which fits into a compact diecast case. Q1 is mounted on the case for heatsinking with its leads poking up the through the board. An on-board 15A blade fuse provides fault protection while externally accessible potentiometer VR1 allows the light sensitivity of the unit to be adjusted. seconds after the doors are unlocked. IC1 can also check whether the headlights have been left on when the ignition is switched off. It does this by briefly turning off drive to Q1 when the ignition is switched off and monitoring the lamp drive voltage using input RA3 (pin 2). If this does not drop to 0V fairly quickly, that means the lights have been turned on manually and left on so it sounds piezo buzzer PB1 by switching its RA6 output on and off to form a series of beeps (250ms on, 250ms off for 10s). CON2’s pin 7 connects to the switch­ ed +12V line from the high-beam circuit of the car. This is monitored by pin 7 of microcontroller IC1 via a resistive voltage divider comprising 3.3kΩ and 1.5kΩ resistors. When pin 7 is pulled high by the high-beam circuit, IC1 kills the PWM drive from its pin 6 and therefore switches off the lowbeam supply to the headlights. This option only needs to be connected if the car’s headlights have dualfilament lamps. This is an important safety feature because we don’t want both filaments in the headlights turned on at the same time. If they were, the bulb would rapidly fail and you could be left with no headlights at all! Finally, three of IC1’s input pins (RB3, RB4 & RB5) are connected to headers which set various linking options (explained below). IC1 has internal pull-ups on all of its port B inputs and if any of these jumpers are fitted, they pull the connected input low. amount of solder on one pad (say, pin 8 at upper-right) and while heating this solder, slide the IC into place, ensuring that pin 1 (indicated by dot, divot or bevelled edge) is at upper-left. Check its alignment and if the pins are not properly centred on the pads, re-melt the solder and nudge it into place. Once the alignment is correct, solder the rest of the pins, then add a little extra solder to that first pin, to refresh the joint. If any pins are bridged, clean up the excess solder using solder wick. Proceed by installing all the resistors in the usual manner, checking each value with a DMM. Follow with the diodes; these are all orientated with their cathode stripes either towards the right or top edge of the PCB. Note that there are three different types which must not be mixed up. Construction Most parts mount on a single PCB coded 03111131 and measuring 98 x 53mm. Fig.2 shows the PCB layout. Before starting assembly, place the board in the bottom of the diecast box with its righthand side (ie, with the cut-outs) hard against the end and mark the positions for the three mounting holes on the base of the box. You should also mark the centre of the tab hole for Mosfet Q1. Don’t drill the holes yet though – that step comes later. That done, you can start fitting the parts on the PCB. IC2 is an SMD and it’s easiest to fit this first. Put a small   Capacitor Codes Value µF Value IEC Code EIA Code 1µF 1µF 1u0 105 10nF 0.01µF 10n 103 Table 1: Resistor Colour Codes   o o o o o o o o o No.   4   1   5   1   1   2   1   1 74  Silicon Chip Value 100kΩ 22kΩ 10kΩ 3.3kΩ 1.5kΩ 47Ω 10Ω 2.2Ω 4-Band Code (1%) brown black yellow brown red red orange brown brown black orange brown orange orange red brown brown green red brown yellow violet black brown brown black black brown red red gold brown 5-Band Code (1%) brown black black orange brown red red black red brown brown black black red brown orange orange black brown brown brown green black brown brown yellow violet black gold brown brown black black gold brown red red black silver brown siliconchip.com.au The external leads are fed through cable glands at one end of the case. Note that this photo shows a prototype unit, with several changes later made to the PCB to obtain the final version shown in Fig.2 Follow with axial RF inductor L1, then mount an 18-pin DIL socket for IC1 with the notch at the top. REG1 can then go in – its leads must be bent down about 6mm from its metal tab so that they fit through the pads while the tab mounting hole lines up with that on the PCB. Use an M3 x 10mm machine screw, nut and shakeproof washer to attach it firmly to the PCB (screw head on the underside) and then solder and trim its leads. Next, install the ceramic capacitors, then fit the small-signal transistors. You may need to bend the latter’s leads to fit the triangular pad pattern on the PCB; don’t get the two different types mixed up. Trimpots VR2 & VR3 can be soldered next, followed by the pin headers. Follow with the electrolytic capacitors, making sure that the longer (+) leads go towards the top of the board. That done, dovetail the three terminal blocks (two 2-way & one 3-way) together to form a 7-way block and fit this with the wire entry holes towards the lefthand edge of the PCB. If fitting the optional warning piezo buzzer, do it now but note that this only makes sense if the unit is to be installed in the vehicle’s cabin area. If it’s going in the engine bay, you can fit a pin header here instead and run leads back into the cabin so the buzzer can be heard. The best technique is to add a little solder to wet the iron (turn up the temperature if you can), hold it at the junction of the fuseholder pin and PCB pad for a few seconds to heat up the metal, then add solder while moving the iron around the outside the pin. Remove the iron as soon as a good fillet has formed to reduce the chance of the solder flowing through the hole. Fuseholder Winding inductor L2 We’re using a PCB-mount blade fuseholder as these are designed for automotive use. Fit this now by pushing it all the way down through the mounting holes (it may be a tight fit) and then soldering the four pins. This soldering is a bit tricky, partly because you need a very hot iron but also because you have to be careful not to let any solder flow down through the hole in the middle of each pin, as this could prevent the fuse from being inserted. Do not solder the holder with a fuse in place! An air-cored inductor is used for the filter since these do not saturate and thus can handle the high current. To wind it, first scrape about 10mm of insulation off one end of a 1m length of 1.25mm diameter enamelled copper wire using a hobby knife or fine emery paper. That done, use pliers to bend this end at right angles just beyond where the bare copper starts and slide it into one of the slots on the bobbin. Wind on 15.5 turns, then bend the wire to pass through the opposite slot. This is much easier to do if you make a M3 NUT M3 NUT M3 NUT M3 STAR WASHER 2 x M3 NYLON NUTS INSULATING BUSH 5819 PCB 2 x M3 NYLON NUTS Q1 TO-220 SILICONE INSULATING WASHER M3 x 15 mm SCREW M3 x 10 mm SCREWS Fig.3: this cross-section diagram shows how Mosfet Q1 and the PCB are mounted in the case. Pairs of Nylon M3 nuts are used as spacers, so that the PCB is at the right height for Q1 to fit underneath and so that fuse F1 clears the lid of the case. Note that the mounting screw at lower-left is longer, to allow a star washer to be fitted for good earthing contact. siliconchip.com.au October 2013  75 Parts List 1 double-sided PCB, code 03111131, 98 x 53mm 1 diecast aluminium box, 111 x 60 x 30mm (Jaycar HB5062) 2 small cable glands (to suit 3-6.5mm diameter cable, eg, Jaycar HP0720, Altronics H4304) 1 PCB-mount blade fuse holder (Altronics S6040) (F1) 1 15A blade fuse (F1) 1 10kΩ linear 9mm PCB-mount horizontal potentiometer (VR1) 2 10kΩ mini horizontal trimpots (VR2,VR3) 1 18-pin DIL socket 1 100µH axial RF inductor (L1) 1 pot core bobbin (Jaycar LF1062, Altronics L5305) 2 2-way terminal blocks and 1 3-way terminal block (CON2) 1 5-pin header (CON1) 3 2-pin headers with jumper shunts (JP1-JP3) 1 100kΩ LDR (LDR1) (Jaycar RD3480, Altronics Z1619) 1 TO-220 insulating washer and plastic mounting bush 1 1m length 1.25mm-diameter enamelled copper wire 1 25mm length 25mm diameter heatshrink tubing 1 short length 5mm diameter heatshrink tubing 1 length 15A twin-core automotive cable 1 length single-core shielded cable 2 lengths 7.5A automotive wire, green (ground) & red (ignition power) 1 length 7.5A automotive wire, blue (central locking; optional) 1 M3 x 15mm machine screw 5 M3 x 10mm machine screws winding jig using an M5 x 70mm bolt and various scrap pieces of PCB material and timber – see page 67, SILICON CHIP, August 2011. If you don’t want to do that, wind some electrical tape around a solid rod to make it a snug fit through the middle of the former, otherwise the bobbin’s thin plastic is likely to crack during winding. Once finished, slip a short length of 20-25mm-diameter heatshrink tubing over the bobbin and shrink it down. 76  Silicon Chip 5 M3 nuts 5 M3 shakeproof washers 7 M3 Nylon nuts 1 crimp eyelet connector 1 small PCB-mount 5V piezo buzzer (optional) (Altronics S6104 or S6105) Miscellaneous Automotive connectors, heatshrink tubing, etc (Note: extra parts may be required to mount box, LDR, etc) Semiconductors 1 PIC16F88-E/P microcontroller programmed with 0311113A. HEX (IC1) 1 IRS21850S high-side Mosfet driver (element14 1925162) (IC2) 1 LM2940CT-5 5V LDO automotive regulator (REG1) 1 IRF1405 automotive N-channel Mosfet (Q1) 1 BC557 PNP transistor (Q2) 1 BC547 NPN transistor (Q3) 2 1N5819 1A Schottky diodes (D1,D2) 3 1N4004 1A diodes (D3-D5) 2 1N5404 3A diodes (for tail light & instrument light wiring; see text) 2 18V 1W Zener diodes (ZD1,ZD2) Capacitors 2 100µF 25V electrolytic 7 1µF MMC 1 10nF MMC or ceramic disc Resistors (0.25W, 1%) 4 100kΩ 1 1.5kΩ 1 22kΩ 2 47Ω 5 10kΩ 1 10Ω 1 3.3kΩ 1 2.2Ω (5%) Once that’s in place, trim off the excess wire and strip the insulation from the other end. The inductor can then be mounted on the board. Be sure to solder its leads on both the top and bottom of the PCB, as this makes a measurable difference to the output voltage and thus may have an impact on headlight brightness. Completing the assembly Now for the final parts. Fit VR1 in place, making sure it sits flush against the PCB surface before soldering its pins, then plug IC1 into its socket (with pin 1 at upper-left). Note that IC1 will be pre-programmed if you purchase it as part of a kit or directly from SILICON CHIP. If not, you will have to program it yourself and you should that now via the ICSP port using 5V power from a PICkit programmer or similar. Now fit fuse F1 and the board is complete except for Q1 which is the next step. First, drill the four 3mm holes in the bottom of the diecast box but about 0.5-1mm closer to the righthand end of the box than where you marked them. That’s necessary because the sides of the box taper outwards towards the top. You will also need to drill holes for VR1 and the two cable glands. The hole for VR1 is centred on the righthand end of the box and placed 13mm up from the base. Enlarge it to 7mm diameter. Note that it must be placed fairly accurately as the box is only just tall enough to fit the blade fuse. The holes for the two cable glands go in the other end of the box, 14mm from the bottom and 20mm apart, equidistant from the centre line. These holes must also be positioned accurately as the internal nuts will only just fit sideby-side in the case. You can check their position by temporarily placing these nuts on the inside face. Drill the holes using a pilot drill to begin with, then enlarge them to 12mm using a tapered reamer until everything fits. De-burr these holes and clean off the swarf, then bend Q1’s leads up about 6mm from the tab, so that when fed through the PCB pads from the bottom, the tab mounting hole is centred on the PCB access hole – see Fig.3. Feed an M3 x 10mm machine screw into its mounting hole from the underside, then slip an insulating washer over this, followed by Q1 (tab-side down) then an insulating bush and M3 nut. Tighten the nut while making sure that the washer and Q1 both face to the left and do not rotate. That done, check that the tab is properly isolated from the case using a DMM set to measure resistance – the reading should be very high (many megohms). Now feed three M3 machine screws up from the underside of the case for mounting the PCB. Two are 10mmlong screws while the third, at lowerleft, is 15mm long. Fit two Nylon M3 nuts to each of these screws and do siliconchip.com.au them up all the way; these form the spacers for the PCB. Next, remove VR1’s nut and feed the pot shaft through its hole in the case, then lower the board down onto the three mounting posts. Use a shakeproof washer and nut for the lower-left mounting hole with the longer screw, as this earths the unit. Attach nuts to the other two mounting screws. Note that while you can use regular M3 nuts for both, we decided to use a Nylon nut for the upper-left hole as it’s quite close to D3’s anode lead. Once the PCB is secured in place, attach VR1’s nut and fit the two cable glands to the case. Do their mounting nuts up firmly so that they are properly secured. Setting the options Jumpers JP1-JP3 set various options, depending on whether a shunt is present or not. These are: •  JP1 – ‘coming home’ lights: if fitted and the LDR is in darkness, runs the lights at 75% duty cycle for 30 seconds after the ignition is switched off. This illuminates the area around the vehicle as you move away from it and is a standard feature of most vehicles with automatic headlights. The delay can be adjusted, although the default should suit most users (see below). •  JP2 – ‘leaving home’ lights: if fitted and the LDR is in darkness, runs the lights at 75% duty cycle for 30 seconds after the doors are unlocked (this also requires connection to the central locking system). This illuminates the area around the vehicle as you get into it and may also help you locate the vehicle in a dark parking lot. This 30s delay period can also be adjusted – see below. •  JP3 – timing periods: allows the ‘coming home’, ‘leaving home’ and warning beeper durations to be set. Each can be from 1-63s. To do this, set pots VR1-VR3 fully anti-clockwise for 1s and fully clockwise for 63s. VR1 sets the ‘coming home’ time, VR2 ‘leaving home’ and VR3 the warning beeper time-out. When set, insert JP3, power up the unit via the ignition switch for a few seconds, power it down and remove JP3, then reset VR1-VR3 to their normal positions. External wiring It’s easiest to wire up the heavyduty leads for the lights first. Begin by stripping 20mm of the outer insulation siliconchip.com.au +12V ON +12V PARK BRAKE SWITCH OFF LIGHTS ON +12V +12V +12V PARK OFF FLASH OFF ON HIGH BEAMS FLASH OFF ON BULB HIGH BEAM SAMPLE WIRING FOR DUAL-FILAMENT HEADLAMPS HEAD LIGHT REAR LIGHT LOW BEAM TAIL LIGHT PARK BRAKE LIGHT Fig.4(a): this conceptual diagram shows how a car with dual-filament headlight bulbs might be wired, so that only one of the two filaments (low or high beams) is powered at any given time. +12V ON +12V PARK BRAKE SWITCH OFF LIGHTS ON +12V +12V +12V PARK OFF +12V FLASH HIGH BEAMS ON OFF SAMPLE WIRING FOR DUAL-BULB HEADLAMPS HEAD LIGHT HIGH BEAM LOW BEAM REAR LIGHT PARK TAIL LIGHT BRAKE LIGHT Fig.4(b): this shows the possible arrangement when separate lamps are used. In this case, the low-beams and high-beams can be powered simultaneously but only if both the light switch and high-beam switch are on. from the twin 15A cable and then 5mm of the inner insulation. Lightly twist the copper strands together and then insert the cable through the lower gland. Next, guide the two cable wires into their respective terminal block holes, with red for the incoming 12V supply and white for the low-beam lights (LB) output. Tighten the terminal screws firmly and check that there are no stray copper strands poking out, then tighten the gland clamp. The other connections go via the second gland. Note that while we have shown a single 4-core cable in our photos, in practice we found it easier to use separate 7.5A automotive wires for the switched ignition line and central locking (optional), plus a single-core shielded cable for the LDR. We connected ground via the unit’s metal case. Feed these wires in and screw them into the terminal block – you may find it helpful to use tweezers or small pliers to guide them and hold them in while doing so. You may need to double over the internal conductor of the shielded cable to make it thick October 2013  77 CENTRAL LOCKING (IF PRESENT) LDR BATTERY + IGNITION HEADLIGHT CONTROLLER + GND 1 LDR 2 LCK 3 IGN 4 12V 5 LB 6 HB 7 CON2 DOOR UNLOCK SOLENOID 1 SILICON CHIP ICSP D1 (SEE TEXT) GND 03111131 HIGH-BEAM HEAD LIGHTS LOW-BEAM HEAD LIGHTS (SECOND 1N5404 ONLY NEEDED IF TAIL LIGHTS WIRED SEPARATELY) 1N5404 1N5404 OPTION 1 TAIL LIGHTS Vehicle connections DIMMING INSTRUMENT LIGHTS Fig.5(a): here’s how to wire up the unit using the simplest approach to powering the tail and instrument lights (number plate lights not shown). When the low beam output is driven high, the added diodes are forward biased so that all the lights are powered. The diodes can be connected inline with the wiring (see text). CENTRAL LOCKING (IF PRESENT) LDR BATTERY + IGNITION + GND 1 LDR 2 LCK 3 IGN 4 12V 5 LB 6 HB 7 HEADLIGHT CONTROLLER CON2 DOOR UNLOCK SOLENOID 1 SILICON CHIP ICSP D1 (SEE TEXT) GND 03111131 HIGH-BEAM HEAD LIGHTS LOW-BEAM HEAD LIGHTS 1N5404 (SECOND 1N5404 ONLY NEEDED IF TAIL LIGHTS WIRED SEPARATELY) OPTION 2 TAIL LIGHTS NO DC RELAY SWITCH + – COM DIMMING INSTRUMENT LIGHTS Fig.5(b): an external relay board can be used to switch the supply rail to the instrument lights to prevent them from also coming on when the daytime running lights are powered. The drive for this relay comes from CON1 on the PCB. The rest of the wiring remains the same. enough to be properly held by the terminal. Depending on your car’s high beam switching arrangement, you may also have to run a wire from pin 7 of CON2 to the switched +12V side of one of the high-beam filaments. This is necessary for vehicles where the low beam filaments are switched off when the high beams are on, eg, when dual-filament headlamp bulbs are used but not in the case of individual bulbs. 78  Silicon Chip This should not be an issue as long as the unit is mounted either inside the vehicle cabin or under the bonnet in a location where it is protected from large volume or high-pressure water ingress. If unsure, you can apply neutralcure silicone sealant around the inside of VR1’s mounting hole and run a bead around the top of the box before screwing the lid in place. However, make sure everything is working to your satisfaction before ‘gluing’ the lid in place in this manner. The easiest way to check is to turn on the low-beam lights, note which filaments are powered, then switch on the high beams and check to see whether the low-beam filaments have gone off. If so, you will need that extra wire so that the unit can sense when the high beams are activated. With those wires in place, do up the second cable gland wire clamp. Note that while we are using cable glands, the box is not fully watertight. The first thing you need to do before fitting the unit to a vehicle is figure out what wiring is required. While many cars will have a relay to switch the headlights, some older models may switch them directly. In these latter vehicles, it may be practical to mount the unit inside the cabin, near the steering column as the headlight and ignition wiring will both be present in that area. Otherwise, the unit is probably best located near the headlight relay. While the wiring will vary from vehicle to vehicle, you can refer to Figs.4(a) & (b) as a guide. These are simplified conceptual diagrams but show the general arrangement to be expected. Fig.4(a) shows the wiring when dual-filament headlight bulbs are used, such that only one filament can be powered at a time. Fig.4(b) shows what to expect when the low and high beam lamps are separate bulbs (possibly in separate housings). Once you have chosen a location and figured out how to attach the unit to the chassis, you will then need to decide where to position the LDR. In cars that have automatic headlights, this is usually located on top of the dash binnacle so that it ‘looks out’ through the windscreen. The problem is, trying to retrofit a sensor in this position can be almost impossible in modern cars, especially if you also have to run a wire through the firewall in order to connect it to the controller. If you are mounting the controller in the engine compartment, then the easiest place to mount the LDR will probably be in the plenum chamber (ie, the chamber below the windscreen wipers that’s used to drain water from the windscreen). The LDR will have to be suitably waterproofed using heatshrink tubing and silicone and siliconchip.com.au CENTRAL LOCKING (IF PRESENT) LDR BATTERY + IGNITION + GND 1 LDR 2 LCK 3 IGN 4 12V 5 LB 6 HB 7 HEADLIGHT CONTROLLER CON2 DOOR UNLOCK SOLENOID 1 SILICON CHIP ICSP D1 (SEE TEXT) GND 03111131 HIGH-BEAM HEAD LIGHTS NO DC RELAY SWITCH NO + DC RELAY SWITCH – COM LOW-BEAM HEAD LIGHTS – COM OPTION 3 TAIL LIGHTS + DIMMING INSTRUMENT LIGHTS Fig.5(c): the tail lights can also be switched using a relay board, driven from the same microcontroller outputs. This has the advantage that there is no loss in brightness due to the relay and the tail lights will now remain off when the daytime running lights are on. should be connected to the controller via a shielded lead (shield to GND). Position the LDR so that its surface has a clear view of the ambient light. Depending on the arrangement, the LDR can then be secured in place using cable ties or perhaps silicone. You could also glue a piece of clear plastic on top of it, to protect the sensor element. Another possibility is to secure the LDR so that it looks out through the front grille but again, make sure it is waterproofed. Alternatively, if the controller is to be mounted under the dashboard (eg, in an older car), then it should be possible to mount the LDR next to the windscreen. It might even be possible to attach it to a mobile phone mounting bracket. Having mounted the control unit and LDR, make the following connections (see Fig.5(a)): (1)  Run a wire from the unit’s metal case to a chassis ground point. Alternatively, you could connect a ground wire to pin 1 of CON2 and run it out through the upper cable gland. (2) Connect the 15A wire from pin 6 of CON2 (white) to the positive (switched) side of the low beam headlights, either to the lights themselves, the headlight wiring or the control relay/switch. (3)  Connect the 15A wire from pin 5 of CON2 (red) to the positive terminal siliconchip.com.au of the car’s battery. It’s probably a good idea to do this via the vehicle’s headlight fuse, even though there is an on-board fuse. This connection can be made to the battery side of the vehicle’s headlight relay/switch. (4)  If you determined earlier that you need the high-beam sensing wire, connect pin 7 of CON2 to the switched high beam +12V line. Otherwise leave pin 7 of CON2 open. (5)  Connect the LDR across the inner and outer conductors of the shielded cable (ie, between pin 1 of CON2 [GND] and pin 2). (6)  Wire the vehicle’s switched ignition line to pin 3 of CON2. Note that many vehicles have two such lines; one is disconnected during ‘cranking’ while the other isn’t. We recommend the latter but you can use the former in which case you may also want to disable the ‘coming home’ feature (ie, leave JP1 out). (7)  Optional – make a connection from pin 2 of CON2 to the driver’s door central locking solenoid. There will be three wires going to the solenoid – one connected to +12V and two which are pulled low, one to lock the door and one to unlock it. Connect the wire to the unlock line. Tail & instrument lights The unit should now be able to switch the headlights on in the dark but note that, in most vehicles, the tail and instrument (dashboard) lights are wired independently of the headlights. This is because switching on the parking lights also switches on the tail lights (and number plate lamp). In some cases, the tail lights may even be switched on individually when parked (ie, only the side facing the road). Ideally, all these lights come on automatically. The simplest solution is to use two or three power diodes so that when voltage is supplied to the headlights, it also flows to the tail and instrument lights without the reverse necessarily being true. Typical light wattages are as follows: headlights 2 x 55W, tail lights 2 x 5W, number plate lamp 6W and instruments 3-4W for a total of 130W (nominal). The controller can supply enough current to run them all. The simplest arrangement is shown in Fig.5(a). Basically, it’s just a matter of connecting the diodes with their anodes from the switched headlight +12V line to the positive (switched) side of the tail lights and instrument lights. When driven by this unit, they will receive a lower voltage than the headlights (by about 0.7V) however this should still be sufficient. If you wish, you can reduce the voltage drop by using 3A Schottky diodes instead (1N5822). Either way, the diodes can be soldered in-line with the wiring, covered with heatshrink tubing and then strapped to the wiring loom with cable ties, so they don’t float around. Relay switching Using diodes means that the tail and instrument lights will also be powered (at reduced brightness) during the day with daytime running lights. This is probably desirable for the tail lights but it could be detrimental to instrument visibility. If you want to prevent this, rather than using diodes, use a relay or relays to switch the tail and/or instrument lights. IC1 brings pins 4 & 5 of the ICSP header high when the controller turns the headlights on at full brightness. The adjacent pin 3 is connected to ground. Thus, you can connect a thin figure-8 or shielded cable to pins 3 & 4 and run this out via the upper cable gland to a relay board. Our DC Relay Switch (SILICON CHIP, November 2006) is suitable and is available as a kit from Jaycar (KC5434). By using the control October 2013  79 problems, we have specified 15 turns just to be safe. If you are unhappy with the resulting brightness, you can reduce the number of turns on L2, especially if you are in an urban area where radio signals are strong. Defeat switch The completed unit can be waterproofed by smearing silicone around the inside of VR1’s mounting hole, the cable glands and the edge of the lid. signal from the controller, this can then be used to switch the tail and/or instrument lights on at night. unless they are within its current and power ratings, which is quite unlikely. High beams In a typical situation, the voltage loss across the unit with the headlights on is around 0.25V. This is low enough that no reduction in brightness should be apparent, although you may notice that the lights are slightly brighter when switched on manually. The 15 turns specified for inductor L2 is a compromise; with 10 turns, the voltage loss is a little lower (and thus headlight brightness higher) but the reduction in filtering causes some (barely detectable) AM radio interference. While we don’t think this level of interference will cause any real This unit should not be connected so as to turn on the high beams automatically. In most cases, it will be necessary for the driver to turn on the headlights manually in order to be able to activate the high-beams, using a stalk on the steering column. In some cases, it may be possible to wire the unit so that it can power either the low or high beams depending on the position of the steering column stalk but make sure that for vehicles where both lamps are lit simultaneously, the unit will not be driving both Headlight brightness LDR The LDR should be waterproofed using heatshrink tubing and silicone. It can be mounted in the plenum chamber and secured to an adjacent washer hose or to some other convenient point using cable ties. 80  Silicon Chip Note that while you can still manually switch the headlights to come on, you can’t turn them off if the Automatic Headlight Controller unit decides they should be on. This should not be an issue but it would be possible to wire up a ‘defeat’ switch in series with the switched ignition line. However be careful if you do this since it would be possible to turn it off and forget, thus defeating the purpose of the unit! Final adjustments & testing As mentioned, VR1 sets the light sensitivity threshold while VR2 sets the daytime running lights brightness (full anti-clockwise disables them). VR3 adjusts the switch-off delay. Since the light sensitivity is the most critical setting, VR1 is externally accessible. For default settings, start with VR1 at about 10 o’clock, VR2 at about 2 o’clock and VR3 about 12 o’clock. If you find it’s getting dark and the lights haven’t come on, turn VR1 clockwise. If they come on when it’s still too light, turn VR1 anti-clockwise. If the lights turn off too quickly when moving through lit areas at dawn or dusk, turn VR3 clockwise. Conversely, if the lights stay on too long (eg, when coming out of a tunnel), turn VR3 anticlockwise. Finally, if the daytime running lights brightness is too high or low, adjust VR2. When you have the unit up and running, cover the LDR so that it is dark and check that all the required lights come on properly, ie, low-beam headlights, tail lights, instrument lights and number plate light(s). These are all required to be lit while driving at night. Also check that the high beams do not turn on automatically but that they can still be activated; as mentioned earlier, you may have to switch the lights manually to the “on” position before the high beams will operate. Finally, note that you may still need to turn the lights on manually when there is reduced visibility due to rain, mist or fog if the ambient light level SC is still high. siliconchip.com.au