BH1750 Light Sensor
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
| BH1750 | ESP32 |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | GPIO21 |
| SCL | GPIO22 |
Default address is 0x23; when the ADDR pin is changed, the common address is 0x5C.
Configuration
Method 1: Web Interface Configuration (Recommended)
Before saving BH1750 configuration, verify the I2C address, sampling mode, and light range.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add BH1750 Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID bh1750_i2cUnique identifier Name BH1750 LightDisplay name Peripheral Type Generic Sensor (type: 38) I2C sensor SDA Pin 21I2C data pin SCL Pin 22I2C clock pin I2C Address 0x230x23 or 0x5C Sampling Interval 50005 seconds Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- Wait 5 seconds and check illuminance data (lx)
💡 Tip: BH1750 directly outputs illuminance values, no ADC conversion needed
Method 2: JSON Configuration File Import
{
"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
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Configure a timer trigger:
- Trigger Type: Timer Trigger
- Execution Interval: 20 seconds
- Add action:
- Action 1: Read illuminance
- Action Type: Sensor Read
- Target Peripheral: bh1750_i2c
- Data Field: illuminance
- Action 1: Read illuminance
- Enable Report Data After Execution
- Click Save
Create Low Light Turn-On Rule
- Create a new rule
- Configure an event trigger:
- Trigger Type: Event Trigger
- Event ID: ds:bh1750_i2c_illuminance
- Comparison: Less Than
- Comparison Value: 80 (lx)
- Add action:
- Action Type: High Level
- Target Peripheral: relay_light (lighting relay)
- Click Save
💡 Tip: Event ID format is
ds:{peripheralID}_{fieldName}
JSON Configuration Example
{
"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
{
"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
| dataField | Meaning | Unit |
|---|---|---|
illuminance | Illuminance | lx |
