3 different light sensors…

 

 

 

 

 

 

 

 

This week I decided to try to understand the differences between 3 different light sensors.

1 – Photoresistor or LDR (Light Dependent Resistor)

2 – Ambient Light Sensor (TEMT6000)

3 – Light Intensity to Frequency IC (TSL230R)

I combined the code from the two bildr tutorials (TEMT6000 + TSL230R), then added some code to read the LDR, and got a simultaneous serial readout of the 3 sensors.

I am still assessing the ranges of the 3 sensors, but so far the Ambient Light Sensor is very sensitive; it takes a lot of direct light to get it to max out at 1023, whereas the photo resistor maxes out around 700 under the same light (both sensors are analog in nature). What’s interesting is that both the Ambient Sensor and the LDR show similar (+ or – 30) readings in low ambient light, but diverge greatly as intensity increases.

The Intensity to Frequency IC (integrated circuit) is completely different in the type of data it produces. Because it is an digital circuit (with 3 sensitivity levels) it produces very detailed readings (by varying the PWM frequency).

At first I thought I would be able to figure out the time of day based on the intensity of the light with these sensors (ideally creating a sensor that can identify “Magic Hour”), but I need to spend more time both researching frequency and spectrum wavelength (totally forgot that colour is measured by wavelength, not frequency… hence “Magic Hour”, with all of its wonderful colours, would be difficult to identify without one of these as well: Colour Light Sensor).

http://vimeo.com/31308076

Along the way, I also thought of a use for a LDR… a bookmark, for all your pages… no more dog ears. When you open a book you’ve marked, the cell acts as a switch that signals your digital note-taking device of choice, to text you all the page and paragraph information (however you’ve formatted your notes) for each would-be dog-eared page…

The photo-sensor switch isn’t too difficult to build… but the rest… well… that’s the trick.

Light Sensors Code

// 3 Light Sensors for Readout
// Marc De Pape
//
// Creation and Computation
// OCAD University
//
// October 26 2011
//
// Based on:
//
// Part: http://www.sparkfun.com/products/8940
// Part: http://www.sparkfun.com/products/8688
// Reports the analog reading of the TEMT6000
// Article: http://bildr.org/2011/06/temt6000_arduino/
// Reports the frequency from the TSL230, higher number means brighter
// Article:  http://bildr.org/2011/08/tsl230r-arduino/ 

int TSL230_Pin = 4; //TSL230 output
int TSL230_s0 = 3; //TSL230 sensitivity setting 1
int TSL230_s1 = 2; //TSL230 sensitivity setting 2

int TSL230_samples = 5; //higher = slower but more stable and accurate

int temt6000Pin = A0; //TEMT6000 Ambient Light Sensor

int photoResistorPin = A2; //Photoresistor (LDR)

void setup(){
  Serial.begin(9600);
  setupTSL230();
}

void loop(){

  float FREQUENCY = readTSL230(TSL230_samples); //Print Frequency IC reading
  Serial.print(FREQUENCY);
  Serial.print("  frequency");
  Serial.print("t");

  float LDR = readLDR(); //Print LDR Reading
  Serial.print(LDR);
  Serial.print("  LDR");
  Serial.print("t");

  float AMBIENT = readTEMT600(); //Print Ambient Reading
  Serial.print(AMBIENT);
  Serial.print("  ambient");
  Serial.println("");

}

void setupTSL230(){
  pinMode(TSL230_s0, OUTPUT);
  pinMode(TSL230_s1, OUTPUT); 

  //configure sensitivity - Can set to
  //S1 LOW  | S0 HIGH: low
  //S1 HIGH | S0 LOW:  med
  //S1 HIGH | S0 HIGH: high

  digitalWrite(TSL230_s1, LOW);
  digitalWrite(TSL230_s0, HIGH);
}

// READ Ambient Sensor
float readTEMT600(){
  float light = analogRead(temt6000Pin);
  return light;
}

// READ Photoresistor
float readLDR(){
  float light = analogRead(photoResistorPin);
  return light;
}

// READ Frequency IC
float readTSL230(int samples){
  //sample light, return reading in frequency
  //higher number means brighter

  float start = micros();
  int readings = 0;

  while(readings < samples){
    pulseIn(TSL230_Pin, HIGH);
    readings ++;
  }

  float length = micros() - start;
  float freq = (1000000 / (length / samples)) * 10;

  return freq;
}

Comments are closed.