Monday, February 18, 2013

Light intensity (LUX) measure using BH1750 sensor with an AVR Atmega library

updated to version 02

This is a BH1750 light intensity sensor module with built-in a 16 bit AD converter generating digital signal. With the BH1750 Light Sensor intensity can be directly measured by the luxmeter, without needing to make calculations.
This library provides function to measure lux through I2C.
This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.

User has to setup only resolution mode.
Setup parameters in bh1750.h

  • 02: fixed a bug in lux conversion formula.
  • 01: first release.


  • read risk disclaimer
  • excuse my bad english


  1. where should i give pin numbers in source code..?

    1. Hello. This a I2C sensor, you have to connect it to the I2C pin of your micro. As example, for the ATmega8 SCL is PC5, SDA is PC4.

    2. sir ,how to display the lux reading is this code is sufficient or we have to made another code for lcd display?? and what is the range output(voltage/current) we are getting at SDA pin of sensor..?

    3. To display values on LCD, you need an LCD library. Then instead of using the uart_puts, you should use your LCD library printout function. About the SDA voltage, it's typically it's 5+. For more information about the I2C protocol, you can take a look to the I2C wikipedia page, or on the ATmega datasheet.

    4. Hello David, do you have an example code to use the LCD with the sensor? Im working on a project with a BH1750 sensor and a HD44780 LCD. Im working with a ATMEGA328p but cant get it working.

    5. Hello, unluckly I do not have an LCD sample for this, but you can use the P.Fleury LCD library, it's a pretty simple library to work with.