Skip to content
Stefan Armborst edited this page Jan 27, 2020 · 16 revisions

getLux

this is a blocking function that reads the brightness value from the sensor.

float getLux();

result float

The brightness as value calculated as Lux.
Depending at the settings from BH1750Quality and MTreg, you can get values between 0.11 Lux and 121.557 Lux.

On communication error, the result will be 0.
The sampling time will be 999.

See also getRaw().


Hints:

To use this function, a measurement must be started before. start()
With this function you can not initiate a measurement.

You can use this function in two ways:

  • As a blocking read to the sensor.
  • As a non blocking read after the function hasValue() returns true.

Blocking Snippet:

void loop()
{  
  BH1750.start();
  float value = BH1750.getLux();  //returns if measurement finished
}

If you call the function getLux() before the measurement was finished, the function returns after the measurement is done.

Non- blocking Snippet:

void loop()
{  
  BH1750.start();
  if (BH1750.hasValue() == true)  //returns 
  {
    float value = BH1750.getLux();
  }
}

For a non blocking read, please use the function hasValue() in conjunction with getLux().

After hasValue() is true, you can use this function several times also in conjunction with getRaw() without doing a physically read to the sensor.

If you want to know if the value was read already, you may ask for it with bool processed()

The formula to calculate Lux from the raw value:
Lux = raw value / luxFactor * Faktor * 69 / MTreg.

The factor is 1 for BH1750Quality BH1750_QUALITY_HIGH and BH1750_QUALITY_LOW and 0.5 for BH1750Quality BH1750_QUALITY_HIGH2.

In the formula above you will notice the term luxFactor.
You can adjust this value, to calibrate the sensor.
Please refer to luxFactor for more information.

With two hacks you even can extend the range to more than 700.000 Lux!

Clone this wiki locally