|
The TSL230R Light to Frequency Converter and Arduino/ATMEGA168The 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 if one has a frequency counter to measure the time it takes the micro-controller to complete a loop. In this case I calculated 5.3 microseconds. Sensitivity and output frequency scaling are user selectable. Any questions or suggestions contact me at lewis@bvunet.net Download spec sheet (PDF)
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
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 */ #define S0 11 #define S1 12 #define S2 5 #define S3 6 #define pulse_in 4 int long pulseCount; float val; void setup() { Serial.begin(9600); pinMode(S0, OUTPUT); // to S0 pinMode(S1, OUTPUT); // to S1 pinMode(pulse_in, 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, 0); /* set scaling divide by 10 any faster Arduino won't read. With Sensitivity 1X, Divide by 1 gives: Freq. out 90 Hz dark, 1.78 kHz normal, 40-50 KHz LED flashlight With sensitivity 100X and divide by 1 gives almost 1.7 MHz. 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() { // first line prevents reading an incomplete pulse pulseCount = 0; // clean out variable // with the above settings for S0-S3 the serial monotor will read around 170 Hz. // and is fairly accurate with a frequency counter. // we measure the HIGH time of the 50% duty cycle square wave while(digitalRead(pulse_in) == 0) {} // check for Lo while(digitalRead(pulse_in) == 1) { // measured delay 5.3 uSec per loop pulseCount++; } // loop while Hi val = (pulseCount * .0000053) * 2; // get the period val = 1/val; // calculate frequency Serial.print("The frequency is "); // serial output Serial.println(val); delay(200); } // end loop You Tube Arduino Microcontroller Video Series March 2012:
Arduino demos:
» About me » Bristol VA/TN » E-Mail » Hobby Electronics » Arduino Microcontroller
General Electronics
Added January 2012: PICAXE Micro-controller Projects!The PICAXE series of micro-controllers rank as the easiest and most cost effective way to use Microchip processors. I wanted an easier and less expensive way to introduce my students to the "PIC" micro-controller. Here I hope to get those starting out past poorly written literature and lack of simple working code examples.
|