ad space

TSL235R Light-to-Frequency Converter: Understanding Its Function and Applications

In many industrial and scientific applications, it is essential to measure light intensity accurately and quickly. The TSL235R is a device that can help with this task, as it converts light intensity into an electrical frequency signal. In this blog post, we will take a closer look at the TSL235R light-to-frequency converter, what it is, how it works, and its various applications.

TSL235R light-to-frequency converter

What is the TSL235R Light-to-Frequency Converter?

The TSL235R is a small, CMOS integrated device(IC) that is designed to convert light intensity into an electrical frequency signal. It works by using a photodiode to detect light, which generates a current proportional to the light intensity. The photodiode is then connected to an oscillator that produces an electrical frequency signal. The frequency of the output signal is proportional to the intensity of the incident light.

The TSL235R IC package has 3 pins (GND, Vcc, and OUT) as shown below.The OUT pin is the square wave output which can be directly connected to a microcontroller.

TSL235R pin out

How does the TSL235R Light-to-Frequency Converter work?

The TSL235R is based on the photodiode, which is a type of semiconductor device that converts light into electrical current. When light falls on the photodiode, it generates a current proportional to the light intensity. The photodiode is then connected to an oscillator, which produces an electrical frequency signal. The frequency of the output signal is proportional to the light intensity, and it can be easily read and processed by electronic circuits.

Applications of the TSL235R Light-to-Frequency Converter

The TSL 235R light-to-frequency converter has a wide range of applications in various fields, including:

  • Light measurement: The TSL 235R is widely used in light measurement applications, as it provides an accurate and fast way to measure light intensity. It can be used to measure light in various settings, such as in a laboratory, for quality control, or for environmental monitoring.
  • Medical and biological applications: The TSL 235R is used in medical and biological applications to measure light intensity in various settings, such as in phototherapy, where it is used to measure the light intensity delivered to the patient.
  • Automation and control systems: The TSL 235R is used in automation and control systems to measure light intensity for various purposes, such as in lighting control systems, where it is used to detect changes in light intensity and adjust the brightness of the lights accordingly.

Measuring Frequency using TSL235R

The following shows circuit diagram of interfacing Arduino with TSL235R light to frequency converter IC measuring frequency with Arduino.

Arduino TSL235R interfacing circuit diagram

The OUT pin 3 of the the TSL235R is connected to Arduino pin 8.

Frequency Measurement Arduino Program

Here we provide two Arduino program that are designed to measure the frequency of the signal generated by a TSL 235R light-to-frequency converter.

Program 1

Below is the first program that uses interrupt to periodically measure the frequency.

#define lightPin 8 // Arduino pin 8 is connected to TSL235R out pin

volatile unsigned long counter=0;

void setup(){
	Serial.begin(9600);
	pinMode(lightPin, INPUT); //configure lightPin as input
}

void loop(){
	// read sensor with 100 msec integration time:
	unsigned long freq=readFreq(100);
	Serial.println(freq); // print frequency on serial monitor
}

unsigned long readFreq(int t){
	//t=100 msec: can measure up to ~140 kHz
	counter=0; // reset counter
	attachInterrupt(0, countFreq, RISING); 
	delay(t); // delay to collect data
	unsigned long Hz=counter*1000/t;
	detachInterrupt(0);
	return Hz;
}

// ISR for measuring frequency
void countFreq(){ 
   counter++; // increase counter on rising signal
}
The first line defines a constant lightPin with a value of 8, which means that the TSL 235R output pin is connected to the Arduino pin 8.

The code contains a setup function that initializes the Serial communication and sets the lightPin as an input. The loop function reads the frequency of the signal generated by the TSL 235R by calling the readFreq function, which returns the frequency in Hz, and prints it to the serial monitor.

The readFreq function takes an integer argument t, which specifies the integration time in milliseconds, and returns the frequency of the signal generated by the TSL 235R. The function resets the counter, attaches an interrupt service routine (ISR) countFreq to the rising signal on pin 2, waits for the specified integration time, calculates the frequency in Hz, detaches the ISR, and returns the frequency.

The countFreq function is an ISR that increments the counter each time it is triggered by a rising signal on pin 2. The frequency of the signal generated by the TSL 235R is calculated by dividing the counter by the integration time and multiplying it by 1000.

This code measures the frequency of the signal generated by the TSL 235R with an integration time of 100 milliseconds, and prints the frequency to the serial monitor. The frequency measurement is done by counting the number of rising signals in the specified integration time and dividing it by the integration time. The code uses the interrupt service routine (ISR) to increment the counter each time a rising signal is detected, which ensures that the frequency measurement is accurate and fast.

Program 2

Here the arduino fuction pulseIN() is used to measure the frequency. 

How does pulseIn() arduino function work?

The pulseIn() function in Arduino is used to measure the length of a pulse in microseconds. This function is useful for measuring the duration of a high or low level of an input signal.

The pulseIn() function takes two arguments: the first is the pin number, and the second is the value of the level that you want to measure. This level can be either HIGH or LOW. The function then waits for the specified level to transition from low to high (or high to low) and starts a timer. The timer stops when the opposite level is detected and the duration of the pulse is returned in microseconds.

Here is an example of using the pulseIn() function to measure the duration of a low level of an input signal on pin 2:

unsigned long pulseDuration;
pulseDuration = pulseIn(2, LOW);

In this example, pulseIn(2, LOW) waits for a low level on pin 2 and starts a timer. The timer stops when a high level is detected and the duration of the low level is returned in pulseDuration.

Note that the pulseIn() function blocks the program execution until the specified level is detected. This means that the program will wait until the level is detected, which can be problematic if the level is never detected. To avoid this, you can specify a timeout in milliseconds as the third argument to the pulseIn() function. If the specified level is not detected within the specified timeout, the function returns 0.

Following is complete code that uses the pulseIn() function for frequency measurement using the TSL235R.

#define lightPin 8 // Arduino pin 8 is connected to TSL235R out pin


void setup(){
	Serial.begin(9600);
	pinMode(lightPin, INPUT);
}
void loop(){
	unsigned long freq=readFreq(lightPin);
	Serial.println(freq); 
}

unsigned long readFreq(byte pin){
		unsigned long t=pulseIn(pin,HIGH);
		unsigned long Hz=1000000/(2*t);
		return Hz;
}

The first line defines a constant lightPin with a value of 8, which means that the TSL 235R output pin is connected to the Arduino pin 8.

The code contains a setup function that initializes the Serial communication and sets the lightPin as an input. The loop function reads the frequency of the signal generated by the TSL 235R by calling the readFreq function, which returns the frequency in Hz, and prints it to the serial monitor.

The readFreq function takes a byte argument pin, which specifies the pin number connected to the TSL 235R output, and returns the frequency of the signal generated by the TSL 235R. The function uses the pulseIn function to measure the duration of the high level of the signal on the specified pin. The frequency of the signal is then calculated by dividing 1000000 (1 second in microseconds) by 2 times the duration of the high level in microseconds.

In this code, the readFreq function is called with the lightPin argument, which is 8, to measure the frequency of the signal generated by the TSL 235R. The pulseIn function is used to measure the duration of the high level of the signal on pin 8, and the frequency is calculated by dividing 1000000 by 2 times the duration of the high level. The calculated frequency is then returned by the readFreq function and printed to the serial monitor.

This code measures the frequency of the signal generated by the TSL 235R and prints it to the serial monitor. The frequency measurement is done by using the pulseIn function to measure the duration of the high level of the signal, and then calculating the frequency by dividing 1000000 by 2 times the duration.

Conclusion

In conclusion, the TSL 235R light-to-frequency converter is a versatile and useful device that can be used in a wide range of applications to measure light intensity. Its small size, fast response time, and accurate output make it an ideal solution for light measurement applications in various fields. Whether you are working in a laboratory, in the medical field, or in automation and control systems, the TSL 235R can help you measure light intensity quickly and accurately.

To measure the frequency data from TSL235R we have provided two different programs, one that uses the interrupt feature and the other using the pulseIn() function. A more accurate reading of frequency can be obtained using the input capture feature of the Arduino microcontroller. The tutorials ATmega32 Input Capture Interrupt Example and ATmega32 Frequency Period Measurement with Input Capture illustrates how you can use the input capture to measure frequency.

Post a Comment

Previous Post Next Post