Example Documentation
Example Documentation
A comprehensive collection of FastBee-Arduino configuration examples, covering basic GPIO operations, sensor integration, display control, communication protocols and Modbus sub-device access.
Recommended reading: Supported Sensors and Modules - Confirm version support first; Complete Sensor and Module Guide - View detailed configuration reference
Example List
Basic Experiments (01-24)
| No. | Name | Core Peripheral Type |
|---|---|---|
| 01 | LED On | GPIO_DIGITAL_OUTPUT |
| 02 | LED Blink | GPIO_DIGITAL_OUTPUT + periph-exec |
| 03 | LED Running Light | Multi GPIO + JavaScript Script |
| 03b | LED Running Light (Command Script) | Multi GPIO + PERIPH/DELAY Command Sequence |
| 04 | Buzzer | GPIO_DIGITAL_OUTPUT / PWM |
| 05 | Relay | GPIO_DIGITAL_OUTPUT |
| 06 | Button Control | GPIO_DIGITAL_INPUT_PULLUP |
| 07 | DC Motor | GPIO_DIGITAL_OUTPUT |
| 08 | Stepper Motor | STEPPER_MOTOR |
| 09 | External Interrupt | GPIO_INTERRUPT |
| 10 | Timer Trigger | TIMER_TRIGGER |
| 11 | PWM Breathing LED | GPIO_PWM_OUTPUT |
| 12 | UART Communication | UART |
| 13 | ADC Voltage Sampling | GPIO_ANALOG_INPUT |
| 14 | RGB LED Strip | NEO_PIXEL |
| 15 | Seven-Segment Display | SEVEN_SEGMENT_TM1637 |
| 16 | NTP Clock | System NTP + Timer |
| 17 | DS1302 RTC | External RTC |
| 18 | DS18B20 Temperature | SENSOR(ONE_WIRE) |
| 19 | DHT11 Temp & Humidity | SENSOR(DHT) |
| 20 | Ultrasonic Distance | SENSOR(HC-SR04) |
| 21 | IR Remote Control | IR_REMOTE (Standard / ESP32 Full) |
| 22 | Servo Control | PWM_SERVO |
| 23 | OLED Display | LCD(SSD1306) |
| 24 | SD Card Read/Write | SDIO config placeholder (SPI partial, file actions TBD) |
Extended Experiments (25-44)
| No. | Name | Core Peripheral Type |
|---|---|---|
| 25 | Laser Sensor | GPIO_DIGITAL_OUTPUT |
| 26 | Tilt Sensor | GPIO_DIGITAL_INPUT_PULLUP |
| 27 | Vibration Sensor | GPIO_DIGITAL_INPUT |
| 28 | Reed Switch | GPIO_DIGITAL_INPUT |
| 29 | Photoelectric Sensor | GPIO_DIGITAL_INPUT |
| 30 | Rain Drop Sensor | ADC + GPIO |
| 31 | PS2 Joystick | Dual ADC + Button |
| 32 | Sound Sensor | GPIO_ANALOG_INPUT |
| 33 | Light Sensor | GPIO_ANALOG_INPUT |
| 34 | Flame Sensor | GPIO_ANALOG_INPUT |
| 35 | Smoke Sensor MQ-2 | GPIO_ANALOG_INPUT |
| 36 | Touch Sensor | GPIO_TOUCH |
| 37 | Rotary Encoder | ENCODER |
| 38 | IR Obstacle | GPIO_DIGITAL_INPUT |
| 39 | LCD1602 Display | LCD config placeholder (PCF8574 driver TBD) |
| 40 | BMP280 Pressure | I2C SENSOR (Standard / Full) |
| 41 | MPU6050 Gyroscope | I2C SENSOR (Standard / Full) |
| 42 | IR Line Tracking | GPIO_DIGITAL_INPUT |
| 43 | RFID MFRC522 | SPI SENSOR (Standard / Full) |
| 44 | PIR Motion | GPIO_DIGITAL_INPUT |
Modbus Sub-Devices (45-48)
| No. | Name | Core Peripheral Type |
|---|---|---|
| 45 | Modbus Temp & Humidity Sensor | UART(Modbus RTU) |
| 46 | Modbus Stepper Motor Control | UART(Modbus RTU) |
| 47 | Modbus Relay Module | UART(Modbus RTU) |
| 48 | Modbus Soil Sensor | UART(Modbus RTU) |
RF & Radar (49-50)
| No. | Name | Core Peripheral Type |
|---|---|---|
| 49 | 433MHz RF Module | RF_MODULE |
| 50 | Radar Sensor Module | RADAR_SENSOR |
Best Practices
Pin Assignment Principles
- GPIO34-39: Input only, suitable for ADC/digital input
- GPIO6-11: Connected to Flash, not recommended for use
- GPIO32-39: ADC1, available after WiFi is enabled (preferred)
- GPIO4,12-15,25-27: ADC2, unavailable after WiFi is enabled
- GPIO0: BOOT button, use with caution
- GPIO5: STATE LED, occupied by default
Sensor Configuration Tips
- DHT11/DHT22: Sampling interval >= 2 seconds, avoid reading too fast to prevent data anomalies
- DS18B20: Multiple sensors can share the one-wire bus, distinguished by address
- I2C Devices: Can share SDA/SCL, but I2C addresses must not conflict
- Ultrasonic HC-SR04: Trigger and echo pins must differ, sampling interval >= 100ms
- BMP280/MPU6050: Standard / Full support, requires
FASTBEE_ENABLE_I2C_SENSORS
Peripheral Execution Rule Design
- Periodic Acquisition: intervalSec >= 5 seconds, avoid frequent sensor reads
- Event Trigger: First confirm the acquisition rule has generated the
ds:<id>_<field>data source - Linked Control: Pay attention to relay active level (high-active / low-active)
- Script Execution: Standard / Full support Command Script and RuleScript, Lite has script actions disabled by default
- Sync Delay: Add syncDelayMs (100-500ms) between actions to avoid concurrent conflicts
Common Scenarios
Scenario 1: Temperature/Humidity Monitoring Alarm
Requirement: Turn on the fan (relay) when temperature exceeds 30°C
Steps:
- Configure DHT11 sensor (type: 38, pin: 13)
- Configure relay (type: 12, pin: 25)
- Create periodic acquisition rule (read DHT11 every 10 seconds)
- Trigger: timerTrigger, intervalSec: 10
- Action 1: sensorRead (dht_01, temperature)
- Create event trigger rule (temperature > 30°C)
- Trigger: eventTrigger, eventId:
ds:dht_01_temperature, operator: >, value: 30 - Action: GPIO HIGH (relay_01)
- Trigger: eventTrigger, eventId:
- Report to MQTT cloud platform (reportAfterExec: true)
Reference: 19-dht11-humidity.md, 05-relay.md
Scenario 2: Auto Light on Low Illuminance
Requirement: Automatically turn on LED when illuminance drops below 50 lux
Steps:
- Configure BH1750 light sensor (type: 38, I2C address: 0x23)
- Or use photoresistor ADC (type: 15, pin: 34)
- Configure LED (type: 12, pin: 26)
- Periodically read illuminance (every 5 seconds)
- Action: sensorRead (bh1750_01, illuminance)
- Event trigger: illuminance < 50 lux
- Trigger: eventTrigger, eventId:
ds:bh1750_01_illuminance, operator: <, value: 50 - Action: GPIO HIGH (led_01)
- Trigger: eventTrigger, eventId:
- Delayed off or re-detect (avoid frequent switching)
Reference: 33-light-sensor.md, 01-led-first.md
Scenario 3: Modbus Device Control
Requirement: Control temperature/humidity sensor and relay via Modbus RTU
Steps:
- Configure UART as Modbus RTU (type: 1, pins: TX-17, RX-16)
- Scan slave devices (address 1-247)
- Map registers to data points
- Holding registers 40001-40002: temperature
- Holding registers 40003-40004: humidity
- Create polling rule (every 10 seconds)
- Trigger: pollTrigger, read holding registers
- Action: parse data, write to sensor_cache
- Conditional trigger control command
- Event trigger: temperature > 35°C
- Action: write Modbus coil (turn on relay)
Reference: 45-modbus-temp-humidity.md, 47-modbus-relay.md
Scenario 4: Local Display Monitoring
Requirement: OLED screen displays temperature and humidity, refreshed every second
Steps:
- Configure DHT11 sensor (type: 38)
- Configure OLED display (type: 36, I2C address: 0x3C)
- Periodically read sensor data (every 2 seconds)
- Action 1: sensorRead (dht_01, temperature)
- Action 2: sensorRead (dht_01, humidity)
- Display action output
- Action 3: displayOLED, show "Temp: 28.5°C"
- Action 4: displayOLED, show "Humidity: 65%"
- Or use TM1637 seven-segment display for alternating display
- Action 3: displayTM1637, show temperature for 2 seconds
- Action 4: displayTM1637, show humidity for 2 seconds
Reference: 23-oled-display.md, 15-seven-segment.md
Scenario 5: Multi-Function Button Control
Requirement: Single button for short-press LED toggle and long-press mode switch
Steps:
- Configure button (type: 13, GPIO_DIGITAL_INPUT_PULLUP, pin: 0)
- Configure LED (type: 12, pin: 26)
- Create event trigger rule (button press)
- Trigger: eventTrigger, eventId:
button:btn_01:click - Action: toggle LED state (HIGH/LOW)
- Trigger: eventTrigger, eventId:
- Create long-press rule
- Trigger: eventTrigger, eventId:
button:btn_01:long_press - Action: toggle mode (auto/manual)
- Trigger: eventTrigger, eventId:
Reference: 06-button-control.md
Scenario 6: Overcurrent Protection
Requirement: Auto power-off and alarm when current exceeds 15A
Steps:
- Configure ACS712 current sensor ADC (type: 15, pin: 34)
- Configure relay (type: 12, pin: 25)
- Periodically read current value (every 1 second)
- Action: sensorRead (current_01, current)
- Advanced params: sensitivity, zeroOffset, vRef, adcMax
- Event trigger: current > 15
- Action 1: GPIO LOW (turn off relay)
- Action 2: triggerEvent, report
over_currentevent - Action 3: MQTT report alarm message
Reference: 13-adc-voltage.md
Peripheral Type Quick Reference
| Type Value | Type Name | Description |
|---|---|---|
| 1 | UART | Serial / Modbus RTU |
| 11 | GPIO_DIGITAL_INPUT | Digital input |
| 12 | GPIO_DIGITAL_OUTPUT | Digital output |
| 13 | GPIO_DIGITAL_INPUT_PULLUP | Pull-up input (button) |
| 15 | GPIO_ANALOG_INPUT | ADC analog input |
| 17 | GPIO_PWM_OUTPUT | PWM output |
| 18 | GPIO_INTERRUPT_RISING | Rising edge interrupt |
| 19 | GPIO_INTERRUPT_FALLING | Falling edge interrupt |
| 20 | GPIO_INTERRUPT_CHANGE | Dual-edge interrupt |
| 21 | GPIO_TOUCH | Touch input |
| 36 | LCD | Display (currently supports SSD1306/SH1106, LCD1602 TBD) |
| 37 | SDIO | SD card interface config placeholder |
| 38 | SENSOR | Sensor (DHT/DS18B20/BMP280 etc.) |
| 41 | PWM_SERVO | Servo |
| 42 | STEPPER_MOTOR | Stepper motor |
| 43 | ENCODER | Rotary encoder |
| 44 | ONE_WIRE | One-wire bus (DS18B20) |
| 45 | NEO_PIXEL | WS2812B RGB LED strip |
| 47 | SEVEN_SEGMENT_TM1637 | TM1637 seven-segment display |
| 48 | RF_MODULE | 433MHz RF transmit/receive level |
| 49 | RADAR_SENSOR | RCWL-0516 / 5.8GHz radar sensor |
Firmware Compatibility
| Mark | Meaning |
|---|---|
| Lite / Standard / Full | All versions supported, see support list for chip differences |
| Standard / Full | Requires Standard or Full version; IR remote currently only on Standard |
Related Documentation
- Peripheral Management — Add and configure peripherals
- Peripheral Execution Management — Rule linkage configuration
- Peripheral Documentation — Detailed peripheral type descriptions
- Modbus RTU Protocol — Modbus communication configuration
