Vehicle light control

From uCtrl.net

(Redirected from VLC)
Jump to: navigation, search
Car with running lights
Car with high beam

VLC, driven by AVR ATTiny2313.

Contents

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

Parts list

Quantity Supplier Part number Description
1 Elfa 73-646-56 AVR-RISC, ATtiny2313-20PI
1 Elfa 50-348-63 Plastic Enclosure (1551), 35x35x15mm
1 Elfa 50-197-16 Plastic Enclosure (1591 FL), 100x50x25mm fixed install.
1 Elfa 48-161-38 DIL socket, 16-pin, 7,62mm
1 Elfa 48-161-53 DIL socket, 20-pin, 7,62mm
2 Elfa 70-003-91 Rectifier diode, 1A 400V, 1N4004
1 Elfa 75-612-36 Heatsink, 27.3 K/W, 19mm, attachable, TO220
22 Elfa 48-356-90 Terminal block, screw, 2,5 mm
1 Elfa 67-008-01 Aluminium electrolytic capacitor, 10uF 25V
2 Elfa 67-008-68 Aluminium electrolytic capacitor, 47uF 25V
1 Elfa 65-851-94 Ceramic Disc Capacitor, 1 nF 100V
1 Elfa 65-550-64 Foil capacitor, 0,01uF
1 Elfa 48-396-76 Laboratory card, 100x160mm (1/5)
10 Elfa 55-284-43 Stranded Wire, 0.50mm2, 16x0.2mm 50 V yellow
2 Elfa 55-721-69 Control cable 10-cores, 0,14mm2, 18x0,10mm 250 V, Ø 5,4mm
4 Elfa 60-722-84 Metal film resistor 1% 0,6W, 1 K
4 Elfa 60-106-15 Carbon film resistor 5% 1/4W, 10 K
4 Elfa 60-104-33 Carbon film resistor 5% 1/4W, 330 Ohm
6 Elfa 60-105-73 Carbon film resistor 5% 1/4W, 4,7 K
1 Elfa 75-350-32 Optocoupler 4-channels, PC817
12 Elfa 43-708-05 Socket connector 2,54, 1×36, female
14 Elfa 43-702-19 Straight pin header 2,54, 1×36, PCB
1 Elfa 33-167-26 Fuse 5x20 mm, 500 mA, quick-acting
1 Elfa 33-152-31 Fuse Holder, wire, 5x20 / 6,3x32mm
1 Elfa 73-095-60 Voltage regulator +5V, L78S05CV 2.0A
5 Elfa 71-027-59 Transistor BC547B, NPN, 45V 0.1A 0.625W

LED indication

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

Wire connection

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

Parts list

Quantity Supplier Part number Description
1 Elfa 48-356-90 Terminal block, screw, 2,5 mm
1 LED1.de 50099302 LED 5mm clear, RBG, 2.1 3.3 3.4V, 20mA, 25°
1 Elfa 75-056-96 LED lense 5mm, CLB 300 low, clear
4 Elfa 55-284-43 Stranded Wire, 0.50mm2, 16x0.2mm 50 V yellow
2 Elfa 55-722-35 Control cable 4-cores, 0,25mm2, 14x0,15mm 250 V, Ø 4,6mm
2 Elfa 60-105-24 Carbon film resistor 5% 1/4W, 1,8 K
1 Elfa 60-105-99 Carbon film resistor 5% 1/4W, 6,8 K
1 Elfa 60-104-74 Carbon film resistor 5% 1/4W, 680 Ohm
1 Elfa 35-305-16 Toggle switch, 1-pole, micro, on-on

Images

Schematic drawing

Vlc circuit.png

Source code

The program is written in basic, using Bascom-AVR.

'--------------------------------------------------------------
'                         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
Personal tools
Namespaces
Variants
Actions
Navigation
Categories
projects
Toolbox