Skip to content

Example 33: Light Sensor ​

Experiment Overview ​

A photoresistor (LDR) changes resistance based on light intensity — the stronger the light, the lower the resistance. A voltage divider circuit converts resistance changes to voltage changes, which are read by the ADC. Suitable for automatic lighting, light-controlled curtains, and similar applications.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
AOGPIO34Light sensor module analog output

The stronger the light, the lower the analog output value; the weaker the light, the higher the value.

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "light_01",
      "name": "Light Sensor",
      "type": 15,
      "enabled": false,
      "pins": [34],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario 1: Auto Light On at Dusk (Polling Trigger) ​

Feature: Automatically turn on light when darkness is detected (ADC > 3000)

Web UI Configuration Steps ​

Step 1: Ensure LED Peripheral is Configured

  • Peripheral ID: led_d1
  • Type: GPIO Output

Step 2: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Auto Light On at Dusk
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 3: Configure Trigger (Polling Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Polling TriggerPeriodic condition check
    Target PeripheralSelect light_01Light sensor
    Polling Interval50005 seconds
    Condition Expressionvalue > 3000Low light threshold

Step 4: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select LOW (common-anode LED)
    • Target Peripheral: Select led_d1
  3. Click Save button


Scenario 2: Auto Light Off at Dawn (Polling Trigger) ​

Feature: Automatically turn off light when dawn is detected (ADC < 1000)

Configuration Steps:

  1. Create rule, name: Auto Light Off at Dawn
  2. Trigger configuration:
    • Trigger Type: Select Polling Trigger
    • Target Peripheral: Select light_01
    • Polling Interval: 5000
    • Condition Expression: value < 1000 (bright light threshold)
  3. Action configuration:
    • Action Type: Select HIGH (common-anode LED off)
    • Target Peripheral: Select led_d1
  4. Click Save

Light Sensor Value Reference ​

Light ConditionADC ValueDescription
Bright (Sunlight)<500Bright environment
Indoor Light1000-2000Normal indoor
Dusk2000-3000Dim light
Dark Night>3000Very dark

Notes ​

  1. Response Speed: Photoresistors respond slowly (~tens of milliseconds); not suitable for fast-changing detection
  2. Temperature Effect: Temperature changes slightly affect resistance
  3. Threshold Calibration: Thresholds differ across environments; on-site tuning required
  4. Non-linearity: The resistance-to-light relationship of photoresistors is non-linear

FastBee | fastbee.cn