Skip to content

Example 13: ADC Analog-to-Digital Conversion ​

Experiment Overview ​

Read analog voltage values via ADC (Analog-to-Digital Converter), converting 0~3.3V analog signals to digital values. ESP32 has two ADC modules (ADC1: 8 channels, ADC2: 10 channels), with resolution up to 12 bits (0~4095).

Hardware Wiring ​

Board LabelGPIO PinConnected Device
ADCGPIO34Potentiometer/Analog sensor output
ADCGPIO36Analog signal input

GPIO34-39 are input-only pins, best suited for ADC acquisition. ADC2 is unavailable when WiFi is active.

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "adc_01",
      "name": "ADC Analog Input",
      "type": 15,
      "enabled": false,
      "pins": [34],
      "params": {}
    }
  ]
}

You can also use a dedicated ADC type for more precise configuration:

json
{
  "id": "adc_precise",
  "name": "ADC Precision Acquisition",
  "type": 26,
  "enabled": false,
  "pins": [36],
  "params": {
    "attenuation": 3,
    "resolution": 12,
    "sampleRate": 0
  }
}

ADC Attenuation Parameters ​

attenuationRangePrecision
00~1.1VHighest
10~1.5VHigh
20~2.2VMedium
30~3.3VLower

Peripheral Execution Linkage ​

Scenario: Voltage Monitoring Alarm (Poll Trigger) ​

Function: Detect ADC voltage every second, trigger buzzer alarm when voltage exceeds threshold (3000mV)

Web Interface Configuration Steps ​

Step 1: Ensure buzzer peripheral is configured

  • Peripheral ID: buzzer_gpio
  • Type: GPIO Output

Step 2: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Over-Voltage Alarm
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 3: Configure Trigger (Poll Trigger)

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Poll TriggerPeriodically detect condition
    Target PeripheralSelect adc_01ADC analog input
    Poll Interval10001000ms = 1 second
    Condition Expressionvalue > 3000Voltage greater than 3000mV

Step 4: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select HIGH Level
    • Target Peripheral: Select buzzer_gpio
  3. Click Save button

Execution Flow:

Poll every 1 second
  ↓
Read ADC value (0-4095)
  ↓
Check: value > 3000?
  ↓ Yes
Buzzer alarm

ADC Attenuation Parameter Reference ​

attenuationRangePrecisionUse Case
00~1.1VHighestPrecision small voltage measurement
10~1.5VHighSmall voltage measurement
20~2.2VMediumMedium voltage measurement
30~3.3VLowerFull range measurement (default)

Notes ​

  1. ADC2 Limitation: ADC2 (GPIO0,2,4,12-15,25-27) is unavailable when WiFi is enabled
  2. Input Range: Exceeding 3.3V will damage the pin, voltage divider circuit needed
  3. Precision: ESP32 ADC has non-linear errors, calibration needed for precise measurements
  4. Input Impedance: ADC input impedance is high, but source impedance should not exceed 10kΩ
  5. Sample Rate: Default single sample, sampleRate=0 means read on demand

FastBee | fastbee.cn