Example 29: Photoelectric Sensor
About 1 min
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 Label | GPIO Pin | Connected Device |
|---|---|---|
| OUT | GPIO4 | Photoelectric sensor DO output (LOW when obstructed) |
JSON Configuration Example
{
"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
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Pass Counter - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 2: Configure Trigger (Polling Trigger)
Click Add Trigger button
Fill in trigger configuration:
Field Value Description Trigger Type Select Polling Trigger Periodic condition check Target Peripheral Select photoelectric_01Photoelectric sensor Polling Interval 5050ms (fast detection) Condition Expression value == 0LOW = light path obstructed
Step 3: Configure Action (Script Counting)
Click Add Action button
Fill in:
- Action Type: Select Command Script
- Action Parameter:
var c=getVar('count',0); c++; setVar('count',c);Click Save button
Application Scenarios
| Scenario | Description | Detection Range |
|---|---|---|
| Item Counting | Conveyor belt item statistics | 5-30cm |
| Limit Detection | Robotic arm position limiting | 5-30cm |
| Safety Protection | Dangerous area intrusion detection | 5-30cm |
Notes
- Alignment: Transmitter and receiver must be directly aligned; misalignment causes false readings
- Ambient Light: Strong light environments may interfere with the receiver; add a light shield
- Detection Range: Typical effective range is 5-30cm (module type)
- Response Speed: Photoelectric sensors respond quickly (<1ms), suitable for high-speed counting
