Exploring, Software, Electronics, Photography, and Kayaking from the Gulf Coast

Arduino and the Taos TSL230R Light Sensor: Getting Started

The TSL230R light sensor IC is an interesting package: a light sensing circuit wrapped up in a clear plastic casing. This neat little device will convert irradiance (the light energy on the surface of the sensor) into frequency. Working with a simple input concept like a frequency means that we won’t have to build any extra circuitry to get the full range of information from the circuit, and having an accurate measure of radiance means that we’ll be able to convert easily over to illuminance, which is how the light looks to us. Obviously, once we can answer the question about how light looks, we can use this information to control other things. (Some great examples are: camera exposure, dimming displays, machine vision, etc.)

This guide is intended to walk you through the basics of interfacing the TSL230 series of chips from Taos with your friendly Arduino microcontroller. The specifics of the chip’s operation may not be painfully obvious the first read over the datasheet, but this guide expects you’ve at least read the important parts: which pins are which, that you can change its sensitivity, and that you can change the scale of the output.

SETUP

The only things we’ll require besides the TSL230R and an arduino is a breadboard, a 0.1uF ceramic capacitor, and some jumper wires. Wire up the pins on the TSL230R as so:

S0-S3: wire each of these to an arduino input, avoid digital in 2, as we’ll need that

OE: The output enable pin should be brought low by connecting it to GND. This pin enables or disables the output frequency. Bringing the pin HIGH will result in disabling output, so for our purposes, we’ll hard-wire it to GND, enabling output and saving an I/O line on the arduino.

Vcc: Connect Vcc to +5V from the arduino. On the hole nearest this pin on the breadboard, connect one leg of your 0.1uF capacitor, and the other to GND. The capacitor is necessary to help filter the power to prevent fluctuations in the output of the chip.

GND: connect to GND

OUT: Connect this pin to digital in 2 on the arduino. We’re going to use an interrupt, so we need to hook up to either in 2 or 3.

So, now that we’ve got everything hooked up, let’s get down to work. The TSL230 has two types of output: a pulse train, and a square wave. The pulse train is a series of high pulses that give us the exact frequency being recorded at that time. Unfortunately, as the pulse high times are in the nano-seconds, they’re gone before we can effectively measure them. The square wave output, on the other hand, has a 50% duty-cycle, meaning the high pulses and low pulses are exactly the same length – 1/2 the frequency. This allows us to register the high pulses in Arduino’s micro-second world.

Pins S2 and S3 control the output scaling, the divide-by types (2, 10, and 100) produce the square wave we want. For now, we’ll choose divide by 100, which has both S2 and S3 high.

The sensitivity controls how many receptors are active on the chip at once. When its set to higher sensitivity, the chip can register smaller and smaller amounts of light, but loses the ability to register higher levels of light. For now, we’ll stick with 1x sensitivity, meaning S0 will be high and S1 will be low.

To read the square wave, you’ve probably seen examples of using pulseIn() – this has a couple of disadvantages, the first being that you’re only measuring one cycle of the frequency (it can change often throughout a second) and the second and most glaring, being that pulseIn() requires a delay while trying to read the input pin. That means for very low light levels (1 cycle per second) you could be waiting up to an entire second for one measurement! A much better way is to take a measure of how many pulses there are per second, which will average out any fluctuations, and if we use an interrupt, we can do anything else we like while we count the pulses.

Notice that our interrupt just increases a counter, that’s all we need it to do. We’re going to check the frequency and re-set it every second in our code. Note that the interrupt is given the argument RISING, this means that it’ll only trigger when the signal changes from LOW to HIGH. We only need to count the pulses per second.

In the above code, we’ve gotten the frequency by counting the number of high pulses per second. This will work fine for our purposes, for the time being. The frequency sent to us by the chip correlates to a particular amount of radiant energy being received by it. We need to convert it to a more useful representation, and our target is a measurement of micro-watts (uW) per centimeter squared (cm2). The datasheet shows us a graph (figure 1) on page 4 that shows us that at a wavelength of 640nm, and 1x sensitivity, the relationship between uW/cm2 and the frequency is a ratio of 1:10. Or, the energy is 1/10th the frequency — uW/cm2 = Freq / 10.

An important point, saved for the last page of the datasheet, is that the actual sensor has an area of about 0.92mm2. This is about 0.0092cm2, whereas the application note found here indicates a size of 0.0136cm2 – I prefer this number. The size of the sensor is important, as we need to figure out how much energy is landing on a square centimeter of space, but we’re much smaller than that. We’ll need to multiply up the conversion to figure how much radiant energy would be landing in the square centimeter that surrounds us.

Also note that the sensor is more or less sensitive to other wavelengths than 640nm, so we’ll work straight from the graph in the datasheet figure 1, and stick with 640nm. Here’s a function to convert the frequency into uW/cm2:

Now we have a measure of not only the uW observed, but we would likely observe, were we to have a sensor that was actually 1cm2.

INCREASING SENSITIVITY

So, the room goes dark, and your frequency lingers around, erm, 2. The TSL230R has a more sensitivity than you might imagine, but you’re going to give up some of your bright-end for it. You’ll be able to go from 0.1 uW to 0.001, at maximum sensitivity. The ramification of this, is that you’re going to have to change the divide-by factor for converting frequency to energy.

If your readings are pretty low, and you’ve done everything else right, it’s time to up the sensitivity a bit.

Now we have a function, that we can call with HIGH to increase sensitivity, LOW to decrease sensitivity, and our frequency conversion to energy scales for us.

In short – the higher sensitivities allow you to differentiate very low amounts of light. Use them in darker settings, and 1x sensitivity out in bright or daylight settings.

OUTPUT SCALING

Edit: Some days you eat pie and some days you eat crow. After imploring dear readers, that you pay attention to the datasheet and which pins are which, I went and had mine all mixed up while working on the scaling portion of this tutorial. You guessed it, I was all wrong. The following text has been changed as of 11/25/08, and now stands as correct instructions.

A topic we haven’t touched on yet is the impact of output scaling. Output frequency scaling changes the way the chip reports frequency to you. Like sensitivity, frequency scaling allows you to measure different ranges of frequency. The divide by 2 method provides the lowest range of frequency, but with the most amount of resolution, divide by ten covers the mid-range of frequency with a moderate amount of
resolution, and divide by 100 covers the high range of frequency with low resolution.

Frequency scaling says that the chip will report one value representing the average value read for x periods – where x is 2, 10, or 100. Simply stated: multiply the frequency you read by the scaling level you have set. For example, in divide-by-2, you multiply your reading by two, and divide-by-100, you multiply your reading by one hundred.

Now, we can change the output scaling at whim, and since we modified the frequency function, we don’t have to change any other code.

Use a lower output scaling for moderate levels of light or to tell minute differences in levels, or use higher scaling for brighter areas, but with less ability to tell the difference between small amounts. For most photographic applications, you’ll prefer divide-by-10 or divide-by-100, to prevent constant jitter, whereas live luminance measurement applications will prefer divide-by-2.

CONVERTING TO WHAT WE SEE

You’ve probably heard the term Lux before, as in “lux meter” or, this light produces this many “lux”. Lux is, essentially, the measure of perceived brightness falling on, or coming from an amount of surface. We’ll be using a surface size of square meters, m2, in our examples. Now, note that we’re talking about “perceived”, as in perceived with our eyes. To our eyes, different wavelengths of light register as brighter or less bright. This is called photometry, what we’ve been dealing with up to this point is measuring actual energy, which is radiometry.

To go from the radiometric (actual) data to photometric (perceived) data, we’ll need to convert the energy into lumens per square meter (lux) from micro-watts per square centimeter. In the process, we’ll need to determine how bright the light appears to us. We’ll use the luminous efficiency function to do this. Now, this function is dependent on wavelength – our eyes perceive different wavelengths more or less brightly. To keep matters simple, we’ll pretend like our light source is monochromatic — that is consists of only a single wavelength. We’ll pick the same wavelength we have been using, 640nm.

To perform this conversion, we’ll need to find the luminous efficiency of 640nm. Fortunately for us, this is empirical data, so we can just look it up in the CIE table. We’ll use CIE Vm(l) from 1978, and find that 640nm has an efficiency of 0.175.

And, there you have it – you can now calculate the Lux for a single wavelength. Now, obviously most light sources we deal with produce light in many wavelengths at once, but we’ll save the more complex calculations for our next post on the subject. In the next one, we’ll cover calculating lux for multiple wavelengths, converting to Exposure Value (EV), calculating exposure time from EV/aperture/ISO, and other conversions.

Hi Phil, the TSL230 series is under license to TAOS (Texas Advanced Optical Systems) along with a number of other optical devices originally produced by TI. I would suggest not using the TI datasheets as the design reference has changed since the licensing – specifically: size of the sensor, wavelength power response curve, and reference levels for a given frequency.

You can find an accurate datasheet linked in the second paragraph of this post.

I expect that I’ll have a chance to do the next write-up early next week. I have all of the code done and tested (well, did before I wrote this one – had to verify my calculations were correct by evaluating camera exposure to what the arduino reported) – just need to find the time to write it up!

Hey, I like the article … very new to micros. I’m thinking about making this my first Arduino project. Do you know what the max lux you could record with the sensor is? I am not certain on how to obtain this info from the datasheet. Just curious how good this sensor is in that sense.

Also, do you have a good recommendation on testing the sensor once it is built? I notice that bulbs come with a lumens rating. Is an acceptable way to verify results to buy a new bulb and see if the sensor lives up to the info on the package? I am always curious how you verify that what you’ve built is giving you accurate results.

Chris – I don’t know what the maximum lux you can read out of it would be (that would be determined by the formula which you use to calculate lux) – remember that the chip only gives you light power (uw/cm2) received, that light may be more or less visible to your eyes.

The absolute maximum frequency you could get out of the chip in the divide-by-two mode is 500KHz. (The maximum frequency in pulse-train mode is 1MHz, that would be one pulse every uSec. Divide-by two has a fifty percent duty-cycle, which would make it 500KHz.) At 500KHz, in divide-by-two and 1x sensitivity, that would work out to about 735 W/m2, or 87,800 lux @ 430nm. Obviously, that’s theoretical, and much higher than you would read in the real world. I have read > 10,000 lx using the guassian formula in the second article, outside during sunlight.

As for testing the sensor – it’s kind of a chicken and egg issue. Does that light bulb _actually_ produce the amount of light it claims? For how long will it produce that amount of light? What wavelengths of light does it produce? The amount of equipment you’d have to have just to answer these questions would present an issue – and each of them would have to be calibrated themselves. I used a simple, real-world test for mine. I created an algorithm based around Pentax reflective metering. (See the photographic conversions article.) Then, I took readings from the sensor, and exposed at the indicated levels – if everything was working correctly, I would find that the majority of light would wind up in the mid-gray brightness band. (I.e. “mid-gray exposure” as metered by a camera light meter — this should result in most of the light being stacked in the middle of the histogram on a digital camera.) I found that shooting the subject at the indicated values from the algorithm produced a consistent mid-gray exposure at least 90% of the time.

Thank you for this great tutorial!
It was super helpful. I would prefer to not have to check the value every 1000ms though. So I made changes and added that code to the interrupt. That way you can just use ‘freq’ whenever you need it.

Bill – thanks for the great feedback! I’m always glad to share information when I have it. There’s nothing more frustrating than getting some great new component and then finding out you have no idea on how to use it!

Just wanted to say thanks.. I’m working on my first project as an Electrical Engineer in College – Party lights 😉 Im kind of obsessed with them now, and made a second version that has 8 channels and can be dimmed via an AVR (Triac-based Phase Control). However, dimming isn’t linear at all, and this will help me dial into the right curve that I need.

Sebf, it would require multiple sensors and/or motion to calculate the directionality of light. As the sensor is only a single sensor, it has no frame of reference to understand whether the light is stronger at its current position, or another. You can do a simple experiment to understand this: pick up the circuit with the sensor, and watch the values as you move it around – pointing it directly at, and away from the light source.

Hi – Great tutorial! I’m a student at the University of Sydney in Interaction Design and was wondering about doing something similar for a project. I’m measuring UV rays (seperate sensor) and would like to see the difference (with this type of sensor) of when a person is wearing or not wearing sunscreen. This looks like it may be the way to go. Any insight or suggestions would be great. Thanks in Advance, DG

Hi Dave, looking at the datasheet for the TSL230R, we find that it’s responsivity drops to near zero at 300nm. While you could filter out everything above 400nm, using a special filter (Wood’s Glass, maybe?), you’d be restricted to UVB and UVA measurements, and you’d have to adjust readings according to the spectral response curve from the datasheet. The combination of the filter and the reduced responsivity will greatly reduce the resolution (by 90-95% or more, hip-shot estimate) of any UV measurements made with the TSL230R.

So, with that in mind, I think a purpose-designed diode or sensor would probably work better. However, I’m not clear if you’re intending to measure the amount of UV, or another type of light – you mention having a separate sensor already for UV. Are you intending to measure how much light, of a longer wavelength, is being received?

Hi
I’m just trying to get a feel for how much light .001uW/cm2 is. I’m working on an exposure meter for a large pinhole camera. I want to measure cumulative exposure over a period of several mins to several hours to account for varying light levels that would be encountered on, for example, a partly cloudy day. Basically I just need to know if this sensor is sensitive enough. I’m not sure of the exact f-stop of the pinhole, im guessing the hole is in the neighborhood of 1-2mm and the photopaper is on a back plate anywhere from a few inches to several feet. Also, I was curious how important it would be to filter the ir or near ir light? Awesome writeup! Thanks for the help

.001 uW/cm2 is very little light. Of course, “how visible” that light is depends on the source of light (daylight, fluorescent, etc.). The f/stop of your camera will, umm, vary quite wildly given those dimensions (1mm at 1 inch would be about f/24, whereas at 1 foot would be close to f/288). Filtering near IR light won’t generally be necessary, but it can help quite a bit – I haven’t tested at exposure lengths greater than a few minutes, but it’s (it being the thing I’m about to point you to =) within 1% accuracy for a 2 minute exposure. Now, I suggest you have a look at a couple of other posts I’ve made, the first being the second tutorial in this series that covers how to calculate photographic exposure amounts, presuming you’ve gone through this tutorial. The link is here: https://roamingdrone.wordpress.com/2008/11/28/arduino-and-the-tsl230r-photographic-conversions/

For the complete device, and to suit your purposes, you’d likely have to make two changes:
1: Add a calculation for reciprocity failure for your given film type
2: Adjust the software so that it displays a remaining exposure time left. You will also want to account for the change in light, so what you’d do is figure out what percentage of the total exposure you’ve already actually taken, and what the remaining time should be given the current reading.

The sensor is perfectly suited for this task, but to make a point – the sensor should be _outside_ of the body of the camera (not measuring the light inside of the camera, it won’t provide you any benefit there, and won’t be sensitive enough), and if you make it through the second tutorial, you’ll see that you just need to know the camera’s parameters, and not so much have to have the light meter inside of the camera. You don’t need to get it perfect at first, experience will tell you how to tune your algorithm. BTW, I designed lightrails (the second link I provided) to eventually be used for digital pinhole photography, as I used to do a lot of that as well. It just lacks the running exposure re-calculation ability, which would be extremely simple to add.

Chris,
Thanks for the help and tips. I am now about 75% done with the project. I’m using a pic 16f916 (8k) but now that I’m implementing the calc_lux_gauss function, I realize I won’t have enough program space to finish. I know there isn’t any shortcut for the calculus however due to the setting this will be used in, there are two assumptions that can be made. One, only b&w paper is being exposed, which, if i understand correctly, is sensitive only to blue and yellow(?) light. And two, The camera is only used in daylight. But I suppose the spectrum of that light depends on what it is reflecting off. Not sure if this information can be used to simplify the lux calculation or not. My backup plan is moving to an arm processor as I only used the pic because of its low power consumption and the simplicity of having one power rail for the lcd, pic and sensor (which cuts my part list in half). And its breadboard friendly.

Also, I too noticed the 7.7hz/(uW/cm2) figure mentioned in the data sheet and was wondering if there is any reason for using 10 instead?

Thanks again. I look forward to showing off this project in the near future.

You can remove the elements of the arrays that are unnecessary for you, but alas, I’m afraid you cannot eliminate lists and algorithmically determine the values, as the CIE tables are empirical. You might be able to save a LOT of space, however, by avoiding floating point math altogether. It’s an old trick, but highly effective (especially since neither the PIC nor the Atmega have an FPU) by working in higher scales and then bringing your result back down at a final stage in calculation.

Please stop by and drop a link to your project when you’re done – I’d love to see it!

Hi again
I ust wanted to ask about the uw/cm2 to w/m2 calculation. Maybe I’m missing something in the code but aren’t there 10000 square cm in a square m? Changing the value from 100 to 10000 in the code seems to be producing ballpark lx values for me. For instance with these conditions, raw freq = 16000 hz, scaling set to /2 and at 100x sensitivity, I get around 80-90 lx depending on where its pointed (using a white paper to diffuse). This seems very reasonable according to http://en.wikipedia.org/wiki/Lux Im in a smaller spare bedroom home office with 2 60w lights. Maybe I’ve got a bug elsewhere but so far this is where I’ve tracked it. Without the change, I’m seeing 1 or less lx and that just doesn’t seem right to me. Its not that dark in here.

There are 100 cm in 1 m. Therefore, there are 100 sq cm in 1 sq m. This can be proven through basic reduction of redundant terms.

That is to say, if 1m == 100cm, then 1m^2 == 100cm^2. Remember that there are 1,000,000 uW in a W.

The problem is unlikely to be in your w_m2 calculation, especially if you are using the method I provided, straight (without modification). Don’t presume the problem lies in your watt calculus if you’re measuring by lux output. De-complicate the issue by first validating wattage, and then validate lux.

So, if you use the calc_uwatt_cm2() function I provide (with my 10x factor), you should get an output of ~1176.47. (Remember that you have to scale the area you actually read to the area of a sqaure cm.)

If you changed to 7.7 as the factor, then you should get ~1527.87.

Given the 1527.87 uW/cm2, you then check your conversion to W/cm2, by dividing by 1M — 0.00152787 W/cm2, then extrapolate that to the same reading over an area of m2, or 0.152787 W/m2.

The conversion to lx is probably where you’re messing up. Can you show me your modified conversion tables for the gaussian function?

Also, remember, that the spot you’re reading the reflection from may not truly be representative of the most amount of light. You have a sensor of 0.0136 cm2, and are extrapolating that out to the same reading across an area of m2. If your formulas are all right, then attempt to move the area you’re reading off and see what changes. Remember that 16kHz at 100x sensitivity and 2x scaling is kinda low. =)

Hey, I only have a minute right now but I wanted to point out that there are, in fact, 10,000 cm^2 in 1 m^2. Your conversion is correct for linear measurements as, there are 100 cm in 1 meter. However 1 square meter is broken down to 1m*1m. or 100cm*100cm. which is 1m^2 or 10000 cm^2. I must admit that I am surprised at your error here as the conversion from radiometric to photometric units requires much more complex mathematics.

Anyway, I’ll start a thread somewhere soon documenting my work so far. The comments section here probably isn’t the best place for it.

You are absolutely right. I can blame my error today on the fact that I’m responding between dealing with more complex issues with my day job here, and my error then that I was more focused on the photometric conversions =) Or maybe just that I, like many, have a tendency to think gloss over something and never come back to it!

This does draw into question how I can start with an incorrect assumption, and end up with a correct answer. In fact, that’s the 8k lb gorilla in the room. This more than likely leads me to an error further down the chain, I’m presuming its going to be in the APEX conversions, as I spent quite a bit of time on gaussian function, and can’t claim credit to it (I stole it, alas =).

I would like to thank you and Andrew for pointing out these errors, I will use them to correct this tutorial and the others in the near future.

I’ve also done the same thing many times myself, no worries. Your right tho, there has to be some error elsewhere that compensates for it. If I have time over the next few days, I’ll debug some more. Otherwise, it’ll wait till I’m back in town.

Phishingphree, hey I forgot to mention it, but since you’re working on a photo-related project, if you’re looking for somewhere to document your project work – might I suggest my site over at OpenMoco.org? It’s intended to be a repository of information related to DIY photography/timelapse/photo motion control – and we could definitely use the content. It’s to be a community-driven site, but as of yet, we haven’t gotten a lot of extra input outside of what I’ve been writing there.

There are a lot of contributors working on things, but I’d love to have your work and notes as well – I plan to get some more work on pinhole-related subjects there done as I complete some hardware prototypes for the timelapse gear I’m working with.

hi again
Ive looked things over a bit. Wanted to ask why your using the sensor size to convert the readings to uw/cm^2. Maybe I’m missing something but the impression I get from the datasheet is that the sensor reports in uw/cm^2. Meaning that the sensor already takes its size into consideration. Another thing I noticed is that the part I received from sparkfun has a sensor size much closer to .9mm2 than 1.3. I’ve modified the calc_uwatt_cm2() function to return freq*2/sensitivity. Also, I’m using .77, 7.7, and 77 as the sensitivity powers as this matches with the datasheet as well. Curious why yours are an order of magnitude larger and not 1, 10, and 100. With these changes, I’m able to get reasonable shutter speed approximation.. like 40ms vs 1/30th. still off, but probably within the 20% for this part number.

The indication that you have to extrapolate the size to get an accurate reading comes from Taos directly.

Here’s the quote from the Taos application note: “The thick middle line is the one to use here. And that line tells us that 10 kHz on the graph corresponds to around 100 mW/cm2. So the power incident on the array is (100 mW/cm2)*(.0136_cm2)=1.36 mW of power.”

Incidentally, I likely picked up the bad 10uW/Hz reading from this application note. Also incidental, .9mm is what my calipers read. (I didn’t have a good set of calipers when I wrote the tutorial, so I experimented with both values – and found 1.37mm to result in a closer reading to my pentax spot meter – in fact, it was ‘spot on’ for readings < 1 second.)

As to why the values are 10, 100, and 1000 vs 1, 10, 100. At this point, a year later – I couldn't tell ya why. I see the same thing you see in this case.

I’ve enjoyed your articles immensely and in the process of building a light meter for myself using your project as a background. Minor differences: I’m using the hardware counter to measure pulses and only dealing with the overflow interrupt. At 1x scaling, the time it takes servicing a pin change interrupt caused my program to temporarily lock up when I shined a bright light on the sensor.

Anyways, I wonder if your calc_uwatt_cm2 function might not be right. By my reading of the data sheet, the typical responsivity is 7.7 Hz/(uW/cm2), not 10. The returned value from calc_uwatt_cm2 should be about 1.3x higher.

Does this make a difference or is it all taken into account when I calibrate the meter?

Andrew, I do see the point you’re indicating. In fact, it’s been long enough now that I can’t properly recall where I got 10 from, but my poor recollection at this phase says it likely came from one of the application examples from Taos for the PIC. You’re right that it does in fact say 7.7.

You should probably choose 7.7 for the most accurate number, however, I’ve found very little deviation from other light meters, in spot mode (such as the one in my K10D) when I was calibrating. It is highly likely that floating point precision (or lack thereof) ends up modifying the difference throughout the full chain of processing.

It strikes me as interesting that it locks up for you at 1x sensitivity with a flashlight? I have been effectively using a device in the field (see my “LightRails” post) at 1x sensitivity in full sunlight (much more light than a flashlight can produce) using the same implementation here with no issues. The only time I ever had a lockup was when the wiring was incorrect.

Edit: In fact, I had 100% rate of lockup when using a flashlight, just like you mention, when the wiring was incorrect. That determination led to the edit in the post its self where I commented about the original version using the wrong pinouts and causing the code to be incorrect.

Thanks for the reply. I haven’t found time to finish building this or put a camera in the loop yet, but it’s still in the works.

The lockup problem was something stupid on my part. I originally wanted the scale and sensitivity values to be dynamic, based on the calculated frequency. i.e. if the frequency went too low, try decreasing the scaling, if scaling is at minimum, increase sensitivity and so on. The problem with code like this is that if the IC is at 100x sensitivity and 1x scaling and I shine a 3W LED into the chip from a couple centimeters away, the ISR doesn’t finish before the next pulse comes in. Add another TSL230R into the mix and it gets worse.

This was all solved by using the onboard timer/counter hardware and enabling an interrupt on overflow. Every sample period I add the counter register to the overflow count multiplied by the maximum value of that timer register. Now I can read two sensors at 1x scale in sunlight with plenty of time to do other things on the AVR.

You are reading the TAOS application note wrong. In the datasheet (graph in Figure 1) it is clearly said that the output frequency is directly converted to uW/cm^2, there’s no need for scaling with the sensor size. That’s what the 1/cm^2 means, it is already scaled to a unit area. The application note just says that you can get the incident _power_ by multiplying with the sensor size.

Now, in the code you divide with the sensors size. If you do this, the unit would be (uW/cm^2) / cm^2 = uW/cm^4, which isn’t anything relevant.

As my application only needs irradiance (uW/cm^2), I haven’t followed through what you do to get reasonable exposures with the camera, but there’s some fishy anyway, based on the incorrect starting point..

You are correct, phishingphree and I have come to that conclusion via email. Unfortunately, it was a little too difficult to try and have that full conversation in the comment area here.

There are numerous reasons as to “why it works” in the field, even when the core assumptions are wrong, but namely, two factors come into play: the lack of an FPU in the atmega chips results in the very small calculations falling within the margin of error on the CPU (it is highly unlikely that it comes anywhere near exact – in fact, this is why I didn’t model blackbody radiators in the second tutorial), and the fact that using it as a “middle-gray” light meter forces EV correction for proper exposure (like any other meter), which largely compensates for any errors. Especially as those errors are largely consistent. (See first point.)

At any rate, I’ll be updating all of the tutorials as soon as I have a chance to build another working model to test on (I’m very busy with the OpenMoco project ATM), as I don’t want to put untested code in here. For the time being, the comment area will serve as a record for these corrections.

Hi… I’ve been reading this tutorial and find it fasinating and decided to dig out an arduino/light sensor and give it a go.

I went through and started pasting the various sections of code – but it dawned on me that it seems incomplete. The subroutine calc_uwcm2 is missing… Can you include it or send it to me.. Or better yet, provide a complete program… I would really like to dig into this more and learn as much as I can… Thanks.

Excellent article. I am new to the Arduino but an “old” hand at microprocessors. I recently found the TS light sensor in a drawer and your article should make its hookup and implementation quite easy. My needs are more limited than photography – just a light detector to measure sunlight so that I can rotate a solar collector (I’ll probably make a cheap quad-cell using a slowly rotating aperture and 4 light fibers. I’ll also use the light information to have the Arduino decide whether to close some insulating panels.

Well, “…” generally indicates “some stuff here”, and you shouldn’t define the same functions twice. If you look at the code and follow the sections, you might notice I’m indicating where I’ve changed an earlier body of code. And where earlier code might reside. This is tutorial that’s supposed to walk you through building a new body of code yourself, so break each out part into its own code section, much of which requires other stuff to be present to actually work.

Hi, I’m new at this and could use some help. I’m using a Arduio Duenmilanove 328P and keep geting the error (‘add_pulse’ was not declared in this scope In function ‘void loop()’:
In function ‘float calc_lux_single(float, float)’:) when compiled. Any advice? Thank you

I read from the datasheet that the output pin of the TSL230R can be driven to abt 12 inches max. Have your application been longer than that, without using a buffer or a line driver? I am thinking of hooking the TSL230R at abt 60 inches from the microcontroller. Would that be a problem, based on your experience?

You might have issues at 60 inches. I’ve run about 24 inches distance, but not much longer. I would suggest either buffering, or using a very small arduino (like the nano or pro mini) closer to the sensor to handle communication with a remote arduino.

[…] The first stop for this kind of adventure always begins at SparkFun.com for goodies. I looked over the different kinds of light sensors, and decided on this one. It was slightly more complicated, but had better a sample on someone else’s blog. […]

The uW/cm2 value obtained in this code is at 640nm (obtained by dividing the freq by 10 and using fig 1 in the datasheet). If I wanted to find the uW/cm2 at different wavelengths e.g. uW/cm2 at 400nm only, how would I get this new value (I can’t use illuminance since I am measuring reflectivity and I need wavelengths from 350 to 1000)?

Is there another datasheet to get the direct relationship between frequency and wavelength?

Thanks for the awesome tutorial. I am following along with my arduino (currently just before converting frequency to energy) I am using Serial.println in my main loop to report the frequency each second. I have noticed that as the frequency gets up to about 70Khz the interrupt takes over, my main loop hangs and I stop getting serial data. Once the sensor is exposed to less light, I get a huge value dumped to serial and then the program continues as normal. Any insight on how I can make the interrupt less pushy? Let me know if you want me to post code.

Great tutorial! Quick question for you: I’m looking to use your code as the basis for a much simpler sensor (I hope). I have a bunch of motorized blinds on the west side of my house and am trying to build a sensor that can essentially return two values to my home automation system: “sunny” and “not sunny”. “Sunny” would equal when it’s bright enough outside such that the solar radiation pounding through the glass would overheat the house. Not-sunny would equal everything else (e.g. cloudy, night time, etc).

Am I right in that to perform this calcuation best, I would actually use the initial irradiance value and *not* an illuminance value? I’m guessing so because it’s the actual irradiance that produces the unwanted heat and not the illuminance. And if so, is the frequency sufficient for that or am I going to want to use the uw_cm2 value?

Great article; thank you so much for documenting your work in this area. Mostly interested in building a pulse oximeter at present. However, might you know of similar sensors of other than IR wavelengths to implement a colorimeter?

I’m trying to construct an pyranometer using this chip. As such I’m trying to calibrate it such as to report an equivalent of w/m^2 of full output. Has anyone else done this and have some calibration information I can use?

Also I’d like to run two of these on the Arduino Uno, how do I get started at that? Thanks,

Hey,
Great tutorial. There’s one thing I can’t figure out. Is the sensor reading the full spectrum, or just 640nm? I think I have my setup working, but my readings drop off considerably in the shade, much more than I expect. I’m wondering if it’s related to the wavelength.

[…] Before we get to far! If you are looking for a photo-ready reading from this sensor, in ISO, ASA, Lux or other, you are in the wrong place. You want this article here: Arduino and the Taos TSL230R Light Sensor: Getting Started. […]

[…] Before we get to far! If you are looking for a photo-ready reading from this sensor, in ISO, ASA, Lux or other, you are in the wrong place. You want this article here: Arduino and the Taos TSL230R Light Sensor: Getting Started. […]

hi can someone please send me the complete code to get a reading in lux because i couldnt really put the above codes together im getting errors id really appreciate it and thanks whoever uploaded this the best tutorial i ever seen, id appreciate anyone who can send me asap to waelmahlous123@hotmail.com

Your TSL230R tutorials are wonderfully detailed and helpful. However, I am having a hard time figuring out how to reassembly the code bits you have into a single sketch. Do you have a fully-defined example somewhere that I could view? It is difficult for a newbie to figure out how to combine the examples above and get it to compile correctly. Thanks! This is great work.

Is any one experienced this problem. I am using this sensor to measure the sunlight. When the sun light is very strong, the system stop working. I checked the frequency before I am using 1x sensitivity and 1x division. Is this because when the frequency is too high, the interruption function will fail arduino?

[…] Conversions By Church on November 28th, 2008 Posted in Projects | Time-lapse Video 20 In the previous post on using the Taos TSL230R with the Arduino, I covered the basic operations of the chip, and some […]