Today I received two TSL235 sensors that convert incoming light to frequency. As there was no article on the playground yet on this particular sensor I wrote a small sketch and added some comments - Arduino Playground - TSL235R - to get people started. The code does not compensate for anything yet (input voltage, temperature etc) ; maybe some future version.
In contrast to the TSL230R it has no configurable divider for the frequency so the # IRQ's can become quite high. Today's max inhouse ~160000 . Therefor I used only the rising edge for the IRQ routine. When it is really really dark one could use CHANGE edge for the IRQ, to double the precision, but be carefull as your Arduino might get stalled during daylight
robtillaart:
...In contrast to the TSL230R it has no configurable divider for the frequency so the # IRQ's can become quite high. Today's max inhouse ~160000 . Therefor I used only the rising edge for the IRQ routine. When it is really really dark one could use CHANGE edge for the IRQ, to double the precision, but be carefull as your Arduino might get stalled during daylight
As always comments and remarks are welcome,
Rob
I'm seeing this too, if the sensor sees the window the script output stops. When I shield the sensor from bright light, it starts streaming output again, with the first value read being very high.
How do I set this up to scale for brighter environments? I'm trying to design a logger that tracks how many minutes of sunlight there are at a given location over the course of a day. Any suggestions on getting this sensor to do the sensing?
For bright sunlight you should use: attachInterrupt(0, irq1, RISING); - but still it can generate too much IRQ's to handle. So if SW cannot handle HW comes in.
Dear Rob,
Thank you for the code. Works great with my Uno on digital pin 2, and on digital pin 3 with small change in code. Can you tell me how to modify it to read two TSL235 sensors?
Best, David
Is there any change i can use the code for the TSL237 - sensor?
That sensor is way more sensitive for low light, i believe it has a output frequency @ 21.8 ?W/cm2 instead of the TSL235 that has 430 ?W/cm2.
The reason i want to use this is that when i push a button i want to take a reading from the sensor, (or two-three readings and use a median value for better accuracy) and then calculate that value to Magnitude / square arc second Magnitudes/ Square Arc Second
so i dont wanna do a continous reading, just when i press a button, take a reading, display the magnitude/ square arc second on a lcd for about 10 sec. and then my arduino will continue with the rest of my code (witch is stepper motor controll with steps printout and a DHT-sensor.
Is there any change i can use the code for the TSL237 - sensor?
You need to compare the datasheets and if the only diff is the light intensity/frequency relation it should be possible.
-update-
A quick look says yes as the output signal is typically 4.5V that is enough to trigger an IRQ I think. Otherwise you can add an extra transistor to make it 5V pulses.
robtillaart:
two TSL should be something like this (not tested)
/*
FILE: TSL235R_duo.pde
AUTHOR: Rob Tillaart
DATE: 2013-02-15
PURPOSE: prototype TSL235R monitoring (double)
Digital Pin layout ARDUINO
=============================
2 IRQ 0 - to TSL235R
PIN 1 - GND
PIN 2 - VDD - 5V
PIN 3 - SIGNAL
*/
volatile unsigned long counter1= 0;
volatile unsigned long counter2= 0;
unsigned long oldcnt1 = 0;
unsigned long oldcnt2 = 0;
unsigned long t = 0;
unsigned long last;
Yes that would be possible but not for the very bright signals. Check the (PCI) PinChangeInterrupt library - Arduino Playground - PinChangeInt - and give every sensor its own counter.
As the PCI-lib is a SW lib it takes more time to handle every pulse than the HW based interrupts mentioned above so this will limit the amount of pulses per second that can be handled.
Is there a way to sample a reading, by that I mean just take ONE reading from the sensor and then stop the loop in this sketch? I'm not too familiar with the attachInterrupt concept and am a little confused as to how to get just one reading rather than loop it over and over again. I tried running it the code in the void setup() portion but that isn't working. Or can I write another function to say sample one reading? But that would require passing variables from function to function.
Is there a way to sample a reading, by that I mean just take ONE reading from the sensor and then stop the loop in this sketch? (...)
Or can I write another function to say sample one reading? But that would require passing variables from function to function.
Sorry for the lack of knowledge on my part.
Does anybody know how to implement that? At least some clues what to search for