Skip to content

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 LabelGPIO PinConnected Device
OUTGPIO4IR obstacle module DO output

The on-module potentiometer adjusts detection range (2~30cm).

JSON Configuration Example ​

json
{
  "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

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Obstacle Stop
    • 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 ir_obstacle_01IR obstacle sensor
    Polling Interval5050ms (fast response)
    Condition Expressionvalue == 0Obstacle detected (LOW)

Step 4: Configure Actions (2 actions required)

Action 1: Stop Motor IN1

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select LOW
    • Target Peripheral: Select motor_in1

Action 2: Stop Motor IN2

  1. Click Add Action button again

  2. Fill in:

    • Action Type: Select LOW
    • Target Peripheral: Select motor_in2
  3. Click Save button

IR Obstacle Sensor Reference ​

StatusOutput LevelDescription
No ObstacleHIGH (1)Normal movement
Obstacle DetectedLOW (0)Need to stop

Application Scenarios ​

ScenarioDescriptionDetection Range
Obstacle-Avoiding RobotForward obstacle detection2-30cm
Limit SwitchMechanical position limiting2-30cm
Object DetectionAssembly line counting2-30cm

Notes ​

  1. Detection Range: Adjustable via potentiometer, typically 2-30cm
  2. Color Impact: Black objects absorb infrared, potentially reducing detection range
  3. Ambient Light: Strong IR light sources (sunlight) may cause interference
  4. Mounting Angle: Sensor must face the detection direction

FastBee | fastbee.cn