Example 38: IR Obstacle Sensor
About 1 min
Example 38: IR Obstacle Sensor
Experiment Overview
An IR obstacle sensor emits infrared light and detects reflected signals to determine if there is an obstacle ahead. Outputs LOW when an obstacle is detected, suitable for automatic obstacle-avoiding robots, distance detection, and similar applications.
Hardware Wiring
| Board Label | GPIO Pin | Connected Device |
|---|---|---|
| OUT | GPIO4 | IR obstacle module DO output |
The on-module potentiometer adjusts detection range (2~30cm).
JSON Configuration Example
{
"peripherals": [
{
"id": "ir_obstacle_01",
"name": "IR Obstacle",
"type": 11,
"enabled": false,
"pins": [4],
"params": {}
}
]
}Peripheral Execution Linkage
Scenario: Obstacle Stop (Polling Trigger)
Feature: Stop motors when obstacle is detected
Web UI Configuration Steps
Step 1: Ensure Motor Peripherals are Configured
- Motor IN1:
motor_in1(GPIO Output) - Motor IN2:
motor_in2(GPIO Output)
Step 2: Create Rule
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Obstacle Stop - Report Data: ✅ Enabled
- Enable: ✅ Enabled
- Rule Name:
Step 3: 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 ir_obstacle_01IR obstacle sensor Polling Interval 5050ms (fast response) Condition Expression value == 0Obstacle detected (LOW)
Step 4: Configure Actions (2 actions required)
Action 1: Stop Motor IN1
- Click Add Action button
- Fill in:
- Action Type: Select LOW
- Target Peripheral: Select
motor_in1
Action 2: Stop Motor IN2
Click Add Action button again
Fill in:
- Action Type: Select LOW
- Target Peripheral: Select
motor_in2
Click Save button
IR Obstacle Sensor Reference
| Status | Output Level | Description |
|---|---|---|
| No Obstacle | HIGH (1) | Normal movement |
| Obstacle Detected | LOW (0) | Need to stop |
Application Scenarios
| Scenario | Description | Detection Range |
|---|---|---|
| Obstacle-Avoiding Robot | Forward obstacle detection | 2-30cm |
| Limit Switch | Mechanical position limiting | 2-30cm |
| Object Detection | Assembly line counting | 2-30cm |
Notes
- Detection Range: Adjustable via potentiometer, typically 2-30cm
- Color Impact: Black objects absorb infrared, potentially reducing detection range
- Ambient Light: Strong IR light sources (sunlight) may cause interference
- Mounting Angle: Sensor must face the detection direction
