The Piezoelectric Sensing Principle

When mechanical stress is applied to non-centrosymmetric crystals like lead zirconate titanate (PZT) ceramics, the internal dipole moments shift, generating a surface charge. This is the direct piezoelectric effect. In a standard brass-backed piezo disc, bending the composite structure strains the ceramic layer, producing a voltage spike proportional to the rate and magnitude of the physical deflection.

Because the sensor acts as a high-impedance capacitive voltage source (typically 10nF to 30nF for hobbyist discs), it cannot drive low-impedance loads directly. It generates high-voltage, low-current transients—easily exceeding 50V on a hard tap—meaning a direct connection to a 3.3V microcontroller GPIO or ADC will instantly fry the silicon without proper signal conditioning and voltage clamping.

Passive vs. Active: What the Output Actually Is

A common mistake in embedded forums is conflating raw piezo elements with active knock sensor modules. They output fundamentally different signals and require entirely different wiring topologies.

  • Passive Piezo Disc (e.g., Murata 7BB-27-4L0): Outputs a raw, high-impedance analog voltage spike. It requires no external power supply, but it generates its own voltage which must be scaled down and bled off via a parallel resistor before hitting an ADC pin.
  • Active Knock Module (e.g., KY-031): Outputs a digital logic level (HIGH/LOW). It contains an LM393 comparator and a potentiometer. It requires a 3.3V or 5V supply and simply trips a digital GPIO when an impact exceeds the potentiometer's threshold. It provides zero data about impact intensity.
Callout Tip: If your project requires measuring how hard a surface was struck (e.g., an electronic drum pad or a structural vibration monitor), you must use a passive analog disc. If you only need to know if a surface was struck (e.g., a secret knock door lock), an active digital module is sufficient.

Wiring, Pinout, and the Critical 1MΩ Bleed Resistor

Below is the wiring specification for interfacing both types to a 3.3V microcontroller like the ESP32 DevKit V1.

ParameterPassive Disc (Murata 7BB-27-4L0)Active Module (KY-031)
Supply RangeNone (Generates own signal)3.3V to 5.5V DC
Output TypeAnalog Voltage (0V - 50V+ transient)Digital Logic (0V or 3.3V/5V)
Signal PinRed wire to ADC (e.g., GPIO 34)DO (Digital Out) to GPIO
Ground PinBlack wire to GNDGND to GND
Conditioning1MΩ resistor in parallel + 3.3V ZenerNone (built-in comparator)

Numbered Steps: Wiring the Passive Analog Disc to ESP32

  1. Solder the Bleed Resistor: Solder a 1MΩ (1,000,000 ohm) resistor directly across the red and black wires of the piezo disc. This provides a discharge path for the piezoelectric charge, preventing dielectric absorption—where the sensor's internal insulation slowly releases trapped charge after an impact, causing ghost readings.
  2. Add Overvoltage Protection: Solder a 3.3V Zener diode (e.g., BZX55C3V3) in parallel with the resistor, with the cathode (stripe) facing the red wire. This clamps the 50V+ transients down to a safe 3.3V.
  3. Connect to ADC: Connect the red wire to an ADC1 pin on the ESP32 (GPIO 32 through 39). Avoid ADC2 pins (GPIO 0, 2, 4, 12-15, 25-27) as they are disabled when WiFi is active.
  4. Connect Ground: Connect the black wire to the ESP32 GND pin.

Output Signal Math: Raw ADC to Voltage

The ESP32 features a 12-bit Successive Approximation Register (SAR) ADC, yielding raw integer readings from 0 to 4095. The physical unit we are extracting is Voltage (V), which serves as our proxy for relative impact intensity.

While piezo elements are technically force sensors, converting Volts to Newtons (N) requires a factory-calibrated charge amplifier and a known-mass drop jig. For embedded DIY, we treat Peak Transient Voltage as our physical unit.

The baseline mathematical conversion from raw ADC to Voltage is:

Voltage = Raw_ADC × (3.3 / 4095)

However, the ESP32's ADC is notoriously non-linear at the extremes of its range (below 0.1V and above 3.0V). To get accurate physical voltage readings, use the modern ESP-IDF or Arduino-ESP32 core function analogReadMilliVolts(), which applies Espressif's factory-stored eFuse calibration data to correct the curve. According to the Espressif ADC Oneshot Documentation, this function returns millivolts directly, bypassing manual scaling errors.

Math Example:
If a tap on the disc yields a raw reading of 1450 via analogRead(), the naive math is 1450 × (3.3 / 4095) = 1.16V. Using analogReadMilliVolts() might return 1120mV (1.12V) due to internal calibration offsets. Always use the calibrated millivolt function for physical unit extraction.

Interference, Calibration, and Signal Conditioning

Piezo discs are essentially high-impedance capacitor microphones. Because of their high output impedance, they are highly susceptible to environmental noise. Here are the three most common interference sources and how to eliminate them:

  1. 60Hz Mains Hum and EMI: The disc and its wires act as an antenna for electromagnetic interference. Fix: Keep the wire leads between the piezo disc and the microcontroller under 3 inches. If you must run longer distances, use Shielded Twisted Pair (STP) cable and tie the shield to ground at the microcontroller end only to prevent ground loops.
  2. Acoustic Table Coupling: Piezo sensors will pick up vibrations from the desk or enclosure they are mounted to, triggering false positives. Fix: Decouple the sensor using a soft mounting medium. Hot glue or a thin layer of RTV silicone between the brass backing and the mounting surface acts as a mechanical low-pass filter, dampening high-frequency ambient chatter while allowing direct, localized impacts to pass through.
  3. RC Decay Calibration: The 1MΩ bleed resistor and the piezo's internal capacitance (approx. 15nF) form an RC low-pass filter. The time constant ($\tau = R \times C$) is $1,000,000 \times 0.000000015 = 0.015$ seconds (15ms). This means the voltage spike decays to 37% of its peak in 15ms. If your impacts are rapid (like drum rolls), drop the resistor to 100kΩ to speed up the decay, but expect a lower peak voltage amplitude.
Advanced Signal Conditioning: For industrial or high-fidelity audio applications where the 1MΩ resistor loads the sensor too heavily and kills low-frequency response, replace the resistor with an op-amp configured as a charge amplifier (e.g., using an OPA129 or TL072 with a 100pF feedback capacitor). This converts the high-impedance charge output into a low-impedance voltage output with minimal signal loss.

Decision Tree: Which Piezo Sensor to Buy

Use this decision path to select the exact component for your workbench. Do not waste time trying to force a digital switch to do an analog measurement job.

Project RequirementIf True...If False...
Do you need to measure impact intensity (soft vs. hard tap)?Proceed to Row 2.Buy a KY-031 Active Knock Module ($1.50 / 5-pack). Wire DO to GPIO. Done.
Is the impact frequency high (e.g., drum pad, >5 hits/sec)?Use a 100kΩ bleed resistor to speed up RC decay.Use the standard 1MΩ bleed resistor for maximum voltage sensitivity.
Do you need to measure absolute force in Newtons?Stop. Buy a dedicated FSR or load cell. Piezos only measure dynamic changes (AC), not static weight (DC).Proceed to final selection.

Final Recommendation: For 95% of embedded analog impact-sensing projects, buy the Murata 7BB-27-4L0 (approx. $2.50 each at Mouser or DigiKey). It is a 27mm diameter, 0.2mm thick PZT disc with pre-attached 28AWG leads. It offers the best balance of capacitance, mechanical durability, and voltage output for 3.3V microcontrollers. Pair it with a 1MΩ carbon film resistor and a BZX55C3V3 Zener diode, and you will have a robust, repeatable impact sensor that will not brick your ESP32.