GPIO Digital Input
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
| Type | type Value | Description |
|---|---|---|
| GPIO_DIGITAL_INPUT | 11 | Floating input |
| GPIO_DIGITAL_INPUT_PULLUP | 13 | Internal pull-up input |
| GPIO_DIGITAL_INPUT_PULLDOWN | 14 | Internal pull-down input |
| GPIO_INTERRUPT_RISING | 18 | Rising edge interrupt |
| GPIO_INTERRUPT_FALLING | 19 | Falling edge interrupt |
| GPIO_INTERRUPT_CHANGE | 20 | Level change interrupt |
| GPIO_TOUCH | 21 | Touch input |
Button Event Detection
Only PULLUP(13) and PULLDOWN(14) types support built-in button event detection:
| Event | eventId | Description |
|---|---|---|
| Single Click | button_click | Short press and release |
| Double Click | button_double_click | Two consecutive short presses |
| Long Press 2s | button_long_press_2s | Hold for 2 seconds |
| Long Press 5s | button_long_press_5s | Hold for 5 seconds |
| Long Press 10s | button_long_press_10s | Hold for 10 seconds |
| Press | button_press | Moment of button press |
| Release | button_release | Moment 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
| Application | Type | Wiring |
|---|---|---|
| Button | PULLUP(13) | One end to GPIO, other end to GND |
| IR Obstacle Avoidance | PULLUP(13) | DO → GPIO (low level when obstacle detected) |
| PIR Motion Sensor | PULLDOWN(14) | OUT → GPIO (high level when motion detected) |
| Reed Switch | PULLUP(13) | Signal pin → GPIO |
| Beam Photoelectric | PULLUP(13) | DO → GPIO |
Configuration
Method 1: Web Interface Configuration (Recommended)
For GPIO input peripherals, verify input mode, pin number, and whether pull-up/pull-down is needed.
Step 1: Navigate to Peripheral Management Page
- Open a browser and navigate to the ESP32 IP address
- After logging in, click Peripheral Configuration in the left menu
Step 2: Add GPIO Digital Input Peripheral
Click the Add Peripheral button
Fill in the configuration:
Field Value Description Peripheral ID btn1orpir1Unique identifier Name Function ButtonorPIR Motion DetectionDisplay name Peripheral Type GPIO Digital Input Pull-up (type: 13) Recommended for buttons Pin Configuration 0or27Fill according to actual wiring Click Save
Step 3: Verify Configuration
- Find the newly added peripheral in the peripheral list
- Click the Enable toggle
- 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)
{
"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)
{
"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)
{
"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:
{
"triggerType": 0,
"triggerPeriphId": "btn1",
"operatorType": 0,
"compareValue": "0"
}As Event Trigger Source
Button events can directly trigger peripheral execution rules:
{
"triggerType": 4,
"triggerPeriphId": "btn1",
"eventId": "button_click"
}When
triggerPeriphIdis empty, the corresponding event from any button will trigger the rule.
Web Interface Configuration Steps
Create Event Trigger Rule
- Switch to the Peripheral Execution Management tab
- Click the Add Rule button
- Configure event trigger:
- Trigger Type: Event Trigger
- Event Source: btn1
- Event Type: button_click (single click)
- Add action (e.g., control LED or relay)
- Click Save
Notes
- Pull-up/Pull-down Selection: Buttons typically use pull-up (press connects to GND); active sensors like PIR are selected based on output polarity
- Debounce Handling: System has built-in software debounce (~50ms), no external debounce circuit needed
- Interrupt Pins: All ESP32 GPIOs can configure interrupts, but avoid time-consuming operations in interrupt callbacks
- Touch Pins: ESP32 only GPIO 0/2/4/12/13/14/15/27/32/33 support TOUCH function
- GPIO34-39: ESP32 GPIO 34-39 only support input, no internal pull-up/pull-down
