Mood light (RGB) controller with 500mA outputs

From uCtrl
Mood light controller v1.1

Information

The mood light controller can control all kinds of RGB light, max 500mA pr. channel. The module has no voltage regulator and therefore needs 5V=. It has two color modes: one and multi color. One color means that one color is stable at the time, this gives three colors. Multi color has two stable color at the time, and this gives six colors (red, yellow, green, cyan, blue and purple). The module is powerful enough to run Prolight LEDs.

Modes

With four DIL-switches one can control how the light should behave:

  1. Pause between color change (long/short)
  2. Fade speed when changing color (long/short)
  3. Color change fade (on/off)
  4. Color mode (one color/multi color)

I/O

Inputs

  1. PC.2 DIP-Switch 1
  2. PC.3 DIP-Switch 2
  3. PC.4 DIP-Switch 3
  4. PC.5 DIP-Switch 4

Outputs

  1. PB.1 (OC1A) Red LED
  2. PB.2 (OC1B) Green LED
  3. PB.3 (OC2) Blue LED

LEDs

Mood-light-rgb-connector-4nmm9q.png

Images

Schematic drawing

Mood-light-controller-circuit-d4w0yg.png

Parts list

Qty. Part
1 AVR ATmega8-16PU, DIL-28, 16 MHz, 23 I/Os
1 Cable tie mount, screw, Max 5mm
1 Capacitor, aluminium electrolytic, 10 µF, 25V
1 Capacitor, aluminium electrolytic, 22 µF, 25V
1 Capacitor, ceramic, 1 nF, 100V
1 DIL socket, 28-pin, 7.62mm
1 Diode, rectifier, 1 A, 400V, 1N4004
1 Enclosure, plastic (1591), 100x50x25mm
1 Fuse 5x20 mm, 800 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
1 Fuse holder, open, PCB, Protective cover
32 cm2 PCB, stripboard, 100x160mm, 160cm2
1 Power jack, panel, 2.1mm, plastic housing
4 Resistor, carbon film, 0.25W, 330 Ω, 5%
4 Resistor, carbon film, 0.25W, 4.7 kΩ, 5%
4 Resistor, carbon film, 0.25W, 10 kΩ, 5%
4 Rubber foot, adhesive, SJ-5012, Ø 12.7x3.5 mm
1 Switch, DIP, PCB, 4-pin
1 Terminal block, pluggable, 3.5 mm, 4-pin vertical male
3 Transistor, NPN, 800 mA, 45V, 0.625W, BC337-25

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_MOOD_LAMP_v1.1
' date: 14/03/2007
'--------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 1000000
Config Watchdog = 1024
Config Portb = Output
Config Portc = Input
Dim A As Byte , R As Integer , Speed As Integer , Fade As Integer , Random As Integer

Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Up , Compare B Pwm = Clear Up
Config Timer2 = Pwm , Prescale = 1 , Compare Pwm = Clear Down

'input
'2. Stable time
'3. Fade speed
'4. Direct crossover
'5. Mode one/two color

Ddrb.1 = 1
Ddrb.2 = 1
Ddrb.3 = 1

Pwm1a = 255
Pwm1b = 255
Ocr2 = 255


For A = 1 To 255 'boot start blue LED
Decr Ocr2
If Pinc.3 = 0 Then Waitms 5 Else Waitms 15
Next A

Gosub Switches

Main:
Do

If Pinc.5 = 0 Then Goto Flerfarget

For A = 1 To 255 'increase red, decrease blue
Decr Pwm1a
Incr Ocr2
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'decrease red, increase green
Decr Pwm1b
Incr Pwm1a
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'decrease green, increase blue
Decr Ocr2
Incr Pwm1b
Waitms Fade
Next A

Gosub Switches

If Pinc.5 = 1 Then Loop
If Pinc.5 = 0 Then Goto Flerfarget

Switches:
If Pinc.2 = 0 Then Speed = 500 Else Speed = 200
If Pinc.3 = 0 Then Fade = 5 Else Fade = 15
If Pinc.4 = 0 Then Fade = 0

Random = Rnd(speed)

For R = 1 To Random
Waitms 10
Next R

Return

Flerfarget:
Pwm1a = 255
Pwm1b = 255

Ocr2 = 0 'start blue
Do
If Pinc.5 = 1 Then
     Pwm1a = 255
     Pwm1b = 255
     Ocr2 = 0
     Goto Main
   End If

For A = 1 To 255 'increase red
Decr Pwm1a
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'decrease blue
Incr Ocr2
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'increase green
Decr Pwm1b
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'decreate red
Incr Pwm1a
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'increase blue
Decr Ocr2
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255 'decrease green
Incr Pwm1b
Waitms Fade
Next A

Gosub Switches
Loop
End