# Light sensor with LED display

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.
LSU mounted in the living room.

Measures light intensity and shows the value on a LED display, if value passes over/under the set point the output is enabled. Uses the AVR ATmega8 microcontroller.

## Details

This module measures light intensity and shows it on a scale from 0 to 782 on the LED display. By multiplying that value with 5, and then divide by 127 you get the light intensity in µW/cm2. If the light intensity rises over or falls below (configurable) the set point; the output activates, with a hysteresis of +-25. The module has two outputs; a constant and a pulse. The constant output can be used to drive e.g. a relay, while the pulse can communicate with other equipment. Powered by: 9-24V.

### Set points

The set point is adjusted using the (on)-off-(on) switches, when adjusting; the display shows this instead of the real value. It is stored in ?EEPROM? making it non-volatile, meaning that it is not lost if the module is without power.

## LED-Display

In reality only one digit is shown at any given time, but by cycling through them in high speed the human eye sees three stable digits.

When DP x is lit:

1. The set value is shown, not the real value.
2. Output is active.
3. Set point has not yet been saved to EEPROM.

## I/O

### Inputs

1. PC.0 Light sensor, analog value
2. PC.1 Set point up
3. PC.2 Set point down
4. PC.3 Active when over or under set point

#### Calculations

Light intensity
${\displaystyle {\frac {ADC\cdot 5}{127}}\approx {\frac {\mu W}{cm^{2}}}\pm 0.039}$

### Outputs

1. PB.0 LED-display digit 1
2. PB.1 LED-display digit 2
3. PB.2 LED-display digit 3
4. PB.3 Output constant
5. PB.4 Output pulse

### LED-Display

1. PortD.0 LED-display A
2. PortD.1 LED-display B
3. PortD.2 LED-display C
4. PortD.3 LED-display D
5. PortD.4 LED-display E
6. PortD.5 LED-display F
7. PortD.6 LED-display G
8. PortD.7 LED-display DP

## D-Sub 9-pin

Pin Function Color
1 9-15V + Yellow
2 GND White
3 Output constant Green
4 Output pulse Brown

## Source code

Bascom-AVR source is available in a git repository:
https://github.com/thomasjsn/AVR-Light-sensor