Our bedroom has a large window facing East that is almost always unshuttered, so that the bedroom light is constantly varying during the evening and morning hours. This gave me the notion that any clock illumination should be inversely proportional to the illumination within the bedroom.
This led to creation of the following simple unit, comprising a double row of 4 high brightness white LEDs, whose brightness is controlled by a PIC processor via the input from a photo diode.
The PIC was chosen as the control, as it contains an ADC input for sensing the photo diode, and a PWM channel for light intensity control of the LEDS. This unit satifactorally controls the clock illumination to the desired level.
The unit is simple to build and may have many other uses where a light source needs to be inversely proportional to the ambient light, for instance an illumination source for car instruments.
Remove these ads by
Signing UpStep 1: Components list
1 off power supply 15 to 18 volts AC or DC.
8 off high brightness white LEDS 5mm ( or as you wish) Led 1 - 8
1 off GP Photo diode Led 9
1 off PIC 16F684 Micro. IC1
1 Off 1 Amp bridge rectifier.
1 off 7812 12Volt regulator. IC2
1 off 78l05 5 Vlot regulator. IC3
1 off 100 uF 25 VW electrolytic capacitor.
3 off 0.01 capacitors (any small sort will suffice)
1 off 470R 1/8thw resistor R5
1 off 470K 1/8thw resistor R4
1 off 1M 1/8thw resistor R3
2 off 1R 1/8thw resistor R1-2
Wire and solder as required.






































Visit Our Store »
Go Pro Today »




this is such a great idea that I decided to make this as my first instructable at all. The clock I already bought, but I would like to illuminate the clock from each of the 12 numbers each with one LED. Is your circuid board design able to also serve 4 LEDs more (two more on each line) THX!
; Assembly code generated by mikroVirtualMachine - V. 5.0.0.3
; Date/Time: 09/02/2009 20:47:26
; Info: http://www.mikroe.com
; ADDRESS OPCODE ASM
; ----------------------------------------------
$0000 $28B0 GOTO _main
$00D5 $ _delay_22us:
;delays.pbas,17 :: sub procedure Delay_22us()
;delays.pbas,18 :: Delay_us(22)
$00D5 $3024 MOVLW 36
$00D6 $1303 BCF STATUS, RP1
$00D7 $1283 BCF STATUS, RP0
$00D8 $00FA MOVWF STACK_10
$00D9 $0BFA DECFSZ STACK_10, F
$00DA $28D9 GOTO $-1
$00DB $0000 NOP
$00DC $ delays_L_3:
$00DC $0008 RETURN
$0085 $ _mul_16x16_u:
$0085 $1303 BCF STATUS, RP1
$0086 $1283 BCF STATUS, RP0
;math.ppas,42 ::
;math.ppas,44 ::
$0087 $01FB CLRF STACK_11
;math.ppas,45 ::
$0088 $01FA CLRF STACK_10
;math.ppas,46 ::
$0089 $01F9 CLRF STACK_9
;math.ppas,47 ::
$008A $3080 MOVLW 128
;math.ppas,48 ::
$008B $00F8 MOVWF STACK_8
;math.ppas,49 ::
$008C $0CF1 RRF STACK_1, F
;math.ppas,50 ::
$008D $0CF0 RRF STACK_0, F
;math.ppas,51 ::
$008E $1C03 BTFSS STATUS, C
;math.ppas,52 ::
$008F $2899 GOTO $+10
;math.ppas,53 ::
$0090 $0874 MOVF STACK_4, W
;math.ppas,54 ::
$0091 $07F9 ADDWF STACK_9, F
;math.ppas,55 ::
$0092 $0875 MOVF STACK_5, W
;math.ppas,56 ::
$0093 $1803 BTFSC STATUS, C
;math.ppas,57 ::
$0094 $0F75 INCFSZ STACK_5, W
;math.ppas,58 ::
$0095 $07FA ADDWF STACK_10, F
;math.ppas,59 ::
$0096 $1803 BTFSC STATUS, C
;math.ppas,60 ::
$0097 $0AFB INCF STACK_11, F
;math.ppas,61 ::
$0098 $1003 BCF STATUS, C
;math.ppas,62 ::
$0099 $1FF0 BTFSS STACK_0, 7
;math.ppas,63 ::
$009A $28A1 GOTO $+7
;math.ppas,64 ::
$009B $0874 MOVF STACK_4, W
;math.ppas,65 ::
$009C $07FA ADDWF STACK_10, F
;math.ppas,66 ::
$009D $0875 MOVF STACK_5, W
;math.ppas,67 ::
$009E $1803 BTFSC STATUS, C
;math.ppas,68 ::
$009F $0F75 INCFSZ STACK_5, W
;math.ppas,69 ::
$00A0 $07FB ADDWF STACK_11, F
;math.ppas,70 ::
$00A1 $0CFB RRF STACK_11, F
;math.ppas,71 ::
$00A2 $0CFA RRF STACK_10, F
;math.ppas,72 ::
$00A3 $0CF9 RRF STACK_9, F
;math.ppas,73 ::
$00A4 $0CF8 RRF STACK_8, F
;math.ppas,74 ::
$00A5 $1C03 BTFSS STATUS, C
;math.ppas,75 ::
$00A6 $288C GOTO $-26
;math.ppas,76 ::
$00A7 $087B MOVF STACK_11, W
;math.ppas,77 ::
$00A8 $00F3 MOVWF STACK_3
;math.ppas,78 ::
$00A9 $087A MOVF STACK_10, W
;math.ppas,79 ::
$00AA $00F2 MOVWF STACK_2
;math.ppas,80 ::
$00AB $0879 MOVF STACK_9, W
;math.ppas,81 ::
$00AC $00F1 MOVWF STACK_1
;math.ppas,82 ::
$00AD $0878 MOVF STACK_8, W
;math.ppas,83 ::
$00AE $00F0 MOVWF STACK_0
;math.ppas,84 ::
$00AF $ math_L_1:
;math.ppas,85 ::
$00AF $0008 RETURN
$00DD $ _pwm_start:
;PWM_c5.ppas,26 ::
;PWM_c5.ppas,27 ::
$00DD $1303 BCF STATUS, RP1
$00DE $1683 BSF STATUS, RP0
$00DF $1287 BCF TRISC, 5
;PWM_c5.ppas,28 ::
$00E0 $1283 BCF STATUS, RP0
$00E1 $1512 BSF T2CON, 2
;PWM_c5.ppas,29 ::
$00E2 $300C MOVLW 12
$00E3 $0495 IORWF CCP1CON, 1
$00E4 $ PWM_c5_L_2:
;PWM_c5.ppas,30 ::
$00E4 $0008 RETURN
$004C $ _adc_read:
;ADClib_A_B.ppas,12 ::
;ADClib_A_B.ppas,13 ::
$004C $3040 MOVLW 64
$004D $1303 BCF STATUS, RP1
$004E $1283 BCF STATUS, RP0
$004F $059F ANDWF ADCON0, 1
;ADClib_A_B.ppas,14 ::
$0050 $30F0 MOVLW 240
$0051 $1683 BSF STATUS, RP0
$0052 $049F IORWF ADCON1, 1
;ADClib_A_B.ppas,15 ::
$0053 $1283 BCF STATUS, RP0
$0054 $179F BSF ADCON0, 7
;ADClib_A_B.ppas,16 ::
$0055 $0822 MOVF FARG_ADC_read, 0
$0056 $00F0 MOVWF STACK_0
$0057 $0DF0 RLF STACK_0, 1
$0058 $1070 BCF STACK_0, 0
$0059 $0DF0 RLF STACK_0, 1
$005A $1070 BCF STACK_0, 0
$005B $0870 MOVF STACK_0, 0
$005C $049F IORWF ADCON0, 1
;ADClib_A_B.ppas,17 ::
$005D $141F BSF ADCON0, 0
;ADClib_A_B.ppas,18 ::
$005E $20D5 CALL _delay_22us
;ADClib_A_B.ppas,19 ::
$005F $149F BSF ADCON0, 1
;ADClib_A_B.ppas,20 ::
$0060 $ ADClib_A_B_L_2:
$0060 $081F MOVF ADCON0, 0
$0061 $00F2 MOVWF STACK_2
$0062 $3000 MOVLW 0
$0063 $18F2 BTFSC STACK_2, 1
$0064 $3001 MOVLW 1
$0065 $00F2 MOVWF STACK_2
$0066 $0872 MOVF STACK_2, 0
$0067 $3A01 XORLW 1
$0068 $1D03 BTFSS STATUS, Z
$0069 $286C GOTO ADClib_A_B_L_3
;ADClib_A_B.ppas,21 ::
$006A $0000 NOP
$006B $2860 GOTO ADClib_A_B_L_2
$006C $ ADClib_A_B_L_3:
;ADClib_A_B.ppas,22 ::
$006C $081E MOVF ADRESH, 0
$006D $00F2 MOVWF STACK_2
$006E $01F3 CLRF STACK_2+1
$006F $0872 MOVF STACK_2, 0
$0070 $00F3 MOVWF STACK_2+1
$0071 $01F2 CLRF STACK_2
$0072 $0872 MOVF STACK_2, 0
$0073 $00A3 MOVWF _adc_read_local_result
$0074 $0873 MOVF STACK_2+1, 0
$0075 $00A4 MOVWF _adc_read_local_result+1
;ADClib_A_B.ppas,23 ::
$0076 $1683 BSF STATUS, RP0
$0077 $081E MOVF ADRESL, 0
$0078 $0472 IORWF STACK_2, 0
$0079 $1283 BCF STATUS, RP0
$007A $00A3 MOVWF _adc_read_local_result
$007B $0873 MOVF STACK_2+1, 0
$007C $00A4 MOVWF _adc_read_local_result+1
$007D $3000 MOVLW 0
$007E $04A4 IORWF _adc_read_local_result+1, 1
;ADClib_A_B.ppas,24 ::
$007F $101F BCF ADCON0, 0
$0080 $ ADClib_A_B_L_0:
;ADClib_A_B.ppas,25 ::
$0080 $0823 MOVF _adc_read_local_result, 0
$0081 $00F0 MOVWF STACK_0
$0082 $0824 MOVF _adc_read_local_result+1, 0
$0083 $00F1 MOVWF STACK_0+1
$0084 $0008 RETURN
$0004 $ _pwm_change_duty:
;PWM_c5.ppas,17 ::
;PWM_c5.ppas,18 ::
$0004 $1303 BCF STATUS, RP1
$0005 $1683 BSF STATUS, RP0
$0006 $0812 MOVF PR2, 0
$0007 $00F0 MOVWF STACK_0
$0008 $01F1 CLRF STACK_0+1
$0009 $0870 MOVF STACK_0, 0
$000A $3F01 ADDLW 1
$000B $00F4 MOVWF STACK_4
$000C $3000 MOVLW 0
$000D $1803 BTFSC STATUS, C
$000E $3F01 ADDLW 1
$000F $0771 ADDWF STACK_0+1, 0
$0010 $00F5 MOVWF STACK_4+1
$0011 $1283 BCF STATUS, RP0
$0012 $0822 MOVF FARG_PWM_Change_Duty, 0
$0013 $00F0 MOVWF STACK_0
$0014 $01F1 CLRF STACK_0+1
$0015 $2085 CALL _mul_16x16_u
$0016 $3006 MOVLW 6
$0017 $00F2 MOVWF STACK_2
$0018 $0870 MOVF STACK_0, 0
$0019 $00F8 MOVWF STACK_8
$001A $0871 MOVF STACK_0+1, 0
$001B $00F9 MOVWF STACK_8+1
$001C $0872 MOVF STACK_2, 0
$001D $ L_PWM_Change_Duty_0:
$001D $1903 BTFSC STATUS, Z
$001E $2824 GOTO L_PWM_Change_Duty_1
$001F $0CF9 RRF STACK_8+1, 1
$0020 $0CF8 RRF STACK_8, 1
$0021 $13F9 BCF STACK_8+1, 7
$0022 $3FFF ADDLW 255
$0023 $281D GOTO L_PWM_Change_Duty_0
$0024 $ L_PWM_Change_Duty_1:
;PWM_c5.ppas,19 ::
$0024 $0878 MOVF STACK_8, 0
$0025 $00F0 MOVWF STACK_0
$0026 $0879 MOVF STACK_8+1, 0
$0027 $00F1 MOVWF STACK_0+1
$0028 $0DF0 RLF STACK_0, 1
$0029 $0DF1 RLF STACK_0+1, 1
$002A $1070 BCF STACK_0, 0
$002B $0DF0 RLF STACK_0, 1
$002C $0DF1 RLF STACK_0+1, 1
$002D $1070 BCF STACK_0, 0
$002E $0DF0 RLF STACK_0, 1
$002F $0DF1 RLF STACK_0+1, 1
$0030 $1070 BCF STACK_0, 0
$0031 $0DF0 RLF STACK_0, 1
$0032 $0DF1 RLF STACK_0+1, 1
$0033 $1070 BCF STACK_0, 0
$0034 $3030 MOVLW 48
$0035 $0570 ANDWF STACK_0, 0
$0036 $00F6 MOVWF STACK_6
$0037 $0871 MOVF STACK_0+1, 0
$0038 $00F7 MOVWF STACK_6+1
$0039 $3000 MOVLW 0
$003A $05F7 ANDWF STACK_6+1, 1
;PWM_c5.ppas,20 ::
$003B $0878 MOVF STACK_8, 0
$003C $00F0 MOVWF STACK_0
$003D $0879 MOVF STACK_8+1, 0
$003E $00F1 MOVWF STACK_0+1
$003F $0CF1 RRF STACK_0+1, 1
$0040 $0CF0 RRF STACK_0, 1
$0041 $13F1 BCF STACK_0+1, 7
$0042 $0CF1 RRF STACK_0+1, 1
$0043 $0CF0 RRF STACK_0, 1
$0044 $13F1 BCF STACK_0+1, 7
$0045 $0870 MOVF STACK_0, 0
$0046 $0093 MOVWF CCPR1L
;PWM_c5.ppas,21 ::
$0047 $300F MOVLW 15
$0048 $0595 ANDWF CCP1CON, 1
;PWM_c5.ppas,22 ::
$0049 $0876 MOVF STACK_6, 0
$004A $0495 IORWF CCP1CON, 1
$004B $ PWM_c5_L_1:
;PWM_c5.ppas,23 ::
$004B $0008 RETURN
$00E5 $ _pwm_init:
;PWM_c5.ppas,8 ::
;PWM_c5.ppas,9 ::
$00E5 $1303 BCF STATUS, RP1
$00E6 $1283 BCF STATUS, RP0
$00E7 $0193 CLRF CCPR1L, 1
;PWM_c5.ppas,10 ::
$00E8 $1215 BCF CCP1CON, 4
;PWM_c5.ppas,11 ::
$00E9 $1295 BCF CCP1CON, 5
$00EA $ PWM_c5_L_0:
;PWM_c5.ppas,12 ::
$00EA $0008 RETURN
$00B0 $ _main:
;ledlightcontrol for clock.pbas,6 :: main:
$00B0 $ _main_main:
;ledlightcontrol for clock.pbas,9 :: porta =%00000001 rem porta 0 is adc input
$00B0 $3001 MOVLW 1
$00B1 $1303 BCF STATUS, RP1
$00B2 $1283 BCF STATUS, RP0
$00B3 $0085 MOVWF PORTA
;ledlightcontrol for clock.pbas,10 :: cmcon0=%00000111 rem disable comparitors
$00B4 $3007 MOVLW 7
$00B5 $0099 MOVWF CMCON0
;ledlightcontrol for clock.pbas,11 :: PORTC = $00 ' Initialize PORTC digital outputs
$00B6 $0187 CLRF PORTC, 1
;ledlightcontrol for clock.pbas,12 :: Pwm_Init(5000) ' Initialize PWM module, freq = 1.5kHz.
$00B7 $1012 BCF T2CON, T2CKPS0
$00B8 $1092 BCF T2CON, T2CKPS1
$00B9 $1412 BSF T2CON, T2CKPS0
$00BA $30F9 MOVLW 249
$00BB $1683 BSF STATUS, RP0
$00BC $0092 MOVWF PR2
$00BD $20E5 CALL _pwm_init
;ledlightcontrol for clock.pbas,13 :: Pwm_Start ' Start PWM
$00BE $20DD CALL _pwm_start
;ledlightcontrol for clock.pbas,15 :: while true
$00BF $ ledlightcontrol for clock_L_2:
;ledlightcontrol for clock.pbas,16 :: j = adc_read(0)
$00BF $01A2 CLRF FARG_ADC_read, 1
$00C0 $204C CALL _adc_read
$00C1 $0870 MOVF STACK_0, 0
$00C2 $00A0 MOVWF _j
$00C3 $0871 MOVF STACK_0+1, 0
$00C4 $00A1 MOVWF _j+1
;ledlightcontrol for clock.pbas,17 :: if j>255 then j=255
$00C5 $0871 MOVF STACK_0+1, 0
$00C6 $3C00 SUBLW 0
$00C7 $1D03 BTFSS STATUS, Z
$00C8 $28CB GOTO L_main_0
$00C9 $0870 MOVF STACK_0, 0
$00CA $3CFF SUBLW 255
$00CB $ L_main_0:
$00CB $1803 BTFSC STATUS, C
$00CC $28D0 GOTO ledlightcontrol for clock_L_7
$00CD $ ledlightcontrol for clock_L_6:
$00CD $30FF MOVLW 255
$00CE $00A0 MOVWF _j
$00CF $01A1 CLRF _j+1
$00D0 $ ledlightcontrol for clock_L_7:
;ledlightcontrol for clock.pbas,18 :: end if
$00D0 $ ledlightcontrol for clock_L_8:
;ledlightcontrol for clock.pbas,22 :: Pwm_Change_Duty(j) ' Change duty ratio
$00D0 $0820 MOVF _j, 0
$00D1 $00A2 MOVWF FARG_PWM_Change_Duty
$00D2 $2004 CALL _pwm_change_duty
$00D3 $28BF GOTO ledlightcontrol for clock_L_2
;ledlightcontrol for clock.pbas,24 :: wend
$00D4 $28D4 GOTO $