Raspberry PI and BH1750 light sensor

The BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone. It is possible to detect wide range at High resolution.

 

Connection:

VCC-3v3 (pin 1)
GND-GND (pin 6)
SCL-SCL(pin 5)
SDA-SDA(pin 3)
ADD-NC or GND

 

Schematics and Layout

Again being an I2C device this is easy to connect to your Raspberry PI.

pi-and-bh1750_schem

 

 

pi-and-bh1750_bb

Code Examples

Save the following as bh1750.py and run by typing in sudo python bh1750.py

#!/usr/bin/python
import smbus
import time
 
# Define some constants from the datasheet
DEVICE     = 0x23 # Default device I2C address
POWER_DOWN = 0x00 # No active state
POWER_ON   = 0x01 # Power on
RESET      = 0x07 # Reset data register value
ONE_TIME_HIGH_RES_MODE = 0x20
 
bus = smbus.SMBus(1)  # Rev 2 Pi uses 1
 
def convertToNumber(data):
  # Simple function to convert 2 bytes of data
  # into a decimal number
  return ((data[1] + (256 * data[0])) / 1.2)
 
def readLight(addr=DEVICE):
  data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE)
  return convertToNumber(data)
 
def main():
 
  while True:
    print "Light Level : " + str(readLight()) + " lux"
    time.sleep(0.5)
 
if __name__=="__main__":
   main()

 

Links
GY-302 BH1750 BH1750FVI light intensity illumination module 3V-5V

SHARE
Previous articleRaspberry Pi and ADS1015 12 bit adc
Next articleRaspberry Pi and MLX90614 infrared thermometer