Tuesday, January 11, 2011

Light Sensor on Arduino

The next board I'd like to write about, is the light sensor mini board. The situation is similar to the temperature board. Easy to connect, but this time there was no datasheet at all. I couldn't find out which photoresistor was used, so the value which was read had to be approximated as well. I found a good resource of the theory of calculation here.

Here is the source code to this example:
int lightSensor = 2;
int lightADCReading;
double currentLightInLux;
double lightInputVoltage;
double lightResistance;

void setup() {

void loop() {
  lightADCReading = analogRead(lightSensor);
  // Calculating the voltage of the ADC for light
  lightInputVoltage = 5.0 * ((double)lightADCReading / 1024.0);
  // Calculating the resistance of the photoresistor in the voltage divider
  lightResistance = (10.0 * 5.0) / lightInputVoltage - 10.0;
  // Calculating the intensity of light in lux       
  currentLightInLux = 255.84 * pow(lightResistance, -10/9);

  Serial.print("Light ADC reading: ");
  Serial.print("Light in lux: ");

This is the output of the program:


  1. benutzt du processing oder direkt java?

  2. Processing habe ich noch nicht benutzt. Ist für mich momentan auch nicht relevant. Für das Arduino board benutzte ich momentan die simple IDE und C. In Zukunft werden aber noch Projekte mit Java oder C# Interaktion folgen.