Direct Reading Light Sensor.

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Direct Reading Light Sensor.

Post by JohnCrow »

Direct Reading Light Sensor.

Introduction:

When starting to experiment with microcontrollers, one simple sensor that is often used by beginners is a Light Dependant Resistor (LDR).

These devices have the advantage of being simple to use and inexpensive.
(Cost is generally less than £1.00)

However, they do have the disadvantage of the output is linear with respect to light level, which means they are not very sensitive at low light levels, and can easily over range (Max Out) at high light levels.
However for a simple change in output level from dark to light they are perfectly adequate.

Devices with the same part no, can also have a wide variation in properties, this makes calibration and repeatability very difficult.

They are normally connected in series with another resistor to act as a voltage divider.
The second resistor can be a variable type to give some level of calibration to the system.

NOTE:
The log functions mentioned in this project are Base 10 Log and not natural logs.


A Better Solution:

Sharp produce a device (GA1A12S202) which has a logarithmic output over a wide dynamic range of 3 to 55 000 Lux.

Adafruit supply the device already mounted on a small breakout board which makes it easy to use.
These cost about £3.50, and come ready to use except for the 3 pin SIL header that has to be soldered to the board.

The board only needs 3 connections
1 VCC = 5V
2 OUT
3 GND = 0

The manufacturer supplies a simple Arduino sketch to get the board working, however this is easy to convert to other microcontrollers.
It cannot be easily used with 8-bit PICs as Flowcode does not support the Log / Antilog operations.

This project will use an AVR device , though 16-bit PIC or ARM devices could also be used.

Equipment Needed:

EB-019 AVR Programmer (Fitted with Suitable Device) & AVRisp module.
EB-005 LCD Display.
Bread board & Leads.


Programming:

The sensor is connected to ADC0 on the microcontroller. This is read as an integer variable.
It has an output of 0.3V to 3.3 V.
The ADC reference is set to 3.3V in Flowcode Properties.

The light level is calculated as follows.
Taking the ADC reading as ADC_RAW

Light Level = Antilog ( (ADC_RAW *5) / 1024)

Some simple test values are shown below for the relationship between ADC_RAW and Light Level

ADC_RAW.................Light

311........................33.00 Lux
313........................33.38 Lux
450........................157.49 Lux
725........................3467.68 Lux
Light Sensor.jpg
Light Sensor.jpg (83.89 KiB) Viewed 6156 times
Log_Light_V3.fcf_avr
(10 KiB) Downloaded 472 times
1 in 10 people understand binary, the other one doesn't !

jgu1
Posts: 1333
Joined: Tue Oct 06, 2009 9:39 am
Has thanked: 1135 times
Been thanked: 299 times
Contact:

Re: Direct Reading Light Sensor.

Post by jgu1 »

Hi John!

Again a nice tips and trick from you. Thank´s for sharing. :D

Regard

Jorgen

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Direct Reading Light Sensor.

Post by JohnCrow »

This is the ARM version, using the ECIO Device and the ECIO Base Board.

Note. ARM Devices operate at 3.3 V. Though the ECIO module has its own voltage regulator so it can still be powered from the ECIO Base Board
ECIO_ARM.jpg
ECIO_ARM.jpg (82.63 KiB) Viewed 6103 times
Log_Light_ARM_V1.fcf_arm
(10 KiB) Downloaded 414 times
1 in 10 people understand binary, the other one doesn't !

User avatar
Addisonne
Posts: 1
Joined: Wed Jul 10, 2013 10:23 am
Location: USA
Contact:

Re: Direct Reading Light Sensor.

Post by Addisonne »

You just rocking man its really amazing tip for me. its really really appreciate to you for such a very useful work. Always stay blessed.

Post Reply