# Light Intensity Sensor

BH1750FVI digital light intensity module is a digital light intensity sensor integrated circuit used for two-wire serial bus interface. It uses the light intensity data collected by module to adjust the brightness of LCD and keyboard backlight. The module resolution can detect a wide range of light intensity changes.

![](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M2Xz7tKsopF1w_h1_8y%2F-M2XzRcvM0JNtt-esVf_%2Fimage.png?alt=media\&token=25561181-6e0e-45a9-9b21-e14db809ecd4)

### Objectives:

* Setup the circuit to allow the Arduino Uno to communicate with the BH1750FVI sensor.
* Setup the Arduino IDE to be able to upload the code to the Arduino IDE.
* Write the code to be able to serial print the light intensity readings.

#### Setup the Circuit:

![](https://3073865318-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ly3RLHyAwTi7Hml5lZN%2F-M2XzgzsnU3vXDHb71og%2F-M2XzqMlZdA3ZP0bbXj_%2Fimage.png?alt=media\&token=b81480b7-9cca-4ba1-8242-c5c185d1424e)

1. Connect the GND pin of the sensor to the GND pin of the Arduino Uno.
2. Connect the V pin of the sensor to the 5v PIN of the Uno.
3. Connect the SDA pin of the sensor to the analog pin (A4) of the Uno.
4. Connect the SCL pin of the sensor to the analog pin (A5) of the Uno.

#### Configuring  the Arduino IDE&#x20;

* Download the following library that will be used with [BH1750FVI](https://drive.google.com/drive/folders/1LbSfsH_kpCTDWFjwupOGzcbk27Y7zwk4)
* Open the Arduino IDE on your desktop/laptop computer and open **Sketch >  Include Library > Add .Zip Library.**&#x20;

#### The Code:

Include the following code to your Arduino IDE:

```
//
  /*
 Measurement of illuminance using the BH1750FVI sensor module
 Connection:
  Module      UNO
G <----->   GND
V  <----->  5V
SDA  <----->  A4
  SCL  <----->  A5
   */
#include <Wire.h>

#define ADDRESS_BH1750FVI 0x23    //ADDR="L" for this module
#define ONE_TIME_H_RESOLUTION_MODE 0x20
//One Time H-Resolution Mode:
//Resolution = 1 lux
//Measurement time (max.) = 180ms
//Power down after each measurement
 byte highByte = 0;
 byte lowByte = 0;
 unsigned int sensorOut = 0;
 unsigned int illuminance = 0;

 void setup()
 {
     Wire.begin();
     Serial.begin(115200);
 }

 void loop()
 {
     Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
     Wire.write(ONE_TIME_H_RESOLUTION_MODE);     //set operation mode
     Wire.endTransmission();

     delay(180);

     Wire.requestFrom(ADDRESS_BH1750FVI, 2); //ask Arduino to read back 2 bytes from the sensor
     highByte = Wire.read();  // get the high byte
     lowByte = Wire.read(); // get the low byte

     sensorOut = (highByte<<8)|lowByte;
     illuminance = sensorOut/1.2;
     Serial.print(illuminance);    Serial.println(" lux");

     delay(1000);

```
