Examples
Examples
A complete collection of FastBee-Arduino configuration examples covering basic GPIO, sensors, displays, communication protocols, and Modbus sub-devices.
Recommended reading: Supported Modules and Sensors — confirm edition support first; Sensor and Module Guide — detailed configuration reference
Example List
Basic Experiments (01-24)
| No. | Name | Core Peripheral Type |
|---|---|---|
| 01 | LED First Use | 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 Light | GPIO_PWM_OUTPUT |
| 12 | UART Communication | UART |
| 13 | ADC Voltage | GPIO_ANALOG_INPUT |
| 14 | RGB NeoPixel Strip | NEO_PIXEL |
| 15 | 7-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 | IR_REMOTE (S3-full) |
| 22 | Servo SG90 | PWM_SERVO |
| 23 | OLED Display | LCD(SSD1306) |
| 24 | SD Card | SDIO placeholder (driver TBD, recommend S3-full) |
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 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 placeholder (PCF8574 driver TBD) |
| 40 | BMP280 Pressure | I2C SENSOR (S3-full) |
| 41 | MPU6050 Gyroscope | I2C SENSOR (S3-full) |
| 42 | IR Tracking | GPIO_DIGITAL_INPUT |
| 43 | RFID MFRC522 | SPI SENSOR (S3-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 | UART(Modbus RTU) |
| 47 | Modbus Relay Module | UART(Modbus RTU) |
| 48 | Modbus Soil Sensor | UART(Modbus RTU) |
RF and Radar (49-50)
| No. | Name | Core Peripheral Type |
|---|---|---|
| 49 | 433 MHz RF Module | RF_MODULE |
| 50 | Radar Sensor | RADAR_SENSOR |
Best Practices
Pin Assignment Guidelines
- GPIO34-39: Input only—suitable for ADC/digital input
- GPIO6-11: Connected to Flash—not recommended
- GPIO32-39: ADC1—usable while WiFi is active (preferred)
- GPIO4,12-15,25-27: ADC2—unavailable while WiFi is active
- GPIO0: BOOT button—use with caution
- GPIO5: STATE LED—occupied by default
Sensor Configuration Tips
- DHT11/DHT22: Sampling interval ≥ 2 s to avoid read errors
- DS18B20: Multiple sensors on one bus, distinguished by address
- I2C devices: Share SDA/SCL but addresses must not conflict
- HC-SR04: Trigger and echo pins must differ; interval ≥ 100 ms
- BMP280/MPU6050: Full edition only; requires more memory
Rule Design Recommendations
- Periodic collection: intervalSec ≥ 5 s to avoid hammering sensors
- Event triggers: Confirm
ds:<id>_<field>data source exists before creating the rule - Relay control: Check active level (active-high vs. active-low)
- Scripts: Full RuleScript requires Full edition; Lite/Standard use command scripts
- Sync delay: Add syncDelayMs (100–500 ms) between actions to avoid concurrency issues
Common Scenarios
Scenario 1: Temperature Monitoring Alarm
Goal: Open a fan (relay) when temperature exceeds 30 °C.
- Configure DHT11 (type: 38, pin: 13)
- Configure relay (type: 12, pin: 25)
- Create timer collection rule (every 10 s)
- Create event trigger rule (temp > 30 °C → GPIO high on relay)
- Report via MQTT (reportAfterExec: true)
Scenario 2: Auto Light on Low Illuminance
Goal: Turn on LED when illuminance drops below 50 lux.
- Configure BH1750 (type: 38, I2C addr: 0x23) or photoresistor ADC
- Configure LED (type: 12, pin: 26)
- Timer read every 5 s
- Event trigger: illuminance < 50 lux → GPIO high
Reference: 33-light-sensor, 01-led-first
Scenario 3: Modbus Device Control
Goal: Read temperature and control relay via Modbus RTU.
- Configure UART for Modbus RTU (TX: 17, RX: 16)
- Scan slave devices (address 1-247)
- Map registers to data points
- Create polling rule (every 10 s)
- Event trigger: temp > 35 °C → write Modbus coil
Reference: 45-modbus-temp, 47-modbus-relay
Scenario 4: Local Display Monitoring
Goal: Show temperature and humidity on OLED, refreshed every second.
- Configure DHT11 (type: 38)
- Configure OLED (type: 36, I2C addr: 0x3C)
- Timer read every 2 s
- Display actions: show temp/humidity text
Reference: 23-oled-display, 15-seven-segment
Scenario 5: Button Multi-Function Control
Goal: Short press toggles LED; long press switches mode.
- Configure button (type: 13, GPIO_DIGITAL_INPUT_PULLUP, pin: 0)
- Configure LED (type: 12, pin: 26)
- Event trigger on click → toggle LED
- Event trigger on long press → switch mode
Reference: 06-button-control
Scenario 6: Overcurrent Protection
Goal: Cut power and raise alarm when current exceeds 15 A.
- Configure ACS712 ADC (type: 15, pin: 34)
- Configure relay (type: 12, pin: 25)
- Timer read every 1 s with sensitivity/zeroOffset calibration
- Event trigger: current > 15 → GPIO low + report
over_currentevent
Reference: 13-adc-voltage
Peripheral Type Quick Reference
| 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 | Both-edge interrupt |
| 21 | GPIO_TOUCH | Touch input |
| 36 | LCD | Display (SSD1306/SH1106; LCD1602 TBD) |
| 37 | SDIO | SD card placeholder |
| 38 | SENSOR | Sensor (DHT/DS18B20/BMP280 etc.) |
| 41 | PWM_SERVO | Servo |
| 42 | STEPPER_MOTOR | Stepper motor |
| 43 | ENCODER | Rotary encoder |
| 44 | ONE_WIRE | 1-Wire (DS18B20) |
| 45 | NEO_PIXEL | WS2812B RGB strip |
| 47 | SEVEN_SEGMENT_TM1637 | TM1637 digital tube |
| 48 | RF_MODULE | 433 MHz RF TX/RX |
| 49 | RADAR_SENSOR | RCWL-0516 / 5.8 GHz radar |
Firmware Compatibility
| Label | Meaning |
|---|---|
| Lite / Standard / Full | Supported on all editions; see the supported list for chip-specific differences |
| Standard / Full | Requires Standard or Full edition; IR remote currently Standard only |
Related Documentation
- Peripheral Management — Add and configure peripherals
- PeriphExec Management — Rule-based automation
- Peripherals Docs — Detailed documentation for each peripheral type
- Modbus RTU Protocol — Modbus communication configuration
For the full Chinese source page, see 示例文档.
