Skip to content

Example 28: Reed Switch Sensor ​

Experiment Overview ​

A reed switch (magnetic control switch) closes its contacts when near a magnet, suitable for door/window open-close detection, water meter pulse counting, and similar applications. Contacts open when no magnetic field is present and close when a magnetic field is detected.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
REEDGPIO4Reed switch module (DO digital output)

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "reed_01",
      "name": "Reed Switch Sensor",
      "type": 13,
      "enabled": false,
      "pins": [4],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario: Door/Window Open Alarm (Polling Trigger) ​

Feature: Check door/window status every 200ms; trigger buzzer alarm when door/window is opened

Web UI Configuration Steps ​

Step 1: Ensure Buzzer Peripheral is Configured

  • Peripheral ID: buzzer_gpio
  • 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: Door/Window Open Alarm
    • 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 reed_01Reed switch sensor
    Polling Interval200200ms
    Condition Expressionvalue == 1HIGH = door/window open

Step 4: Configure Actions (2 actions required)

Action 1: Buzzer Alarm

  1. Click Add Action button
  2. Fill in:
    • Action Type: Select HIGH
    • Target Peripheral: Select buzzer_gpio

Action 2: Send Alarm Event

  1. Click Add Action button again

  2. Fill in:

    • Action Type: Select Send Event
    • Event Type: alarm
    • Event Message: Door/window has been opened
  3. Click Save button

Installation Guide ​

ComponentInstallation LocationDescription
MagnetOn door/window sashMoves with door/window
Reed SwitchOn door/window frameFixed in place
Trigger Distance10-20mmTypical distance

Notes ​

  1. Installation Position: Place the magnet on the door/window sash; fix the reed switch on the door/window frame
  2. Trigger Distance: Typical trigger distance is 10-20mm
  3. Counting Applications: Water/gas meter pulse counting can use interrupt mode (type: 18)
  4. Sealing: Waterproof enclosure is required for outdoor use

FastBee | fastbee.cn