So we built our own light sensing system using Arduino microcontroller. We got the idea from iGEM 2010 Cambridge team. The sensor used was model TSL238T.
Our code. Written by Juano Venegas.
//Analog reading test. Data send to serial port.
//Sensor connections
// According to pin numbers given in TSL238T datasheet.
// Pin 1 -> Ground
// Pin 2 -> Ground
// Pin 3 -> 5 Volts.
// Pin 4 -> Pin n° 2 Arduino.
//Also, a 0.1 uF capacitor would be suitable to wire between ground and 5V. The closest possible to the sensor (it reduces noise).
// Instructions down below
// Pin definition
const int lightsensor = 2; // Light sensor port
// Variables
unsigned long pulseCount ; // Counts pulses given by sensor
void setup()
{
Serial.begin(9600);
pinMode(lightsensor, INPUT);
attachInterrupt(0, add_pulse, RISING);
}
void loop()
{
pulseCount = 0;
delay(500);
// Send value through serial port
Serial.print("i");
// Instructions:
// First, run this program. Data should be sent to Arduino's terminal. Arduino (Tools > Serial Monitor).
// If it works ok, it should give data every half second (it will show as text in the format i1234f, meaning a 1234 value).
// Check values given at absolute darkness and absolute lighting conditions. Write them down and add a bit of margin to the number and replace them in LINE B.
// Now, comment LINE A and uncomment LINE B. Run the program again.
// Now it should give values between 0 and 1023. Values are proportional to the intensity of the light source.
// Good luck!!
Serial.print(pulseCount); // LINE A
//Serial.print(map(pulseCount, here_write_absolute_darkeness_value_number , here_write_absolute_light_value_number, 0, 1203)); // LINE B
Serial.println("f");
//Serial.flush();
}
void add_pulse()
{
pulseCount++; // Increase pulse count
}