Light-Sensitive Auto Light Control Scenario
Light-Sensitive Auto Light Control Scenario
Scenario Description
Use a photosensitive sensor (ADC) to detect ambient light intensity. When light falls below a threshold, automatically turn on the light (relay); when light recovers, automatically turn off the light.
Required Peripherals
| Peripheral | Type | Description |
|---|---|---|
| light_sensor | GPIO_ANALOG_INPUT(15) | Photosensitive resistor ADC |
| relay_light | GPIO_DIGITAL_OUTPUT(12) | Light relay |
Complete Configuration Process
Method 1: Web Interface Configuration (Recommended)
This scenario requires first adding the photosensitive ADC and lighting relay, then using peripheral execution rules for threshold evaluation and on/off control.
Step 1: Configure Peripherals
Step 1: Open 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 Photosensitive Sensor
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID light_sensorLight sensor Name Light SensorDisplay name Peripheral Type GPIO Analog Input (type: 15) ADC collection Pin Configuration 36AO connected to GPIO36 (ADC1) Initial State 0Default Click Save
Step 3: Add Lighting Relay
Click the Add Peripheral button again
Fill in the configuration:
Field Value Description Peripheral ID relay_lightLighting relay Name Lighting RelayDisplay name Peripheral Type GPIO Digital Output (type: 12) Relay control Pin Configuration 15IN connected to GPIO15 Initial State 0Default off Click Save
Step 2: Configure Peripheral Execution Rules
Rule 1: Turn On Light When Dark
Switch to Peripheral Execution Management tab
Click the Add Rule button
Fill in basic configuration:
- Rule Name:
Turn On Light When Dark - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Configure trigger:
- Trigger Type: Select Platform Trigger
- Target Peripheral ID: Enter
light_sensor - Operator: Select
Less Than (<) - Threshold:
500(low voltage when dark)
Configure action:
- Action Type: Select High Level
- Target Peripheral: Select
relay_light
Click Save
Rule 2: Turn Off Light When Bright
Create rule, name:
Turn Off Light When BrightTrigger configuration:
- Trigger Type: Select Platform Trigger
- Target Peripheral ID: Enter
light_sensor - Operator: Select
Greater Than (>) - Threshold:
2000(high voltage when bright)
Action configuration:
- Action Type: Select Low Level
- Target Peripheral: Select
relay_light
Click Save
💡 Tip: Light-on threshold 500, light-off threshold 2000, forming a 1500 hysteresis band to prevent frequent switching
Method 2: JSON Configuration File Import
Working Principle
- Photosensitive resistor and fixed resistor form a voltage divider; ADC reads the voltage at the divider point
- Stronger light → lower photosensitive resistance → higher ADC value
- Dimmer light → higher photosensitive resistance → lower ADC value
- Set dark threshold (500) and bright threshold (2000) to form a hysteresis band, avoiding frequent switching
Precautions
- Hysteresis Design: Gap between light-on threshold (500) and light-off threshold (2000) prevents jitter
- Sensor Direction: Some photosensitive modules have inverted logic (higher value when darker); comparison direction needs to be swapped
- ADC Pins: Use ADC1 channels (GPIO32-39) to avoid WiFi conflicts
