Library for BH1750 I2C light sensor. Supports autoranging! True to datasheet. (beware: calls are blocking at the moment)

So there is this light sensor (like the one present in any phone), BH1750. I got mine soldered to some nice breakout board.

Few facts about this library: it is very true to the datasheet. it takes advantage of MTreg (time of measurement), which lets you to increase resolution up to 3.86 times at the cost of time it takes to perform a measurement. Measurement is blocking ! I've also implemented an autoranging feature. Just like in those fancy multimeters! It works as follows, thresholds are hard-coded:

  1. <5 lx switches to Hi-res2 and to max MTreg (so measurement time is like 500ms)
  2. <1000 lx Hi-res, MTreg default.
  3. above there is no real need for Hi-res, so Low-res mode is used.

Last note: I greatly recommend you to use log10 value of the luminosity data. it makes much more sense, because it becomes linear.

Download repository: zip gz

Files at revision 0:a7280a6c3c9b

Name Size Actions
BH1750.cpp 4421 Revisions Annotate
BH1750.h 1664 Revisions Annotate