Electronic switch with 4 channels and voltage regulator

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.

I used this module to control the LED lights in my first apartment.
Mounted in the living room

Information

A build-in voltage regulator for 5V allows a input voltage of 9 to 24V. The used is used for digital control of four channels, every channel with a dual color LED (red/green) and a push button. The LEDs show the status of the output, they lit up when a button is pushed and turns off after 10 seconds. By pushing the buttons the outputs can be toggled. The module can receive a external signal that turns off all outputs. Max load is 0.5 A (about 25 LEDs). It's possible to power anything running on 5V with this controller, like relays.

I/O

Inputs

  1. PA.0 Push button 1
  2. PA.1 Push button 2
  3. PD.0 Push button 3
  4. PD.1 Push button 4
  5. PD.2 Lights out, from Light control unit

Outputs

Status LED

  1. PB.0 LED 1 green
  2. PB.1 LED 1 red
  3. PB.2 LED 2 green
  4. PB.3 LED 2 red
  5. PB.4 LED 3 green
  6. PB.5 LED 3 red
  7. PB.6 LED 4 green
  8. PB.7 LED 4 red

LED light outputs

  1. PD.3 LED lighting 1
  2. PD.4 LED lighting 2
  3. PD.5 LED lighting 3
  4. PD.6 LED lighting 4

D-Sub 9-pin

  1. LED lighting 1
  2. LED lighting 2
  3. LED lighting 3
  4. LED lighting 4
  5. Lights out -12V, from Light control unit
  6. Lights out +12V, from Light control unit
  7. -5V out
  8. +5V out

Wires

  1. Yellow
  2. Green
  3. Blue
  4. Purple
  5. Red
  6. Brown
  7. White
  8. Black

Images

Schematic drawing

Electronic-switch-circuit-4l0504.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 D-Sub soldering cups, 9 pin female
1 DIL socket, 20-pin, 7.62mm
1 DIL socket, 6-pin, 7.62mm
1 Diode, rectifier, 1 A, 400V, 1N4004
1 Enclosure, plastic (1591 FL), 120x65x40mm, flange
1 Enclosure, plastic (1591), 112x62x31mm
1 Fuse 5x20 mm, 500 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
1 Fuse holder, open, PCB, Protective cover
1 Heat conducting film for heatsink, Adhesive, TO220
1 Heatsink, 6K/W @ 10W, 37.5mm 49g
4 LED 5mm, Red/Green, 2.0 2.1V, 10mA, 100 63mcd, 30°
4 LED holder 5mm, RTC51, black plastic
1 Optocoupler, single, CNY17F-3, DIL-6
1 Power jack, panel, 2.1mm, plastic housing
13 Resistor, carbon film, 0.25W, 330 Ω, 5%
5 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
5 Resistor, carbon film, 0.25W, 10 kΩ, 5%
1 Resistor, metal film, 0.6W, 1 kΩ, 1%
13 Straight pin header, female, Single row, 2.54mm
13 Straight pin header, male, Single row, 2.54mm
4 Switch, push-button, 1-pole, 1A, 50VAC, on-(off)
2 Terminal block, PCB, screw, 5mm 2-pin
4 Transistor, NPN, 800 mA, 45V, 0.625W, BC337-25
1 Voltage regulator +5V, 1 A, 7805PI
1 m Wire, stranded, 0.22mm2, Black
3 m Wire, stranded, 0.22mm2, Grey
1 m Wire, stranded, 0.22mm2, Red
3 m Wire, stranded, 0.22mm2, Yellow

Resources

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_LED_CONTROL_DIGITAL_4CH_v.1.0
' date: 17/02/2007
'--------------------------------------------------------------
$regfile = "attiny2313.dat"
$crystal = 8000000
Config Watchdog = 1024
Config Portb = Output
Config Porta.0 = Input
Config Porta.1 = Input
Config Portd.0 = Input
Config Portd.1 = Input
Config Portd.2 = Input
Config Portd.3 = Output
Config Portd.4 = Output
Config Portd.5 = Output
Config Portd.6 = Output

Dim A As Byte , Ledtimer As Integer
Dim Bryter1 As Bit , Bryter2 As Bit , Bryter3 As Bit , Bryter4 As Bit

Ledtimer = 100
Bryter1 = 0
Bryter2 = 0
Bryter3 = 0
Bryter4 = 0

Portb = 0
Portd.3 = 0
Portd.4 = 0
Portd.5 = 0
Portd.6 = 0

'Boot sequence
For A = 0 To 7
    Portb.a = Not Portb.a                                   'all LEDs on
    Waitms 250
Next A

For A = 0 To 7
    Portb.a = Not Portb.a                                   'all LEDs off
    Waitms 250
Next A

Waitms 1000

Start Watchdog

Main: 'start loop
'Change status
If Pina.0 = 1 And Bryter1 = 0 Then 'push button 1
   Bryter1 = 1
   Portd.3 = Not Portd.3
   Ledtimer = 100
   End If
If Pina.1 = 1 And Bryter2 = 0 Then 'push button 2
   Bryter2 = 1
   Portd.4 = Not Portd.4
   Ledtimer = 100
   End If
If Pind.0 = 1 And Bryter3 = 0 Then 'push button 3
   Bryter3 = 1
   Portd.5 = Not Portd.5
   Ledtimer = 100
   End If
If Pind.1 = 1 And Bryter4 = 0 Then 'push button 4
   Bryter4 = 1
   Portd.6 = Not Portd.6
   Ledtimer = 100
   End If

'Reset button timers
If Pina.0 = 0 Then Bryter1 = 0 'push button 1
If Pina.1 = 0 Then Bryter2 = 0 'push button 2
If Pind.0 = 0 Then Bryter3 = 0 'push button 3
If Pind.1 = 0 Then Bryter4 = 0 'push button 4

'LEDs
If Ledtimer > 0 Then
   Decr Ledtimer
   Portb.0 = Portd.3                                        'ch 1 LED green
   Portb.1 = Not Portd.3                                    'ch 1 LED red
   Portb.2 = Portd.4                                        'ch 2 LED green
   Portb.3 = Not Portd.4                                    'ch 2 LED red
   Portb.4 = Portd.5                                        'ch 3 LED green
   Portb.5 = Not Portd.5                                    'ch 3 LED red
   Portb.6 = Portd.6                                        'ch 4 LED green
   Portb.7 = Not Portd.6                                    'ch 4 LED red
   End If
If Ledtimer = 0 Then
   Portb = 0                                                'all LEDs off
   End If

'Lights out
If Pind.2 = 0 Then
   Ledtimer = 100
   Portd.3 = 0
   Portd.4 = 0
   Portd.5 = 0
   Portd.6 = 0
   End If

Reset Watchdog
Waitms 100
Goto Main 'restart loop
End