Maker Pro
Maker Pro

Light Meter Programming

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
Hello. I’m hoping I can obtain some help with programming a circuit. I’m designing an ambient light sensor with a digital display showing the amount of lux detected. I have ordered a digital display that comes with a HD44780 chip included in it. Here is the webpage for the digital display I have ordered:

https://www.sparkfun.com/commerce/product_info.php?products_id=709

Well I have never programmed before and I’m hoping I can learn a few things from the people here at this forum. I’m not sure but is it just as easy as ordering a photo sensor and getting the correct program for it to communicate with the digital screen to display the lux? If so, can someone please recommend a possible photo sensor or schematic for my application?
If someone would respond I would GREATLY appreciate the help. THANK YOU SO MUCH.
 

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
Hi Guys,

I have a question about the photocell for my application.

I talked to a customer service person from sparkfun.com and ordered the following photocell:

http://www.sparkfun.com/commerce/product_info.php?products_id=9088


http://www.sparkfun.com/commerce/product_info.php?products_id=9088


Would you agree that this is a good photocell for my design. I'm just hoping its sensitive and accurate enough. I'm making a basic light sensor that will show the amount of lux on the digital screen. I figure my light meter lux max will be either 20k,40k,50k, or 100k lux. I looked at other light meters on the market and this is what they all maxed out at.



I also ordered a microprocessor from the customer service guys recommendation. Here it is:

http://www.sparkfun.com/commerce/product_info.php?products_id=9950
 

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
Hello,

I’m hoping I can obtain some much needed help with the programming of a circuit. I have never programmed before so this is all new to me. Well I’m designing an ambient light sensor with a digital display showing the amount of lux detected. So pretty much, just a basic light meter with a digital display for the lux. Looking at other light meters on the market I believe I want the lux range to be from 0 to anywhere to 20k, 40k, 50k, or even 100k lux. The max lux range really doesn’t matter as long as it’s sufficient enough. With the help of a customer service member I have already ordered the main parts I believe I’ll need for this circuit. Those parts being a photocell, a LCD screen (HD44780 chipset), and a micro-controller(Arduino Uno). I already have a breadboard, resistors, etc. If someone would be so kind to help me out by telling me how the easiest way to start constructing and programming this circuit I would greatly appreciate it. Diagrams or similar projects with my components would be great too. Thanks again.
Here are the web pages to the parts I have ordered so far:
(Photocell)
http://www.sparkfun.com/commerce/product_info.php?products_id=9088
(LCD Screen)
https://www.sparkfun.com/commerce/product_info.php?products_id=709
(Micro-controller)
http://www.sparkfun.com/commerce/product_info.php?products_id=9950
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
Do you want Lux as in the actual unit of light intensity or would you be happy with relative intensity(some random unit which will be defined)?

I was thinking a resistance based model where ambient light would lower the resistance. Then you'd have an analog to digital converter(depending on the number of bits you want) which would be your inputs to your microcontroller.

Also, take it slowly on buying stuff, if you know nothing about programming, first get the basics right before going over-board on buying stuff...
NOTE: I'm new to micro-controllers too, but I still may be able to help you.

You have:
ATmega32
A programmer that I'm not too familiar with(but it should be the same)....
LDRs
LCD screens...

Lets get the external circuit done first though...
 
Last edited:

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
Eptheta thank you so much for responding and the help. :D

The Lux meter I'm creating I want to be like the light meters you would buy from a store. So the actual unit of light intensity I beleive is what I would want.

A resistance based model where ambient light would lower the resistance would be the simplest and best choice for my application. I definitely agree about getting the external circuit built first then I can worry about the correct programming to use to make the circuit operate how I want it to be. Thanks again and I look forward to you or whoever's next post with helping me out.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Having made an analogue light meter for fun some time ago, let me tell you a few things that you will need to be aware of...

The first thing is that the eye's response to light (similarly to the ear's response to sound) is not linear. Generally speaking, each noticeable increment in brightness represents a probably a doubling in light intensity.

Because of this, you require both the ability to measure a large range of values, as well as having very high resolution at low levels.

This can be tricky because anything that converts light to a voltage will have to be able to both detect very small changes of voltage (when the light is dim) as well as handling a much larger voltage when the light is brighter. If your light detector can be used as a current source, then you can measure the time it takes to charge a capacitor and use this as a reciprocal measure of light intensity. A more sophisticated mechanism might be to look at the rate of change of a voltage on a capacitor.

A second issue is calibration. If you're measuring in absolute units you need to calibrate the unit. There may be issues with linearity (consider capacitor leakage at low currents vs high currents) which may require some sort of compensation (possibly in software).

Consider also the stability of the circuit with temperature and supply voltage.
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
Hi,
Steve, what do you think about using an ADC(for current) then just put the LDR in series.
I think the micro-controller has one in-built that can be used.I'm not sure if the resolution will be acceptable to you though (8 bits)...
But if you manage to get a 16 bit one, then you can get 65k readings (depending on the capability of the ADC)

Also, you might get a vague sense of accuracy if you calibrate your contraption to some approximations...
I haven't checked but I'm pretty sure LED data-sheets have intensity vs voltage graphs, so you can pick several light sources, pick a voltage and then find the right point on the graph.

Also, Steve, do you have a lot of experience with micro-controllers?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The LDR isn't anywhere near linear, so you're going to have to do a lot of mucking about both in software and with a light meter (or a calibrated light source) to be able to correct for it.

Maybe you can find an equation that describes the LDR's response? I used a photodiode or a phototransistor in my circuits.

if your response is linear, 8 bits will allow you yo measure maybe 8 stops of light intensity -- that's not very much at all.

I'm not sure what an ADC output driving an LDR would be useful for, unless you have some other method of measuring the current. It *might* allow you to extend the range of measurement somewhat in some circumstances, it would have to be somewhat more complex than you describe.

The problem with LED intensity vs current is that the LED isn't an even light source, so you would have to fix both in place to ensure the alignment is fixed. Even then, you may be able to get relative readings, but not absolute ones.

I have more than 30 years experience in programming a variety of things, uC's included. However there are more different types of uC's available than I've had hot dinners...
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
I'm not sure what an ADC output driving an LDR would be useful for, unless you have some other method of measuring the current. It *might* allow you to extend the range of measurement somewhat in some circumstances, it would have to be somewhat more complex than you describe.
No, what I meant is Vcc to LDR to ADCs input. I've never personally worked with ADCs before, but I've seen my friends do it.. Correct me if I'm wrong, but don't ADCs convert an analogous current(or voltage) into an equal or to-scale digital one ?
So if I have a 5V source and a 5Ohm resistance connected to an ADCs input, I'd get 00000001 as my digital output, but if i change it to a 10V supply, then my digital output would become 00000010.
Alternatively, it can convert multiples of analogs to digital ones, so say 5mA corresponds to binary 1, 10mA corresponds to binary 2 etc...

if your response is linear, 8 bits will allow you yo measure maybe 8 stops of light intensity -- that's not very much at all.
That gets 8 bits 255 voltage/current intervals, and 16 bits, 65k.
65k seems good enough.

The problem with LED intensity vs current is that the LED isn't an even light source, so you would have to fix both in place to ensure the alignment is fixed. Even then, you may be able to get relative readings, but not absolute ones.
not a light source? what do you mean ?
Still assuming it is a 'light source': If you compare your relative readings with standard ones (on the datasheet) then you can calibrate it can't you ?
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
eptheta. Grab a calculator and get the log of the following numbers

1
255
65535

What do you notice about the relationship between the last 2?

We perceive light and sound intensity logarithmically. The difference to your eye between a reading of 1 and 255 is almost exactly the same as between 255 and 65535.

so the difference between having 8 and 16 bits of resolution is not a factor of more than 250, it is a factor of 2 (in apparent brightness range) .

A LED isn't an "EVEN light source". The light isn't uniform. And it's not that simple...
 

eptheta

Dec 20, 2009
188
Joined
Dec 20, 2009
Messages
188
Oh well, it was worth a shot. Sorry I couldn't help much heberjm8.
 

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
I have done a lot more research about programming and feel more comfortable with the terms now. I have my arduino board and my computer up and now communicating. Anyways, I was wondering if someone could send me or create a similar code for my design (light meter displaying the amount of lux on a lcd screen) that I could edit to my needs. I haven't been able to find a good code to start with yet, so I'm hoping someone can help me out with that. I appreciate your help so much. THANKS!!!
 

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
Hello,

I was hoping you could help me out. I have a question about the coding. I've attached a video and code for a light meter below. I was wondering if you could tell me for that code that someone has posted if that's all the code you need for it to work. I was talking to someone at school today about it and he wasn't sure but he was telling me about how that's not an entire code. (Even though the person who posted it said it was.) He talked about the beginning of the code and how it starts with "Serial.begin (9600) " He was telling me there is a code for that alone and I would need it along with the code that got posted. Something about a library code. I was confused with what he was saying. To me it looks like an entire code but then again I don't really know nothing about coding. Can you clear anything up for me? Thanks!!!


http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1202530375

 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You need to determine what libraries are being used. The libraries contain the routines like Serial.begin()
 

heberjm8

Oct 11, 2010
13
Joined
Oct 11, 2010
Messages
13
Steve thanks for responding.
Now how would I go about finding the libraries for a code that I found on the internet?
So that code I found, even thought it looks complete, there is still a section of code missing for the serial.begin that I would need?
Thank you so much for the help!
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
It may be that they are a part of some C compiler, or it may be that they are part of a library downloaded from somewhere.

The fact that the code doesn't have "include" statements in it is suggestive that the routines are part of the basic package.

Try googling for some of these identifiers and see what pops up.

A very quick google leads me to believe that that are part of the Arduino software.
 
Top