Mood light (RBG) with 100 mA outputs

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've later built a bigger and better mood light and controller.
Mood light in the living room

Information

Nine LEDs, three of each color (red, green and blue) is mounted in the bottom of a ice glass. The LEDs are soldered onto a PCB that lies at the bottom and point upwards, illuminating the entire glass. A AVR device controls the LEDs using PWM, this gives the option of regulating the intensity of the LEDs and fade between colors.

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. PD.0 DIP-Switch 1
  2. PD.1 DIP-Switch 2
  3. PD.2 DIP-Switch 3
  4. PD.3 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-r4d164.png

Parts list

Qty. Part
1 AVR ATmega8-16PU, DIL-28, 16 MHz, 23 I/Os
1 Capacitor, aluminium electrolytic, 10 µF, 25V
2 Capacitor, aluminium electrolytic, 47 µ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, 400 mA, fast-acting
1 Fuse holder, open, PCB, 5x20mm
3 LED 5mm clear, Blue, 4.9V, 20mA, 350mcd, 12°
3 LED 5mm clear, Green, 2.1V, 20mA, 385mcd, 6°
3 LED 5mm clear, Red, 2.0V, 20mA, 140mcd, 6°
1 Power jack, panel, 2.1mm, plastic housing
10 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%
3 Resistor, metal film, 0.6W, 1 kΩ, 1%
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 screw female
1 Terminal block, pluggable, 3.5 mm, 4-pin vertical male
3 Transistor, NPN, 100 mA, 45V, 0.5W, BC547B
1 Voltage regulator +5V, 1 A, 7805PI

Resources

Source code

Template:Basic code

'--------------------------------------------------------------
' Thomas Jensen
'--------------------------------------------------------------
' file: AVR_MOOD_LAMP
' date: 13/01/2007
'--------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 1000000
Config Watchdog = 1024
Config Portb = Output
Config Portd = Input
Dim A As Byte , R As Integer , Speed As Integer , Fade As Integer , Random As Integer
Dim Hyst1 As Byte , Hyst2 As Byte , Hyst3 As Byte

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
'0. Speed 1
'1. Fade
'2. Crossover
'3. Mode

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

Ocr2 = 0
Pwm1a = 255
Pwm1b = 255

Main:
Do

For A = 1 To 255
Decr Pwm1a
Incr Ocr2
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255
Decr Pwm1b
Incr Pwm1a
Waitms Fade
Next A

Gosub Switches

For A = 1 To 255
Decr Ocr2
Incr Pwm1b
Waitms Fade
Next A

Gosub Switches

Loop

Switches:
If Pind.0 = 0 Then Speed = 500 Else Speed = 200
If Pind.1 = 0 Then Fade = 5 Else Fade = 15
If Pind.2 = 0 Then Fade = 0
If Pind.3 = 0 Then Goto Hysterisk

Random = Rnd(speed)

For R = 1 To Random
Waitms 10
Next R

Return

Hysterisk:
Pwm1a = 255
Pwm1b = 255
Ocr2 = 255
Do
If Pind.3 = 1 Then
     Pwm1a = 255
     Pwm1b = 255
     Ocr2 = 0
     Goto Main
   End If

Hyst1 = Rnd(255)
For A = 1 To Hyst1
Decr Pwm1a
Waitms Fade
Next A

Hyst2 = Rnd(255)
For A = 1 To Hyst2
Decr Pwm1b
Waitms Fade
Next A

Hyst3 = Rnd(255)
For A = 1 To Hyst3
Decr Ocr2
Waitms Fade
Next A

'senk
For A = 1 To Hyst1
Incr Pwm1a
Waitms Fade
Next A

For A = 1 To Hyst2
Incr Pwm1b
Waitms Fade
Next A

For A = 1 To Hyst3
Incr Ocr2
Waitms Fade
Next A

Gosub Switches
Loop
End