TS1230a internal schematic
Internal Schematic

Arduino Interfacing TSL230R Light Frequency Converter

The purpose of this page is to demonstrate the operation of the TSL239R light to frequency converter. The device outputs a 50% duty square wave whose frequency is proportional to light intensity. Not only can the TSL230R be used for detecting light intensity to adjust say lighting levels, it's sensitive enough to be a motion detector by measuring small changes in light level due to the motion of an object.

The program below is very basic in measuring the positive on time of the square wave and calculating the frequency, acting as a crude frequency counter. The same basic setup can be used with any number micro-controllers.

Download spec sheet (PDF)

Sensitivity

The TSL230R provides three levels of sensitivity (in addition to an off state) to accommodate the measurement of nearly any light intensity.

This is accomplished by dividing the photodiode array into sections which can be enabled or disabled to provide the needed sensitivity. The sensitivity is set by setting the appropriate levels on control pins S0 and S1.


S1    S0    Sensitivity
0     0     off
0     1     x 1
1     0     x 10
1     1     x 100

Output Frequency Scaling

The raw output frequency can vary from approximately 1 Hz to over 1 Mhz. Since the top frequency output is so high that some micro-controllers, such as the BASIC Stamp, are unable to measure the frequency, two pins (S2 and S3) on the TSL230R are provided as a frequency divider setting making it possible to measure the output frequency with slower micro-controllers.


S3   S2   Divide output by
0     0   1
0     1   2
1     0  10
1     1  100
Arduino connected to TS1230
Basic Schematic

Pin out on TSL230R:
1 S0 Sensitivity select input
2 S1 Sensitivity select input
3 OE Output Enable
4 GND Ground 0 V
5 VCC/VDD +3 to +5 VDC supply voltage
6 Scaled-frequency output
7 S2 Scaling select input
8 S3 Scaling select input




/* Program 1 
Make sure these libraries 
are present. This uses an
I2C LCD display.
*/

#include <OneWire.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); 
// set the LCD address to 0x27

#define S0 11
#define S1 12
#define S2 5
#define S3 6
#define pulsePin 4

unsigned long pulseCount;
unsigned int val;

void setup() {
  lcd.init(); // initialize the lcd
  lcd.backlight();
  //  Serial.begin(9600);
  pinMode(S0, OUTPUT); // to S0
  pinMode(S1, OUTPUT); // to S1
  pinMode(pulsePin, INPUT);  // freq input 
  pinMode(S2, OUTPUT);  // to S2
  pinMode(S3, OUTPUT);  // to S3 

  /* set sensitivity 
   S1    S0    sensitivity
   L     L     power down
   L     H     1X
   H     L     10X
   H     H     100X    
   Higher sensitivity creates 
   higher frequency out.
   */
   
  digitalWrite(S1, 1);
  digitalWrite(S0, 1);

  /* Frequency divide
   S3     S2          (divide-by)   
   L      L              1             
   L      H              2
   H      L              10
   H      H              100    */
   
  digitalWrite(S3, 1);
  digitalWrite(S2, 1);
} // end setup

void loop() {

  pulseCount = pulseIn(pulsePin, HIGH);
  val = pulseCount * 2; // get the period
  // play with 900000 for better accuracy
  val = 900000 / val;

  lcd.print("Freq = ");
  lcd.print(val);
  lcd.println(" Hz       ");
  delay(500);
  //  lcd.clear();
  lcd.home();
} // end loop

You Tube Arduino Microcontroller Video Series March 2012: