Light sensor
From uCtrl.net
Contents |
Information
This module measures the light intensify and shows this on a scale from 0 to 782 on the LED display. By multiplying the shown value with 5, and then divide by 127 you get the light intensity in µW/cm2. The threshold value is shown while it's being adjusted, if the light intensity rises over/or falls below (optional) the output will be activated. The hysteresis is +-25. Only one digit is shown on the LED display at any time, but the speed is so fast that me see it as three stable digits.
LED-Display
When DP lit:
- Showing threshold value
- Output active
- EEPROM value not yet saved.
I/O
Inputs
- PC.0 Light sensor, analog value
- PC.1 Threshold up
- PC.2 Threshold down
- PC.3 Over/under threshold
Outputs
- PB.0 LED-display digit 1
- PB.1 LED-display digit 2
- PB.2 LED-display digit 3
- PB.3 Output constant
- PB.4 Output pulse
LED-Display
- PortD.0 LED-display A
- PortD.1 LED-display B
- PortD.2 LED-display C
- PortD.3 LED-display D
- PortD.4 LED-display E
- PortD.5 LED-display F
- PortD.6 LED-display G
- PortD.7 LED-display DP
D-Sub 9-pin
| Pin | Funksjon | Farge |
| 1 | 9-15V + | Yellow |
| 2 | GND | White |
| 3 | Output constant | Green |
| 4 | Output pulse | Brown |
Parts list
| Quantity | Supplier | Part number | Description |
| 1 | Elfa | 73-672-04 | AVR-RISC, ATmega8-16PI |
| 1 | Elfa | 50-197-32 | Plastic Enclosure (1591 FL), 120x65x40mm fixed install. |
| 1 | Elfa | 44-093-55 | D-Sub plastic hood, 9-pin, black |
| 1 | Elfa | 44-055-51 | D-Sub soldering cups, 9 pin male |
| 1 | Elfa | 44-055-02 | D-Sub soldering cups, 9 pin female |
| 1 | Elfa | 48-161-87 | DIL socket, 28-pin, 7,62mm |
| 1 | Elfa | 70-003-91 | Rectifier diode, 1A 400V, 1N4004 |
| 1 | Elfa | 75-508-58 | Display 3x7segment, 9,2mm Green |
| 3 | Elfa | 48-884-18 | Unthreaded round spacer, 3mm, Ø6mm |
| 1 | Elfa | 75-612-36 | Heatsink, 27.3 K/W, 19mm, attachable, TO220 |
| 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 | 48-396-76 | Laboratory card, 100x160mm (1/5) |
| 2 | Elfa | 55-722-35 | Control cable 4-cores, 0,25mm2, 14x0,15mm 250 V, Ø 4,6mm |
| 1 | Elfa | 73-221-26 | Light-to-voltage sensor, TSL 250R, 127mV / (μW/cm2) |
| 3 | Elfa | 60-106-15 | Carbon film resistor 5% 1/4W, 10 K |
| 11 | 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 |
| 22 | Elfa | 43-708-05 | Socket connector 2,54, 1×36, female |
| 22 | Elfa | 43-702-19 | Straight pin header 2,54, 1×36, PCB |
| 1 | Elfa | 33-167-18 | Fuse 5x20 mm, 400 mA, quick-acting |
| 1 | Elfa | 33-150-17 | Open fuse holder, PCB, 5x20mm |
| 1 | Elfa | 33-150-25 | Open fuse holder, PCB, Protective cover |
| 3 | Elfa | 48-858-02 | Skrew, wood, recessed, 3x12mm, + |
| 1 | Elfa | 73-095-60 | Voltage regulator +5V, L78S05CV 2.0A |
| 1 | Elfa | 55-141-12 | Cable Tie Mounts, skrew, Max 5mm |
| 5 | Elfa | 71-027-59 | Transistor BC547B, NPN, 45V 0.1A 0.625W |
| 1 | Elfa | 35-305-40 | Toggle switch, 1-pole, micro, (on)-off-(on) |
| 1 | Elfa | 35-305-16 | Toggle switch, 1-pole, micro, on-on |
Images
PCB installed |
Schematic drawing
Source code
The program is written in basic, using Bascom-AVR.
'-------------------------------------------------------------- ' Thomas Jensen '-------------------------------------------------------------- ' file: AVR_LIGHT_SENSOR_v1.0 ' date: 18/03/2007 '-------------------------------------------------------------- $regfile = "m8def.dat" $crystal = 1000000 Config Watchdog = 1024 Config Portb = Output Config Portd = Output Config Portc = Input Dim W As Word , Volt As Word , Read_timer As Integer Dim C_limit1 As Integer , C_limit2 As Integer Dim Over_limit As Bit , Limit As Integer Dim Volt_temp As String * 1 , Volt_string As String * 3 Dim Volt_number As Integer , Set_timer As Integer Dim Over_limit_set As Bit , Action_timer As Integer Dim Up_counter As Integer , Down_counter As Integer Dim Eeprom_limit As Eram Integer , Eeprom_save As Integer Dim Lowlimit As Integer , Highlimit As Integer Config Adc = Single , Prescaler = Auto , Reference = Avcc Start Adc 'get eeprom values Limit = Eeprom_limit Portd = 64 Portb.0 = 1 Portb.1 = 0 Portb.2 = 0 Waitms 500 Portb.0 = 0 Portb.1 = 1 Waitms 500 Portb.1 = 0 Portb.2 = 1 Waitms 500 Portb.2 = 0 Waitms 500 Start Watchdog 'program start Main: 'read light If Read_timer = 0 Then W = Getadc(0) Volt = W Read_timer = 666 End If 'set limit up If Pinc.1 = 1 Then C_limit1 = 0 Up_counter = 0 End If If Pinc.1 = 0 Then If C_limit1 = 0 Then Incr Limit C_limit1 = 1 Incr Up_counter Eeprom_save = 20000 Set_timer = 133 End If 'set limit down If Pinc.2 = 1 Then C_limit2 = 0 Down_counter = 0 End If If Pinc.2 = 0 Then If C_limit2 = 0 Then Decr Limit C_limit2 = 1 Incr Down_counter Eeprom_save = 20000 Set_timer = 133 End If 'correct if value out of range If Limit < 0 Then Limit = 0 If Limit > 999 Then Limit = 999 If Volt > 999 Then Volt = 999 'check limit and set conditions Lowlimit = Limit - 25 Highlimit = Limit + 25 If Pinc.3 = 0 Then If Volt > Highlimit Then Over_limit = 1 If Volt < Lowlimit Then Over_limit = 0 Else If Volt < Lowlimit Then Over_limit = 1 If Volt > Highlimit Then Over_limit = 0 End If 'show light level/threshold If Set_timer = 0 Then Volt_string = Str(volt) If Set_timer > 0 Then Volt_string = Str(limit) 'digit 1 If Len(volt_string) > 2 Then Volt_temp = Left(volt_string , 1) Else Volt_temp = "0" Volt_number = Val(volt_temp) Portd = Lookup(volt_number , Table) If Set_timer > 0 Then Portd.7 = 1 If Len(volt_string) > 3 Then Portd = 121 Portb.0 = 1 Portb.1 = 0 Portb.2 = 0 Waitms 5 Portb.0 = 0 Portb.1 = 0 Portb.2 = 0 'digit 2 If Len(volt_string) = 2 Then Volt_temp = Left(volt_string , 1) If Len(volt_string) > 2 Then Volt_temp = Mid(volt_string , 2 , 1) If Len(volt_string) < 2 Then Volt_temp = "0" Volt_number = Val(volt_temp) Portd = Lookup(volt_number , Table) If Over_limit = 1 Then Portd.7 = 1 If Len(volt_string) > 3 Then Portd = 80 Portb.0 = 0 Portb.1 = 1 Portb.2 = 0 Waitms 5 Portb.0 = 0 Portb.1 = 0 Portb.2 = 0 'digit 3 Volt_temp = Right(volt_string , 1) Volt_number = Val(volt_temp) Portd = Lookup(volt_number , Table) If Read_timer > 600 And Eeprom_save = 0 Then Portd.7 = 1 If Read_timer < 600 And Eeprom_save > 0 Then Portd.7 = 1 If Len(volt_string) > 3 Then Portd = 80 Portb.0 = 0 Portb.1 = 0 Portb.2 = 1 Waitms 5 Portb.0 = 0 Portb.1 = 0 Portb.2 = 0 'set outputs If Over_limit = 1 And Over_limit_set = 0 Then Over_limit_set = 1 Portb.3 = 1 Action_timer = 33 End If If Over_limit = 0 Then If Over_limit_set = 1 Then Action_timer = 100 Over_limit_set = 0 Portb.3 = 0 End If 'pulse output If Action_timer > 0 Then Decr Action_timer Portb.4 = 1 End If If Action_timer = 0 Then Portb.4 = 0 'timers If Set_timer > 0 Then Decr Set_timer If Read_timer > 0 Then Decr Read_timer 'fast threshold adjust If Up_counter > 66 Then Incr Limit If Down_counter > 66 Then Decr Limit 'save eeprom values If Eeprom_save > 0 Then Decr Eeprom_save If Eeprom_save = 1 Then Eeprom_limit = Limit 'loop Reset Watchdog Goto Main End '---- data for correct display of numbers on LED display ------ Table: Data 63 , 6 , 91 , 79 , 102 , 109 , 125 , 7 , 127 , 111 , 128 ' 0 1 2 3 4 5 6 7 8 9 dp

