Example 30: Rain Sensor
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 Label | GPIO Pin | Connected Device |
|---|---|---|
| AO | GPIO34 | Rain sensor analog output |
| DO | GPIO4 | Rain sensor digital output |
The module includes a potentiometer to adjust the digital output threshold.
JSON Configuration Example
{
"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
- Click Peripheral Config in the left menu → Switch to Peripheral Execution tab
- Click New Rule button
- Fill in basic configuration:
- Rule Name:
Rain Alarm - 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 rain_digitalRaindrop switch Polling Interval 10001 second Condition Expression value == 0LOW = rain detected
Step 4: Configure Actions (2 actions required)
Action 1: Buzzer Alarm
- Click Add Action button
- Fill in:
- Action Type: Select HIGH
- Target Peripheral: Select
buzzer_gpio
Action 2: Send Weather Event
Click Add Action button again
Fill in:
- Action Type: Select Send Event
- Event Type:
weather - Event Message:
Rain detected
Click Save button
Raindrop Sensor Value Reference
| Status | Analog Value | Description |
|---|---|---|
| No Water | ~4095 | Dry condition |
| Light Rain | 2000-3000 | Few water droplets |
| Moderate Rain | 1000-2000 | More water droplets |
| Heavy Rain | <1000 | Many water droplets |
Notes
- Corrosion: Prolonged exposure leads to sensor board corrosion; power off when not raining
- Threshold Adjustment: Adjust digital output trigger sensitivity via the on-module potentiometer
- Analog Value: Near 4095 when dry; decreases when wet — lower value means heavier rain
- ADC2 Limitation: GPIO34 belongs to ADC1, unaffected during WiFi operation
