Skip to content

BH1750 Light Sensor ​

The BH1750 is a commonly used I2C illuminance sensor that directly outputs illuminance values, suitable for automatic lighting, agricultural supplemental lighting, shading control, and environmental logging. The current driver is a lightweight implementation that does not depend on additional third-party libraries, making it available for slim ESP32 firmware.

Wiring ​

BH1750ESP32
VCC3.3V
GNDGND
SDAGPIO21
SCLGPIO22

Default address is 0x23; when the ADDR pin is changed, the common address is 0x5C.

Configuration ​

Before saving BH1750 configuration, verify the I2C address, sampling mode, and light range.

Step 1: Navigate to Peripheral Management Page ​

  1. Open a browser and navigate to the ESP32 IP address
  2. After logging in, click Peripheral Configuration in the left menu

Step 2: Add BH1750 Peripheral ​

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDbh1750_i2cUnique identifier
    NameBH1750 LightDisplay name
    Peripheral TypeGeneric Sensor (type: 38)I2C sensor
    SDA Pin21I2C data pin
    SCL Pin22I2C clock pin
    I2C Address0x230x23 or 0x5C
    Sampling Interval50005 seconds
  3. Click Save

Step 3: Verify Configuration ​

  1. Find the newly added peripheral in the peripheral list
  2. Click the Enable toggle
  3. Wait 5 seconds and check illuminance data (lx)

💡 Tip: BH1750 directly outputs illuminance values, no ADC conversion needed


Method 2: JSON Configuration File Import ​

json
{
  "id": "bh1750_i2c",
  "name": "BH1750 Light",
  "type": 2,
  "enabled": false,
  "pinCount": 2,
  "pins": [21, 22, 255, 255, 255, 255, 255, 255],
  "params": {
    "frequency": 100000,
    "address": 0,
    "isMaster": true
  }
}

Peripheral Execution Integration ​

Web Interface Configuration Steps ​

Create Light Collection and Auto Light-On Rule

  1. Click Peripheral Execution in the left menu
  2. Click the Add Rule button
  3. Configure a timer trigger:
    • Trigger Type: Timer Trigger
    • Execution Interval: 20 seconds
  4. Add action:
    • Action 1: Read illuminance
      • Action Type: Sensor Read
      • Target Peripheral: bh1750_i2c
      • Data Field: illuminance
  5. Enable Report Data After Execution
  6. Click Save

Create Low Light Turn-On Rule

  1. Create a new rule
  2. Configure an event trigger:
    • Trigger Type: Event Trigger
    • Event ID: ds:bh1750_i2c_illuminance
    • Comparison: Less Than
    • Comparison Value: 80 (lx)
  3. Add action:
    • Action Type: High Level
    • Target Peripheral: relay_light (lighting relay)
  4. Click Save

💡 Tip: Event ID format is ds:{peripheralID}_{fieldName}


JSON Configuration Example ​

json
{
  "id": "exec_bh1750_read",
  "name": "BH1750 Light Collection",
  "enabled": false,
  "triggers": [
    {
      "triggerType": 1,
      "timerMode": 0,
      "intervalSec": 20
    }
  ],
  "actions": [
    {
      "targetPeriphId": "bh1750_i2c",
      "actionType": 19,
      "actionValue": "{\"periphId\":\"bh1750_i2c\",\"sensorCategory\":\"BH1750\",\"dataField\":\"illuminance\",\"sensorLabel\":\"Light\",\"unit\":\"lx\",\"decimalPlaces\":0,\"driverParams\":{\"addr\":\"0x23\",\"sda\":21,\"scl\":22}}",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "reportAfterExec": true
}

Low Light Turn-On ​

json
{
  "id": "exec_bh1750_light_on",
  "name": "Low Illuminance Light-On",
  "enabled": false,
  "triggers": [
    {
      "triggerType": 4,
      "eventId": "ds:bh1750_i2c_illuminance",
      "operatorType": 3,
      "compareValue": "80"
    }
  ],
  "actions": [
    {
      "targetPeriphId": "relay_light",
      "actionType": 0,
      "actionValue": "",
      "useReceivedValue": false,
      "syncDelayMs": 0,
      "execMode": 0
    }
  ],
  "reportAfterExec": true
}

Available Data Fields ​

dataFieldMeaningUnit
illuminanceIlluminancelx

FastBee | fastbee.cn