Hello everyone!
I'm newish to coding and electronics in general, and I'm having some trouble using a light to frequency sensor.
The TSL237-LF.
I've scoured the internet for code examples and found a couple, but they do not seem to give me good readings.
Does anyone have experience with this sensor, and could you please help. I out of my depth on this one.
Thank you.
So what is your circuit layout and what code are you using that does not seem to give you good readings?
I read that,
Power-supply lines must be decoupled by
a 0.01μF to 0.1μF capacitor with short leads placed close to the
TSL237 (Figure 17). A low-noise power supply is required to
minimize jitter on output pulse.
Have you met those requirements?
I also read that the Arduino is not all that great at reading frequencies. I am assuming you are using an Arduino?
Hey, thanks for fielding my question.
I do have a 0.1μF capacitor in the circuit. the leads are about 6" though.
I am using an Arduino Uno, and it is powering the sensor.
Since I last posted; I used a different sensor, and have gotten much better results. I may have damaged the first one when I soldered the leads onto it. 😬 I am new at this and expect to make mistakes.
the code I am using is:
int TSL237 = 2;
#define READ_TM 1000
int GreenLED = 8;
volatile unsigned long pulse_cnt = 0;
unsigned long cur_tm = millis();
unsigned long pre_tm = cur_tm;
unsigned int tm_diff = 0;
void setup() {
// attach interrupt to pin2, send output pin of TSL230R to arduino 2
// call handler on each rising pulse
attachInterrupt(0, add_pulse, RISING);
pinMode(TSL237, INPUT);
pinMode(GreenLED, OUTPUT);
digitalWrite(GreenLED, HIGH);
Serial.begin(9600);
}
void add_pulse(){
pulse_cnt++;
return;
}
unsigned long get_tsl_freq() {
// copy pulse counter and multiply.
// the multiplication is necessary for the current
// frequency scaling level. Please see the
// OUTPUT SCALING section below for more info
unsigned long freq = pulse_cnt;
Serial.println(freq);
// re-set pulse counter
pulse_cnt = 0;
return(freq);
}
void loop() {
pre_tm = cur_tm;
cur_tm = millis();
if( cur_tm > pre_tm ) {
tm_diff += cur_tm - pre_tm;
}
else if( cur_tm < pre_tm ) {
// handle overflow and rollover (Arduino 011)
tm_diff += ( cur_tm + ( 34359737 - pre_tm ));
}
if( tm_diff >= READ_TM ) {
// re-set the ms counter
tm_diff = 0;
unsigned long frequency = get_tsl_freq();
}
}
Here are a couple of pictures of the circuit. I am using a green LED with a 220kohm resistor for low light, as I don't want high frequencies, because I read that it overloads the Arduino.
https://drive.google.com/file/d/1Q8Kf5fsZpxvhZQg2YJRUy6m9_Ms6v9dL/view?usp=sharing
https://drive.google.com/file/d/1Q25u7HvRWjuyybh3GuHXdKn_qfc6S0W5/view?usp=sharing
What other controllers would you suggest? Or maybe another sensor would work better for what I am trying to do. You can see my other post on measuring translucence to see what I'm trying to do.
Thanks again for the help.