Skip to content

GPIO Digital Input ​

Overview ​

GPIO digital input is used to read buttons, switches, digital sensor signals, etc. Supports pull-up/pull-down modes; some types support interrupts and button event detection.

Supported Peripheral Types ​

Typetype ValueDescription
GPIO_DIGITAL_INPUT11Floating input
GPIO_DIGITAL_INPUT_PULLUP13Internal pull-up input
GPIO_DIGITAL_INPUT_PULLDOWN14Internal pull-down input
GPIO_INTERRUPT_RISING18Rising edge interrupt
GPIO_INTERRUPT_FALLING19Falling edge interrupt
GPIO_INTERRUPT_CHANGE20Level change interrupt
GPIO_TOUCH21Touch input

Button Event Detection ​

Only PULLUP(13) and PULLDOWN(14) types support built-in button event detection:

EventeventIdDescription
Single Clickbutton_clickShort press and release
Double Clickbutton_double_clickTwo consecutive short presses
Long Press 2sbutton_long_press_2sHold for 2 seconds
Long Press 5sbutton_long_press_5sHold for 5 seconds
Long Press 10sbutton_long_press_10sHold for 10 seconds
Pressbutton_pressMoment of button press
Releasebutton_releaseMoment of button release

For digital input troubleshooting, first check pull-up/pull-down and default levels; for buttons, door sensors, PIR modules, etc., it is recommended to first confirm events in logs before connecting to peripheral execution rules.

When event trigger is not working, first confirm whether the input generates an eventId, then check whether the rule is enabled, whether triggerPeriphId matches, and whether the action can be executed manually.

Typical Applications ​

ApplicationTypeWiring
ButtonPULLUP(13)One end to GPIO, other end to GND
IR Obstacle AvoidancePULLUP(13)DO → GPIO (low level when obstacle detected)
PIR Motion SensorPULLDOWN(14)OUT → GPIO (high level when motion detected)
Reed SwitchPULLUP(13)Signal pin → GPIO
Beam PhotoelectricPULLUP(13)DO → GPIO

Configuration ​

For GPIO input peripherals, verify input mode, pin number, and whether pull-up/pull-down is needed.

Step 1: Navigate to Peripheral Management Page ​

  1. Open a browser and navigate to the ESP32 IP address
  2. After logging in, click Peripheral Configuration in the left menu

Step 2: Add GPIO Digital Input Peripheral ​

  1. Click the Add Peripheral button

  2. Fill in the configuration:

    FieldValueDescription
    Peripheral IDbtn1 or pir1Unique identifier
    NameFunction Button or PIR Motion DetectionDisplay name
    Peripheral TypeGPIO Digital Input Pull-up (type: 13)Recommended for buttons
    Pin Configuration0 or 27Fill according to actual wiring
  3. Click Save

Step 3: Verify Configuration ​

  1. Find the newly added peripheral in the peripheral list
  2. Click the Enable toggle
  3. Check real-time status value

💡 Tip: PULLUP(13) and PULLDOWN(14) types support button event detection (single click, double click, long press)


Method 2: JSON Configuration File Import ​

Add the following configuration to the peripherals array in data/config/peripherals.json:

Button Input (Pull-up) ​

json
{
  "id": "btn1",
  "name": "Function Button",
  "type": 13,
  "enabled": false,
  "pins": [0],
  "params": {
    "initialState": 0,
    "pwmChannel": 0,
    "pwmFrequency": 1000,
    "pwmResolution": 8,
    "defaultDuty": 0
  }
}

PIR Motion Sensor (Pull-down) ​

json
{
  "id": "pir1",
  "name": "PIR Motion Detection",
  "type": 14,
  "enabled": false,
  "pins": [27],
  "params": {
    "initialState": 0,
    "pwmChannel": 0,
    "pwmFrequency": 1000,
    "pwmResolution": 8,
    "defaultDuty": 0
  }
}

Interrupt Input (Rising Edge) ​

json
{
  "id": "interrupt1",
  "name": "Count Interrupt",
  "type": 18,
  "enabled": false,
  "pins": [34],
  "params": {
    "initialState": 0,
    "pwmChannel": 0,
    "pwmFrequency": 1000,
    "pwmResolution": 8,
    "defaultDuty": 0
  }
}

Peripheral Execution Integration ​

As Platform Trigger Data Source ​

Digital input state changes are reported via MQTT and can be used as platform trigger conditions:

json
{
  "triggerType": 0,
  "triggerPeriphId": "btn1",
  "operatorType": 0,
  "compareValue": "0"
}

As Event Trigger Source ​

Button events can directly trigger peripheral execution rules:

json
{
  "triggerType": 4,
  "triggerPeriphId": "btn1",
  "eventId": "button_click"
}

When triggerPeriphId is empty, the corresponding event from any button will trigger the rule.

Web Interface Configuration Steps ​

Create Event Trigger Rule

  1. Click Peripheral Execution in the left menu
  2. Click the Add Rule button
  3. Configure event trigger:
    • Trigger Type: Event Trigger
    • Event Source: btn1
    • Event Type: button_click (single click)
  4. Add action (e.g., control LED or relay)
  5. Click Save

Notes ​

  1. Pull-up/Pull-down Selection: Buttons typically use pull-up (press connects to GND); active sensors like PIR are selected based on output polarity
  2. Debounce Handling: System has built-in software debounce (~50ms), no external debounce circuit needed
  3. Interrupt Pins: All ESP32 GPIOs can configure interrupts, but avoid time-consuming operations in interrupt callbacks
  4. Touch Pins: ESP32 only GPIO 0/2/4/12/13/14/15/27/32/33 support TOUCH function
  5. GPIO34-39: ESP32 GPIO 34-39 only support input, no internal pull-up/pull-down

FastBee | fastbee.cn