Skip to content

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 ​

PeripheralTypeDescription
light_sensorGPIO_ANALOG_INPUT(15)Photosensitive resistor ADC
relay_lightGPIO_DIGITAL_OUTPUT(12)Light relay

Complete Configuration Process ​

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

  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 Photosensitive Sensor

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDlight_sensorLight sensor
    NameLight SensorDisplay name
    Peripheral TypeGPIO Analog Input (type: 15)ADC collection
    Pin Configuration36AO connected to GPIO36 (ADC1)
    Initial State0Default
  3. Click Save

Step 3: Add Lighting Relay

  1. Click the Add Peripheral button again

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDrelay_lightLighting relay
    NameLighting RelayDisplay name
    Peripheral TypeGPIO Digital Output (type: 12)Relay control
    Pin Configuration15IN connected to GPIO15
    Initial State0Default off
  3. Click Save


Step 2: Configure Peripheral Execution Rules ​

Rule 1: Turn On Light When Dark

  1. Click Peripheral Execution in the left menu

  2. Click the Add Rule button

  3. Fill in basic configuration:

    • Rule Name: Turn On Light When Dark
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled
  4. Configure trigger:

    • Trigger Type: Select Platform Trigger
    • Target Peripheral ID: Enter light_sensor
    • Operator: Select Less Than (<)
    • Threshold: 500 (low voltage when dark)
  5. Configure action:

    • Action Type: Select High Level
    • Target Peripheral: Select relay_light
  6. Click Save


Rule 2: Turn Off Light When Bright

  1. Create rule, name: Turn Off Light When Bright

  2. Trigger configuration:

    • Trigger Type: Select Platform Trigger
    • Target Peripheral ID: Enter light_sensor
    • Operator: Select Greater Than (>)
    • Threshold: 2000 (high voltage when bright)
  3. Action configuration:

    • Action Type: Select Low Level
    • Target Peripheral: Select relay_light
  4. 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 ​

  1. Photosensitive resistor and fixed resistor form a voltage divider; ADC reads the voltage at the divider point
  2. Stronger light → lower photosensitive resistance → higher ADC value
  3. Dimmer light → higher photosensitive resistance → lower ADC value
  4. Set dark threshold (500) and bright threshold (2000) to form a hysteresis band, avoiding frequent switching

Precautions ​

  1. Hysteresis Design: Gap between light-on threshold (500) and light-off threshold (2000) prevents jitter
  2. Sensor Direction: Some photosensitive modules have inverted logic (higher value when darker); comparison direction needs to be swapped
  3. ADC Pins: Use ADC1 channels (GPIO32-39) to avoid WiFi conflicts

FastBee | fastbee.cn