Skip to content

Example 30: Rain Sensor ​

Experiment Overview ​

A raindrop sensor outputs both analog and digital signals by detecting water droplets on its board surface. The analog output reflects humidity levels, while the digital output indicates whether a threshold has been reached. Suitable for smart clotheslines, automatic rain awnings, and similar applications.

Hardware Wiring ​

Board LabelGPIO PinConnected Device
AOGPIO34Rain sensor analog output
DOGPIO4Rain sensor digital output

The module includes a potentiometer to adjust the digital output threshold.

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "rain_analog",
      "name": "Rainfall - Analog",
      "type": 15,
      "enabled": false,
      "pins": [34],
      "params": {}
    },
    {
      "id": "rain_digital",
      "name": "Raindrop - Switch",
      "type": 11,
      "enabled": false,
      "pins": [4],
      "params": {}
    }
  ]
}

Peripheral Execution Linkage ​

Scenario: Rain Alarm (Polling Trigger) ​

Feature: Check raindrop switch every 1 second; trigger buzzer alarm when rain is detected

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: Rain 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 rain_digitalRaindrop switch
    Polling Interval10001 second
    Condition Expressionvalue == 0LOW = rain detected

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 Weather Event

  1. Click Add Action button again

  2. Fill in:

    • Action Type: Select Send Event
    • Event Type: weather
    • Event Message: Rain detected
  3. Click Save button

Raindrop Sensor Value Reference ​

StatusAnalog ValueDescription
No Water~4095Dry condition
Light Rain2000-3000Few water droplets
Moderate Rain1000-2000More water droplets
Heavy Rain<1000Many water droplets

Notes ​

  1. Corrosion: Prolonged exposure leads to sensor board corrosion; power off when not raining
  2. Threshold Adjustment: Adjust digital output trigger sensitivity via the on-module potentiometer
  3. Analog Value: Near 4095 when dry; decreases when wet — lower value means heavier rain
  4. ADC2 Limitation: GPIO34 belongs to ADC1, unaffected during WiFi operation

FastBee | fastbee.cn