Simple Light Meter

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:

Simple Light Meter

Post by JohnCrow »

Simple Light Meter

Introduction

The standard CDS type photocell has the advantage of being very cheap to buy and can be used as one leg of a potential divider and read by the ADC input of a microcontroller.
The disadvantage of them is no two devices are exactly alike and even from the same batch can vary by a few ohms at any given illumination. They also do not have a linear output.
This makes calibration quite difficult.

This project uses a GA1A12S202 sensor, mounted on a breakout board.
The board has a 68k-ohm resistor mounted between output and ground. This converts the output to a voltage.
The board is supplied by Adafruit.

Required Parts.

This project has been developed using an AVR Mega 324P device.
The reasons for not using a PIC will be explained later.

EB019 Atmel Programmer & AVRISP
EB016 Prototype Board

Atmel AVR Mega 324P Microcontroller
4x20 LCD Display
Patch Jumpers
3.3V Voltage Regulator IC

Connections

The sensor BOB has only 3 connections

5V / Ground / Out

Power is connected to 5V and Ground on the programmer board.
(These are actually taken from the SIL header on the Protoboard.)
Out is connected to Port A0 on the programmer.

The output range of the sensor is 0V to 3V so to get maximum resolution the ADC resolution is set to match.
This means using a 3.3 V reference voltage.

The 3 pin voltage regulator is used to provided a suitable voltage. This is connected to pin 18 on the DIL header on the right hand side of the 40pin socket on the programmer.

Program Description.

The output of the sensor is read as in Integer on ADC0
This is then converted to a Float (This is to give better accuracy)
The light level in Lux is calculated as follows

Lux = Antilog( (ADC Value * 5) / 1024)

Note Flowcode calculates antilog using the power function.

Pow(10,X)

This function gave problems when using a PIC.
It would give a correct value when x was a whole number, but if the value was anything else the output was wrong.


The output was also converted to Foot Candles, to allow the readings to be compared to a Sekonic Studio Deluxe Lightmeter.

This is done by multiplying Lux by 0.09290

A simple check for under and over range is also included.

The device covers 3 Lux to 55 000 Lux. (Specified Values)
Though it will display over 98 000 Lux this cannot be taken as accurate.
Maybe a divide by 10 resistor network could be added to the project and higher readings could be taken.

This equates to an ADC reading of 97 to 970

The calculated values are converted to strings for display on the LCD.
They are shown with a resolution of 2dp.
This is accomplished by the following C Code inserted at the start of the program.

#ifdef FCV_PRECISION
#undef FCV_PRECISION
#endif
#define FCV_PRECISION 2

It should be noted C Code does not simulate.
Light Meter V1.fcfx
(11.54 KiB) Downloaded 529 times
Project1a.jpg
Project1a.jpg (43.2 KiB) Viewed 5084 times
Sensor.jpg
Sensor.jpg (36.95 KiB) Viewed 5084 times
1 in 10 people understand binary, the other one doesn't !

Post Reply