Car front lights controller

From uCtrl
This page is kept for historical interest. It may document projects or methods that are obsolete and/or no longer relevant. The information here is not kept up-to-date.

This car has been scrapped.
Car with running lights
Car with high beam

Information

This unit is used for controlling additional car headlights, such as high beams and fog/running lights. The module also controls a RGB LED on the dashboard, indicating the status of the lights and used as a alarm LED. It's connected directly to the cars battery, and sensing the status of the cars built-in park light, low beam and high beam.

Fog/running lights

The fog/running lights are controlled in such a way that they do not violate Norwegian law. Meaning; they can only be on during the day and must be used together with the parking lights. They can not be used together with low or high beam. Using the switch it's possible to still use the fog/running lights together with the low beam, but this is only permitted in extreme weather conditions or fog. The fog/running lights are turned or kept on for one minute after the car has been turned off, to illuminate the front of the car in dark situations. They also have a three second start up delay, so not to

High beam

The high beam is activated together with the cars build-in high beam lamps. If the fog/running lights are on they will be turned off, even if just using the headlamp flasher. The use of fog/running lights together with the high beam is according to Norwegian law only permitted when running at low speed (5-15 mph), but this combination is not possible.

I/O

Inputs

  1. PD0 Parking lights
  2. PD1 Low beam
  3. PD2 High beam
  4. PD3 Switch

Outputs

  1. PB3 Green LED indication
  2. PB4 Blue LED indication
  3. PB5 Signal active
  4. PB6 Fog/running lights
  5. PB7 High beam

Wire connection

# Color Function
1 Red 13.8V +
2 Black 0V
3 Green Parking lights in +
4 Brown Parking lights in -
5 Yellow Low beam in +
6 Gray Low beam in -
7 Purple High beam in +
8 White High beam in -
9 Pink Switch in +
10 Blue Switch in -
11 & 12 Yellow (separate) Relays fog/running lights and high beam out -
13 Red (separate) Green LED indication
14 White (separate) Blue LED indication
15 Yellow (separate) Signal active

LED indication

A RBG LED is used for indication of which lights are active.

  • Red High beams
  • Green bright Running lights
  • Green dimmed Fog lights
  • Blue Alarm LED

Wire connection

# Color Function
1 Yellow 13.8V +
2 Brown Red -
3 Green Green -
4 White Blue -

Images

Schematic drawing

Car-front-lights-controller-circuit-q0961q.png

Parts list

Qty. Part
1 AVR ATtiny2313-20PU, DIL-20, 20 MHz, 18 I/Os
1 Capacitor, aluminium electrolytic, 10 µF, 25V
2 Capacitor, aluminium electrolytic, 47 µF, 25V
1 Capacitor, ceramic, 1 nF, 100V
1 Capacitor, metallized polyester foil, 0.01 µF
2 m Control cable, 10-cores, 0.14mm2, 250 V, Ø 5.4mm
2 m Control cable, 4-cores, 0.25mm2, 250 V, Ø 4.6mm
1 DIL socket, 16-pin, 7.62mm
1 DIL socket, 20-pin, 7.62mm
2 Diode, rectifier, 1 A, 400V, 1N4004
1 Enclosure, plastic (1551), 35x35x15mm
1 Enclosure, plastic (1591 FL), 100x50x25mm, flange
1 Fuse 5x20 mm, 500 mA, fast-acting
1 Fuse holder, wire, 5x20 / 6.3x32mm
1 Heatsink, 27.3K/W, 19mm, attachable, TO220
1 LED 5mm clear, RBG, 2.1 3.3 3.4V, 20mA, 25°
1 LED lens 5mm, CLB 300 low, Clear
1 Optocoupler, 4-channels, PC817
32 cm2 PCB, stripboard, 100x160mm, 160cm2
4 Resistor, carbon film, 0.25W, 330 Ω, 5%
1 Resistor, carbon film, 0.25W, 680 Ω, 5%
2 Resistor, carbon film, 0.25W, 1.8 kΩ, 5%
6 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
1 Resistor, carbon film, 0.25W, 6.8 kΩ, 5%
4 Resistor, carbon film, 0.25W, 10 kΩ, 5%
4 Resistor, metal film, 0.6W, 1 kΩ, 1%
12 Straight pin header, female, Single row, 2.54mm
14 Straight pin header, male, Single row, 2.54mm
1 Switch, toggle, 1-pole, micro, on-on
15 Terminal block, screw, 2.5 mm
5 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B
1 Voltage regulator +5V, 2 A, L78S05CV
14 m Wire, stranded, 0.50mm2, Yellow

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: Vehicle_light_control_v2.5
' date: 01/05/2010
'--------------------------------------------------------------
$regfile = "attiny2313.dat"
$crystal = 8000000
Config Portd = Input
Config Portb = Output
Config Watchdog = 1024
Dim L_timer As Byte , B_active As Bit , B_cache As Bit
Dim Wait_timer As Integer , Start_timer As Byte , Al_timer As Byte , Al_active As Byte
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up

Const Pwm_off = 255 '255
Const Pwm_low = 235 '235
Const Pwm_high = 0 '0

'init port and i/o's
Portb = 0
Ddrb.3 = 1
Ddrb.4 = 1
Pwm1a = Pwm_off
Pwm1b = Pwm_off

'init variables
L_timer = 20
B_active = 0
Wait_timer = 0
Al_timer = Pwm1b
Start_timer = 0

B_cache = Not Pind.3 'set strobe var

Pwm1a = Pwm_high
Waitms 1000
If Pind.3 = B_cache Then 'init strobe sequence
   B_active = 1
Else
   B_active = 0
End If
Pwm1a = Pwm_off

Start Watchdog

Main:
'low beam timer
If Pind.1 = 1 And L_timer < 20 Then Incr L_timer 'low beam off
If Pind.1 = 0 Then L_timer = 0 'low beam on

'start timer
If Pind.0 = 0 And Start_timer < 120 Then Incr Start_timer 'park on
If Pind.0 = 1 Then Start_timer = 0 'park off

'high beam
If Pind.2 = 0 Then Portb.7 = 1 'high beam on
If Pind.2 = 1 Then Portb.7 = 0 'high beam off

'running lights
If Pind.3 = 0 Then 'switch off
   If L_timer = 20 And Start_timer = 120 And Pind.2 = 1 Then
      Portb.6 = 1                                           'only park active'
      Pwm1a = Pwm_high                                      'set green LED high
   End If
   If L_timer = 0 Or Pind.2 = 0 Then
      Portb.6 = 0
      Pwm1a = Pwm_off
   End If
End If

'fog lights
If Pind.3 = 1 Then 'switch on
   If Start_timer = 120 And Pind.2 = 1 Then
      Portb.6 = 1                                           'park active/high beam off
      Pwm1a = Pwm_low                                       'set green LED low
   End If
   If Pind.2 = 0 Then
      Portb.6 = 0
      Pwm1a = Pwm_off
   End If
End If

'signal
If B_active = 1 Then 'strobe active
   Portb.5 = 1                                              'set strobe output
   Pwm1b = Pwm_low                                          'set blue LED
End If

'waiting lights
If Pind.0 = 1 And L_timer < 20 Then 'if low beam was on
   Wait_timer = 3600
   Portb.6 = 1
   End If
If Wait_timer > 0 Then
   Decr Wait_timer
   If B_active = 0 Then Pwm1a = 255 - Pwm1b
   If B_active = 1 Then Pwm1a = Pwm_high
   End If
If Pind.0 = 1 And Wait_timer = 0 Then 'turn off after X sec
   Portb.6 = 0
   Pwm1a = Pwm_off
   End If
If Pind.0 = 0 And Wait_timer > 0 Then 'turn off when park on
   Wait_timer = 0
   Portb.6 = 0
   Pwm1a = Pwm_off
   End If

'alarm led
If Pind.0 = 1 And B_active = 0 Then 'if park off, strobe off
   If Al_timer = 0 Then Al_active = 1                       'count up
   If Al_timer = 255 Then Al_active = 2                     'count down
   End If
If Pind.0 = 0 And B_active = 0 Then 'off when park on, strobe off
   Pwm1b = Pwm_off
   Al_timer = Pwm1b
   Al_active = 0
   End If

If Al_active = 1 Then 'set alarm LED PWM up
   Al_timer = Al_timer + 5
   Pwm1b = Al_timer
   If Al_timer = 255 Then Al_active = 0
End If

If Al_active = 2 Then 'set alarm LED PWM down
   Al_timer = Al_timer - 5
   Pwm1b = Al_timer
   If Al_timer = 0 Then Al_active = 0
End If

Reset Watchdog 'loop cycle
Waitms 25
Goto Main
End