Skip to content

Example 29: Photoelectric Sensor ​

Experiment Overview ​

A through-beam photoelectric sensor consists of a transmitter and receiver pair. When the light path is obstructed, the output signal changes. Suitable for counting, limit detection, conveyor belt item detection, and other industrial scenarios.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
OUTGPIO4Photoelectric sensor DO output (LOW when obstructed)

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "photoelectric_01",
      "name": "Photoelectric Sensor",
      "type": 13,
      "enabled": false,
      "pins": [4],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario: Item Pass Counter (Polling Trigger + Script) ​

Feature: Detect items passing through the light path and automatically count

Web UI Configuration Steps ​

Step 1: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Pass Counter
    • Report Data: ✅ Enabled
    • Enable: ✅ Enabled

Step 2: Configure Trigger (Polling Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Polling TriggerPeriodic condition check
    Target PeripheralSelect photoelectric_01Photoelectric sensor
    Polling Interval5050ms (fast detection)
    Condition Expressionvalue == 0LOW = light path obstructed

Step 3: Configure Action (Script Counting)

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Command Script
    • Action Parameter:
    var c=getVar('count',0);
    c++;
    setVar('count',c);
  3. Click Save button

Application Scenarios ​

ScenarioDescriptionDetection Range
Item CountingConveyor belt item statistics5-30cm
Limit DetectionRobotic arm position limiting5-30cm
Safety ProtectionDangerous area intrusion detection5-30cm

Notes ​

  1. Alignment: Transmitter and receiver must be directly aligned; misalignment causes false readings
  2. Ambient Light: Strong light environments may interfere with the receiver; add a light shield
  3. Detection Range: Typical effective range is 5-30cm (module type)
  4. Response Speed: Photoelectric sensors respond quickly (<1ms), suitable for high-speed counting

FastBee | fastbee.cn