BH1750 (GY-302), measure the lighting quality of your home (Arduino / ESP8266 / ESP32)

The GY-302 from CJMCU is an I2C board that allows you to measure the amount of light using the BH1750 photodetector. We will use the measured brightness to construct an ambient lighting quality indicator based on European Standard EN 12464-1. It is very easy to integrate the sensor GY-302 in an Arduino project or ESP8266 using the library developed by Christopher Laws. It is available on this GitHub page. The GY-302 costs less than one euro.

Add the BH1750 library to the Arduino IDE

Download the ZIP archive of the library from GitHub without decompressing it.

github arduino library bh1750

From the Arduino IDE, go to the menu and then Add the .ZIP library

ide arduino add ajouter librairie

Circuit

The GY-302 module (BH1750) communicates via the I2C bus with the Arduino or ESP8266. The wiring is very simple. Locating the GY-302 pins.

Pin Description
GND Ground
ADDR Select I2C adresse. 0x23 by default. 0x5C if connected to 3V3
SDA I2C SDA
SCL I2C SCL
VCC 3.3V

arduino ic2 BH1750 circuit

For your Fritzing schemas, the component is available on GitHub here

On an Arduino, connect the SDA pin to pin A4 and SCL on pin A5. On the ESP8266 Wemos d1 mini, SDA is in D2 and SCL in D1. For other ESP8266 cards, read this article.

It is possible to manually assign the I2C bus pins using the Wire.h library. At the beginning of the program, the bookstore is declared

Then in the setup ()

Here, all I2C devices are diverted to the new pins.

How to measure the quality of lighting?

In Europe, EN 12464-1 (summary in English and French) defines the minimum lighting levels according to the occupied workplace.

en 12464-1 niveau luminosite eclairage lux

Source: LUX Lighting Review No. 228 May / June 2004 available online.

In a dwelling, there is no specific standard (to my knowledge). Keria, a lighting specialist, has published some common light intensities on his site. Here are excerpts of the recommendations for some rooms of the house (or to obtain a certain atmosphere: intimate, convivial, game, work).

Pièce et ambiance recherchée Intensité lumineuse Couleur recommandée
Salon, salle à manger, chambre d’adulte. Ambiance tamisée, intime. 25-50 lux Blanc chaud
Salon, salle à manger, cuisine, chambre d’adulte, bureau. Ambiance conviviale, moments de détente. 100-150 lux Blanc chaud
Bureau, bibliothèque, chambre d’enfant, salle de jeux. Ambiance de travail, de jeux. 200-250 lux Blanc neutre
Ambiance technique : espaces de forte activité (bureau, atelier) et de circulation (couloirs, entrée) 350-500 lux Blanc froid

Source : https://www.keria.com/guides/comment-calculer-la-quantite-declairage-necessaire-dans-une-piece

On the basis of these different data, I constructed a 5-level indicator (too low, low, ideal, high, too high). You can adjust the values according to your habits and needs.

How to use the BH1750 library

The BH1750 library is used very similar to the BME280 library (or BMP180). At the beginning of the program, the library is called and the lightMeter object is initialized by indicating the address of the BH1750 on the I2C bus. By default the BH1750 is located at address 0x23. If you have a conflict with another component, you can assign the address 0x5C by feeding the addr pin to 3.3V.

The library supports the 6 modes of operation of the sensor. The sensor can measure continuous brightness

  • BH1750_CONTINUOUS_LOW_RES_MODE: Fast measurement (16ms) at low resolution (4 lux of precision)
  • BH1750_CONTINUOUS_HIGH_RES_MODE (default mode): High resolution (1 lux accuracy). The measurement time is 120ms
  • BH1750_CONTINUOUS_HIGH_RES_MODE_2: Very high resolution (0.5 lux accuracy). Measurement time 120ms

These three other modes allow to realize a single measurement (One_Time) and then to put the sensor in energy saving. Accuracy and measurement time are identical.

  • BH1750_ONE_TIME_LOW_RES_MODE
  • BH1750_ONE_TIME_HIGH_RES_MODE
  • BH1750_ONE_TIME_HIGH_RES_MODE_2

In the setup, the lightMeter object is started by using the function begin (uint8_t mode) by passing it as parameter the measurement mode. The configure (uint8_t mode) function is (called by begin) is also exposed.

The readLightLevel method reads the light intensity measured by the BH1750 at any time. The function returns the measurement directly to Lux.

Arduino Code / ESP8266

Here is the complete code of the application you just need to upload. It works either on Arduino, ESP8266 or ESP32.

Here. One more brick finished for our station is monitoring the air quality (and well being).

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.

Tags:

DIY Projects