Back to Sensors & Actuators Series

Knock Sensor: Piezoelectric Engine Detonation

April 10, 2026 Wasil Zafar 8 min read

Knock sensor deep dive — piezoelectric vibration detection, knock frequency analysis, Arduino code, and ECU engine management applications.

Contents

  1. Working Principle
  2. Electrical Characteristics
  3. Interfacing with MCU
  4. Calibration
  5. Code Example
  6. Real-World Applications
  7. Limitations

Working Principle

A knock sensor is a piezoelectric accelerometer tuned to detect the characteristic vibration frequency of engine knock (detonation). Engine knock occurs when the air-fuel mixture auto-ignites ahead of the spark-initiated flame front, creating destructive pressure waves in the combustion chamber at 5–15 kHz. The knock sensor contains a piezoelectric ceramic element (usually PZT) that generates a voltage when mechanically stressed by these vibrations.

The ECU monitors the knock sensor output, comparing the signal amplitude during the “knock window” (a specific crank angle range near TDC) against a threshold. If knock is detected, the ECU retards ignition timing to prevent engine damage.

Electrical Characteristics

ParameterTypical (Bosch 0 261 231 120)
TypeResonant piezoelectric accelerometer
Resonant Frequency~7 kHz (tuned for engine knock band)
Bandwidth5–15 kHz (knock-relevant range)
Sensitivity~25 mV/g at resonance
OutputAC voltage (0–5 V peak, proportional to vibration)
Impedance>1 MΩ (high impedance, capacitive source)
MountingBolt-on (M8) to engine block
Operating Temperature−40 to +150 °C

Interfacing with an MCU

The knock sensor output is a high-impedance AC signal. Use a bandpass filter (centre frequency ~7 kHz, bandwidth ~5 kHz) followed by a peak-detect and rectify circuit (or an envelope detector) to produce a DC level proportional to knock intensity. Feed this to an ADC. Professional ECUs use a dedicated knock IC (e.g., TI TPIC8101) that handles filtering, integration, and windowed gain.

Knock window: Only analyse the sensor signal during the crank angle window where knock can occur (typically 10° before TDC to 70° after TDC on the combustion stroke). Signals outside this window are mechanical noise from valve train, injectors, and accessories.

Calibration

  • Background noise floor: Measure the sensor output at various RPM levels with no knock; this sets the adaptive threshold baseline
  • Knock threshold: Typically 2–3× the background level at a given RPM; too sensitive = false retard, too insensitive = missed knock
  • Torque verification: The mounting bolt must be tightened to the specified torque (typically 20 Nm); incorrect torque changes the sensor’s coupling to the block
  • Induced knock test: Advance timing aggressively on a dyno to induce controlled knock and verify the system detects and retards correctly

Code Example

/*
 * Knock Sensor — Basic Detection (Arduino)
 * Wiring: Sensor signal through bandpass filter + envelope
 *         detector → A0 (0-5V DC proportional to knock)
 * NOTE: Real ECU systems use dedicated knock ICs (TPIC8101)
 */
#define KNOCK_PIN A0
#define THRESHOLD 200  /* ADC counts — tune per engine */

int background = 0;

void setup() {
    Serial.begin(115200);  /* Fast baud for real-time */
    Serial.println("Knock Sensor Ready — warming up engine...");

    /* Establish background noise level at idle */
    long sum = 0;
    for (int i = 0; i < 100; i++) {
        sum += analogRead(KNOCK_PIN);
        delay(10);
    }
    background = sum / 100;
    Serial.print("Background ADC: ");
    Serial.println(background);
}

void loop() {
    int raw = analogRead(KNOCK_PIN);
    int delta = raw - background;

    if (delta > THRESHOLD) {
        Serial.print("** KNOCK DETECTED ** Level: ");
        Serial.print(delta);
        Serial.println("  Action: retard timing 2-3 deg");
    }

    /* Update adaptive background (slow filter) */
    background = (background * 99 + raw) / 100;
    delay(1);  /* Fast sampling for knock detection */
}

Real-World Applications

ECU Engine Management & Performance Tuning

Knock sensors are mandatory in every modern spark-ignition engine for closed-loop knock control. They enable ECUs to run more aggressive timing maps (closer to the knock limit for maximum performance) while protecting the engine. Aftermarket ECUs (MegaSquirt, Haltech, Link) use knock audio channels for tuning. Knock sensors also find use in industrial machinery vibration monitoring and structural health monitoring (adapted for different frequency bands).

ECUEngine TuningOBD-IIVibration

Limitations

  • Signal processing complexity: Raw output contains valve train, injector, and accessory noise; sophisticated filtering is mandatory.
  • RPM-dependent noise: Background level changes with RPM; requires adaptive thresholding.
  • Mounting critical: Incorrect bolt torque or wrong location on the block dramatically reduces sensitivity.
  • Single frequency tuning: Resonant sensors are sensitive to a narrow band; knock frequency shifts with cylinder bore size.