Unit G - ESP32 Foundations

37. Pinout, Strapping Pins, ADC, DAC and Touch

Learn strapping pins and 12-bit ADC, then build a trim setpoint reader that reports LOW/MID/HIGH bands.

Estimated time 3 hours

Learning outcomes

  • Explain the GPIO matrix idea at course level
  • List classic strapping pins and why they matter at boot
  • Use 12-bit analogRead (0-4095) on GPIO 34
  • Build a trim setpoint reader with voltage estimate and bands
  • State DAC and touch as awareness topics on classic ESP32

Parts and preparation

ESP32 DevKit, 10 k ohm potentiometer, breadboard, jumper wires.

Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.

Pinout, Strapping Pins, ADC, DAC and Touch instructional connection diagram

Project: Trim setpoint reader

Many products hide a trim pot for threshold, brightness or calibration. You will read a pot on GPIO 34 and turn it into a human setpoint display.

Sketch 1 proves 12-bit ADC codes. Sketch 2 is the useful reader: print raw, estimated volts, and LOW/MID/HIGH band for your trim.

ESP32 DevKit highlighting strapping pins
Respect strapping pins at boot before hard-wiring controls.

GPIO matrix idea

Many peripheral signals can route to a wide set of GPIOs - with exceptions. Trust silkscreen and Espressif notes over Uno D-numbers. Some pins are input-only; some are strapping; some serve flash on modules.

Strapping pins

At reset, classic ESP32 samples GPIO 0, 2, 12, 15 (and often 5). GPIO 0 LOW at reset often enters download mode - useful for flashing, confusing with a casual button.

Pin (classic)Course caution
GPIO 0Boot / download strap
GPIO 2Strapping; often on-board LED
GPIO 12Flash voltage select risk
GPIO 15Avoid unwanted pull at boot
GPIO 5Strapping on classic - check docs

ADC: 12-bit, attenuation and nonlinearity

12-bit codes 0-4095 with analogReadResolution(12). Finer than Uno 0-1023, but nonlinear at the ends. Power the pot from 3V3. GPIO 34 is input-only - ideal for the wiper. Treat readings as useful, not metrology-grade.

Uno 10-bit versus ESP32 12-bit ADC scales
0-4095 codes - still approximate.
ItemUno R3 defaultESP32 course default
Resolution10-bit (0-1023)12-bit (0-4095)
Course pot pinA0GPIO 34 (input-only)

DAC and touch (awareness)

Classic ESP32 DAC on GPIO 25/26; many RISC-V parts differ. touchRead exists on supported pins. This lesson's practical path is the trim pot on GPIO 34.

Wiring and safe build sequence

  1. Potentiometer outer legs -> 3V3 and GND; wiper -> GPIO 34
  2. USB to DevKit; Serial Monitor 115200
Power rule: switch off before moving wires. Arduino I/O pins are control signals; high-current loads require a driver and suitable external supply.

Worked sketch 1: Prove 12-bit ADC

Download .ino sketch

What this sketch is for: Discovery: turn the pot and watch raw codes move through roughly 0-4095.

const int potPin = 34;

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
}

void loop() {
  int raw = analogRead(potPin);
  Serial.println(raw);
  delay(200);
}

How the code works

  1. analogReadResolution(12) selects 0-4095 codes.
  2. GPIO 34 is input-only - do not digitalWrite it.
  3. Power the pot from 3V3, not 5 V.

Worked sketch 2: Trim setpoint reader

Download .ino sketch

What this sketch is for: Useful calibration tool: print raw ADC, estimated volts, and LOW/MID/HIGH band so you can set thresholds for later lamps and alerts. Match the breadboard layout below before upload.

Breadboard layout for ESP32 trim setpoint reader: potentiometer on 3V3, GND and GPIO 34
Breadboard for sketch 2: pot outer legs to 3V3 and GND; wiper to GPIO 34 (ADC1). Power the pot from 3V3, not 5 V. Click to enlarge.
const int potPin = 34;
unsigned long lastPrint = 0;

const char* band(int raw) {
  if (raw < 1200) return "LOW";
  if (raw < 2800) return "MID";
  return "HIGH";
}

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  Serial.println("Trim setpoint reader");
}

void loop() {
  if (millis() - lastPrint < 250) return;
  lastPrint = millis();

  int raw = analogRead(potPin);
  float volts = raw * (3.3f / 4095.0f);
  Serial.print("raw ");
  Serial.print(raw);
  Serial.print("  ");
  Serial.print(volts, 2);
  Serial.print(" V  ");
  Serial.println(band(raw));
}

How the code works

  1. Band thresholds are teaching defaults - retune for your pot travel.
  2. Voltage estimate assumes ~0-3.3 V full scale - ESP32 ADC is approximate.
  3. Use these bands later as alert thresholds in the Unit I capstone.
  4. Build from the breadboard photo: 3V3 and GND to pot ends; wiper to GPIO 34.

Test and record evidence

Expected result: Sketch 1: raw values move with the pot. Sketch 2: each line shows raw, volts and LOW/MID/HIGH as you trim.

Practical evidence checklist

Common faults and checks
  • Stuck mid: wiper on 34, outers on 3V3/GND.
  • Only to 1023: call analogReadResolution(12).
  • Noisy ends: expected somewhat - average if needed.
Extension challenge: Add hysteresis so the printed band does not chatter at the LOW/MID boundary.

Check your understanding

Q1. What project is sketch 2?

Show answer

A trim setpoint reader with voltage and LOW/MID/HIGH bands.

Q2. 12-bit analogRead range?

Show answer

0 to 4095.

Q3. Name two classic strapping pins

Show answer

Any two of GPIO 0, 2, 12, 15 (and 5).

Q4. Why GPIO 34 for the pot?

Show answer

Input-only ADC pin on classic ESP32.

Q5. Classic DAC pins?

Show answer

GPIO 25 and 26 on classic ESP32.

Q6. Power the pot from 5 V?

Show answer

No - use 3V3.

Q7. Why are band labels useful?

Show answer

They turn raw codes into setpoint language for later projects.