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
Changelog
- 02: fixed a bug in lux conversion formula.
- 01: first release.
Code
Notes
- read risk disclaimer
- excuse my bad english
where should i give pin numbers in source code..?
ReplyDeleteHello. 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.
DeleteThank you soo much sir..
Deletesir ,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..?
DeleteTo 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.
DeleteHello 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.
DeleteHello, 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.
DeleteHello, I already have an working lcd code, and i have got the BH1750 Lightsensor code from you. The problem is: I have no idee how to get the data from the lightsensor on the LCD. I can't even test your BH1750 code becuase i cant see it on the lcd. So Besides the fact that the code has no errors, i dont even know if it works. Im using eclipse btw.
DeleteSorry, but im still learning so its hard to understand sometimes
Hello, let's suppose your lcd output function for a char array is lcd_puts. Then you could do something like this in your main loop: char printbuff[100]; int lux = bh1750_getlux(); itoa(lux, printbuff, 10); lcd_puts("lux: "); lcd_puts(printbuff); lcd_puts("\r\n");. But I will test the BH1750 using uart, before using an LCD, mixing two test together isn't always the best option.
Deleteoke thanks man i will try this. i cant use that library btw. It errors every time. im using http://winavr.scienceprog.com/example-avr-projects/avr-gcc-4-bit-and-8-bit-lcd-library.html right now.
ReplyDeleteHello, you can try the LCDsendChar function. Something like this, instead of the lcd_puts should work LCDstring(printbuff, strlen(printbuff));
DeleteHey David! I'm still struggling to get the light sensor working along with the LCD screen. This is what I am using: hd44780 + BH1750 sensor amega 328p.
ReplyDeleteIve got the LCD working on it's own. But can i maybe send the code to an email or something? So you can maybe see the problem with it.
Hello, I'm sorry but i can not review code, I hope you understand, if I do it for you, I must do it for all. So, can you print out an int value on the LCD?
DeleteHi David! I use Code Vision AVR to code an ATMega. So, is your code still relevant with Code Vision AVR?
ReplyDeleteHello, I've never compiled it using the code vision compiler, this project is built using avrgcc. I think you have to port it to the code vision avr compiler.
Delete