Library for ROHM BH1750FVI Ambient Light Sensor

The most advanced library for ROHM BH1750FVI. Supports all sensors functions. Compatible with Arduino AVR, Arduino ESP8266, Arduino STM32.

  • Defaul range: 1 - 65'535 lux
  • Measurement accuracy: ±20%, possible to calibrate
  • Peak wave length: 560nm, yellow-green
  • Power supply voltage: 2.4 - 3.6v

Supports all sensors features:

  • *Changing Sensitivity
  • Changing Resolution
  • Read Illuminance
  • Power Down
  • Power Up
  • Reset
  • Calibration

Tested on:

-Arduino AVR
-Arduino ESP8266
-Arduino STM32

*This option is used to compensate the influence of the optical filter. For example, when transmission rate of optical window is 50% (measurement result becomes 0.5 times lower), influence of optical window is ignored by changing sensor sensitivity from default 1.0 to 2.0 times

Download link - GitHub - enjoyneering/BH1750FVI: This is an Arduino library for the ROHM BH1750FVI Ambient Light S

The library does not give the lux value from 0.11 to 120000 by changing the resolution itself ? :wink:

To measure as low as 0.11 lux, I use a fixed delay of 662 ms. Is that the same as your code ?

No, but it dose - "Adjust measurement result for influence of optical window". Yours will show wrong light intensity with optical window like this:

I wanted to explore the extended range and it is not a library, just a Github Gist.
It is also to compare the lux values for the different modes. It turns out that a different mode can result in a different value (with the same light intensity). Therefor changing the mode might cause a glitch in the values.

Your library might be the first library that has the extended range. Since all modes are supported in your library, the range is 0.11 lux to 120k.

When I compare both of our code, many is more or less the same. Did you see my code before writing the library ?

This is not the same, selecting 5 bits:

// Your code
measurnentTimeLowBit <<= 3;
measurnentTimeLowBit >>= 3;
measurnentTimeLowBit |= BH1750_MEASUREMENT_TIME_L;

// My code
return( BH1750_MEAS_TIME_L | (mt & 0x1F)); // lowest 5 bits

I think my code is more pretty :wink:

Koepel:
It turns out that a different mode can result in a different value (with the same light intensity). Therefor changing the mode might cause a glitch in the values.

Because the datasheet says - " It is possible to detect wide range at High resolution". The key word is POSSIBLE. The ROHM company cheated with numbers. The main purpose of changing Sensitivity is adjust measurement result for influence of optical window. If you want true wide range use MAX44009 with 16-bit ADC. "An extremely wide dynamic light range that extends from 0.045 lux to 188,000 lux—more than a 4,000,000 to 1 range. The onchip autoranging scheme requires no user intervention for the gain-range setting."

When I compare both of our code, many is more or less the same. Did you see my code before writing the library

No I didn't, only the datasheet.

I think my code is more pretty :wink:

It might, but it's hard to read for me:

return( BH1750_MEAS_TIME_L | (mt & 0x1F)); // lowest 5 bits

I try to use KISS principle. Plus many things is hardcoded in your library. This is a bad habit. These kind of things is driving me nuts:

float lux_dark = (float) b / BH1750_factor * ( 69.0 / 254.0 ) / 2.0;      // BH1750_factor is usually 1.2

This is why I've started make my own libraries. But yours is defiantly 100 times better than popular library with "thousands" stars :slight_smile:

@ enjoyneering: Can I get BH1750 values on range 0.11lx - 100000lx using your library? If it’s yes, please explain how to obtain that values.

The ROHM company cheated with numbers. Technically you can, but you need to use math and have the lights with intensity close to 0.11lx & 100000lx for calibration. The datasheet says - " It is possible to detect wide range at High resolution". The key word is POSSIBLE.

For 0.11lx set "Sensitivity" to the max, put the light with intensity close to 0.11lx. Read the value from the sensor. Find an error = readValue/0.11. Now using the error you can measure light with low intensity.

For 100000lx set "Sensitivity" to the min, add dark filter between sensor and light with intensity close to 100000lx. Read the value from the sensor. Find an error = readValue/100000. Now using the error you can measure light with high intensity.

The main purpose of changing Sensitivity is to compensate the influence of the optical filter like this:

But you can use Sensitivity in a non-standard way to measure very low or very high values.

Enjoyneering