Skip to content

Examples ​

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

Hardware Cases ​

The examples below correspond to different hardware and configurations; their JSON must not be copied across devices:

EnvironmentExampleMain content
esp32c3-F4R0C3 Temperature/HumidityOLED, temperature/humidity, and low-memory usage
esp32c3-F4R0 (verify Flash first)C3 Smart Switch PanelNeutral-live 1/2/3-gang, button single click, relay and web sync; materials verified, physical device pending
esp32c6-F4R0C6 RGB Quick StartGPIO8 WS2812 with timer/platform linkage
esp32-F4R0Puzhong ESP32 TestClassic ESP32 peripherals and rules
esp32s3-F16R8ECM50-A Networking and Industrial CollectionAI/DI, SHT30, Modbus RTU, Ethernet, and 4G
esp32s3-F8R0Waveshare 6-channel Relay6-channel relay, WS2812, and RS485
esp32s3-F16R8Waveshare 4-inch TouchscreenRGB display, GT911 touch, web drag-and-drop editing, and generic device control

The JSON for existing cases is kept under docs/ in the FastBee-Arduino source repository; the smart switch panel case provides field notes and the original Arduino code, and a dedicated config must be established after confirming the physical device identity — the COM4 temperature/humidity config cannot be reused. Verify the chip, pins, and local network parameters before importing; public examples contain no production WiFi or MQTT credentials.

Example List ​

Basic Experiments (01-24) ​

No.NameCore Peripheral Type
01LED OnGPIO_DIGITAL_OUTPUT
02LED BlinkGPIO_DIGITAL_OUTPUT + periph-exec
03LED Running LightMulti GPIO + JavaScript Script
03bLED Running Light (Command Script)Multi GPIO + PERIPH/DELAY Command Sequence
04BuzzerGPIO_DIGITAL_OUTPUT / PWM
05RelayGPIO_DIGITAL_OUTPUT
06Button ControlGPIO_DIGITAL_INPUT_PULLUP
07DC MotorGPIO_DIGITAL_OUTPUT
08Stepper MotorSTEPPER_MOTOR
09External InterruptGPIO_INTERRUPT
10Timer TriggerTIMER_TRIGGER
11PWM Breathing LEDGPIO_PWM_OUTPUT
12UART CommunicationUART
13ADC Voltage SamplingGPIO_ANALOG_INPUT
14RGB LED StripNEO_PIXEL
15Seven-Segment DisplaySEVEN_SEGMENT_TM1637
16NTP ClockSystem NTP + Timer
17DS1302 RTCExternal RTC
18DS18B20 TemperatureSENSOR(ONE_WIRE)
19DHT11 Temp & HumiditySENSOR(DHT)
20Ultrasonic DistanceSENSOR(HC-SR04)
21IR Remote ControlIR_REMOTE (check environment feature state)
22Servo ControlPWM_SERVO
23OLED DisplayLCD(SSD1306)
24SD Card Read/WriteSDIO config placeholder (SPI partial, file actions TBD)

Extended Experiments (25-44) ​

No.NameCore Peripheral Type
25Laser SensorGPIO_DIGITAL_OUTPUT
26Tilt SensorGPIO_DIGITAL_INPUT_PULLUP
27Vibration SensorGPIO_DIGITAL_INPUT
28Reed SwitchGPIO_DIGITAL_INPUT
29Photoelectric SensorGPIO_DIGITAL_INPUT
30Rain Drop SensorADC + GPIO
31PS2 JoystickDual ADC + Button
32Sound SensorGPIO_ANALOG_INPUT
33Light SensorGPIO_ANALOG_INPUT
34Flame SensorGPIO_ANALOG_INPUT
35Smoke Sensor MQ-2GPIO_ANALOG_INPUT
36Touch SensorGPIO_TOUCH
37Rotary EncoderENCODER
38IR ObstacleGPIO_DIGITAL_INPUT
39LCD1602 DisplayLCD config placeholder (PCF8574 driver TBD)
40BMP280 PressureI2C SENSOR (i2cSensors required)
41MPU6050 GyroscopeI2C SENSOR (i2cSensors required)
42IR Line TrackingGPIO_DIGITAL_INPUT
43RFID MFRC522SPI SENSOR (rfid required)
44PIR MotionGPIO_DIGITAL_INPUT

Modbus Sub-Devices (45-48) ​

No.NameCore Peripheral Type
45Modbus Temp & Humidity SensorUART(Modbus RTU)
46Modbus Stepper Motor ControlUART(Modbus RTU)
47Modbus Relay ModuleUART(Modbus RTU)
48Modbus Soil SensorUART(Modbus RTU)

RF & Radar (49-50) ​

No.NameCore Peripheral Type
49433MHz RF ModuleRF_MODULE
50Radar Sensor ModuleRADAR_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: Require FASTBEE_ENABLE_I2C_SENSORS and the active i2cSensors runtime feature

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: Requires active ruleScript and commandScript; low-memory targets may reject or disable script work
  • 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:

  1. Configure DHT11 sensor (type: 38, pin: 13)
  2. Configure relay (type: 12, pin: 25)
  3. Create periodic acquisition rule (read DHT11 every 10 seconds)
    • Trigger: timerTrigger, intervalSec: 10
    • Action 1: sensorRead (dht_01, temperature)
  4. Create event trigger rule (temperature > 30°C)
    • Trigger: eventTrigger, eventId: ds:dht_01_temperature, operator: >, value: 30
    • Action: GPIO HIGH (relay_01)
  5. 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:

  1. Configure BH1750 light sensor (type: 38, I2C address: 0x23)
    • Or use photoresistor ADC (type: 15, pin: 34)
  2. Configure LED (type: 12, pin: 26)
  3. Periodically read illuminance (every 5 seconds)
    • Action: sensorRead (bh1750_01, illuminance)
  4. Event trigger: illuminance < 50 lux
    • Trigger: eventTrigger, eventId: ds:bh1750_01_illuminance, operator: <, value: 50
    • Action: GPIO HIGH (led_01)
  5. 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:

  1. Configure UART as Modbus RTU (type: 1, pins: TX-17, RX-16)
  2. Scan slave devices (address 1-247)
  3. Map registers to data points
    • Holding registers 40001-40002: temperature
    • Holding registers 40003-40004: humidity
  4. Create polling rule (every 10 seconds)
    • Trigger: pollTrigger, read holding registers
    • Action: parse data, write to sensor_cache
  5. 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:

  1. Configure DHT11 sensor (type: 38)
  2. Configure OLED display (type: 36, I2C address: 0x3C)
  3. Periodically read sensor data (every 2 seconds)
    • Action 1: sensorRead (dht_01, temperature)
    • Action 2: sensorRead (dht_01, humidity)
  4. Display action output
    • Action 3: displayOLED, show "Temp: 28.5°C"
    • Action 4: displayOLED, show "Humidity: 65%"
  5. 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:

  1. Configure button (type: 13, GPIO_DIGITAL_INPUT_PULLUP, pin: 0)
  2. Configure LED (type: 12, pin: 26)
  3. Create event trigger rule (button press)
    • Trigger: eventTrigger, eventId: button:btn_01:click
    • Action: toggle LED state (HIGH/LOW)
  4. Create long-press rule
    • Trigger: eventTrigger, eventId: button:btn_01:long_press
    • Action: toggle mode (auto/manual)

Reference: 06-button-control.md

Scenario 6: Overcurrent Protection ​

Requirement: Auto power-off and alarm when current exceeds 15A

Steps:

  1. Configure ACS712 current sensor ADC (type: 15, pin: 34)
  2. Configure relay (type: 12, pin: 25)
  3. Periodically read current value (every 1 second)
    • Action: sensorRead (current_01, current)
    • Advanced params: sensitivity, zeroOffset, vRef, adcMax
  4. Event trigger: current > 15
    • Action 1: GPIO LOW (turn off relay)
    • Action 2: triggerEvent, report over_current event
    • Action 3: MQTT report alarm message

Reference: 13-adc-voltage.md

Peripheral Type Quick Reference ​

Type ValueType NameDescription
1UARTSerial / Modbus RTU
11GPIO_DIGITAL_INPUTDigital input
12GPIO_DIGITAL_OUTPUTDigital output
13GPIO_DIGITAL_INPUT_PULLUPPull-up input (button)
15GPIO_ANALOG_INPUTADC analog input
17GPIO_PWM_OUTPUTPWM output
18GPIO_INTERRUPT_RISINGRising edge interrupt
19GPIO_INTERRUPT_FALLINGFalling edge interrupt
20GPIO_INTERRUPT_CHANGEDual-edge interrupt
21GPIO_TOUCHTouch input
36LCDDisplay (currently supports SSD1306/SH1106, LCD1602 TBD)
37SDIOSD card interface config placeholder
38SENSORSensor (DHT/DS18B20/BMP280 etc.)
41PWM_SERVOServo
42STEPPER_MOTORStepper motor
43ENCODERRotary encoder
44ONE_WIREOne-wire bus (DS18B20)
45NEO_PIXELWS2812B RGB LED strip
47SEVEN_SEGMENT_TM1637TM1637 seven-segment display
48RF_MODULE433MHz RF transmit/receive level
49RADAR_SENSORRCWL-0516 / 5.8GHz radar sensor

Firmware Compatibility ​

MarkMeaning
Release environmentsSupported according to compile state, runtime feature switch, memory budget and chip pin constraints
Feature-dependentCheck compile support, runtime switch, memory budget and chip-specific overrides

FastBee | fastbee.cn