Piezo

A piezoelectric sensor converts mechanical stress into electrical signals using piezoelectric materials like quartz or ceramics. When pressure or vibration is applied, these materials generate a voltage proportional to the force. Widely used in applications such as accelerometers, microphones, and pressure sensors, piezoelectric sensors offer high sensitivity, fast response and durability.

Piezoelectric disc
Fig.: Piezoelectric disc

Applications

Technical Specifications

Disc Material Brass
Piezoceramic Material PZT (Lead Zirconate Titanate)
Resonant Frequency ~4.3 kHz
Capacitance ~20–30 nF
Operating Voltage ±5 V (output)
Operating Temperature -20°C to +70°C
Max Vibration Acceleration ~100 g
Output Type AC voltage (requires amplification for microcontrollers)

📄 Piezo element datasheet (90 kB)

Functionality and safety precautions

A piezo sensor generates a voltage when mechanically deformed, which can be up to 30 V or more. This could easily damage the connected microcontroller, since it only tolerates 5V or 3.3V. To limit those voltage spikes a 1MΩ resistor is placed in parallel between Cathode and Anode of the piezo disc. This helps protecting the microcontroller by dissipating excess voltage. Additionally a 5V (or 3.3V) Zener diode can also be placed parallel with the resistor to prevent voltage spikes above 5V (resp.: 3.3V).
The sensitivity of the piezo sensor can be adjusted by selecting different resistor values (~1MΩ to 10MΩ). A smaller resistor decreases sensitivity.

Mount the piezo sensor mechanically to avoid false readings due to loose connections.

Prevent strong mechanical shocks that could generate excessive voltages.

Used Components

Connections

Terminal diagram of a Piezoelectric disc
Fig.: Terminal diagram of a Piezoelectric disc
Connection Polarity
Inner electrode (PZT ceramic side) Anode (+)
Outer electrode (metal/brass side) Cathode (−), GND

Setup & Programming

Arduino

Circuit diagram for connecting a Piezoelectric disc with the Arduino Uno
Fig.: Circuit diagram for connecting a Piezoelectric disc with the Arduino Uno
#define PIN_PIEZO A0

void setup() {
    pinMode(PIN_PIEZO, INPUT);
    Serial.begin(9600);
}

void loop() {
    int sensorValue = analogRead(PIN_PIEZO);
    Serial.println(sensorValue);
    delay(25);
}

Arduino with Interrupts

Another way to interface a piezo sensor with an Arduino is by using an interrupt. However, this method can only detect a binary signal - that is, whether the piezo was triggered or not - but not how strongly it was pressed.

#define PIN_PIEZO 2
#define CUSTOM_DELAY 1000

#define lmillis() ((long)millis())

volatile int pressedSum = 0;
long lastAction;

void setup() {
    Serial.begin(9600);
    attachInterrupt(digitalPinToInterrupt(PIN_PIEZO), handlePiezo, RISING);
    lastAction = lmillis() + CUSTOM_DELAY;
}

void loop() {
    if (lmillis() - lastAction >= 0) {
        lastAction = lmillis() + CUSTOM_DELAY;
        Serial.println("Pressed on piezo: " + String(pressedSum) + " times");
    }
}

void handlePiezo() {
    pressedSum++;
}

ESP32

Circuit diagram for connecting a Piezoelectric disc with the ESP32
Fig.: Circuit diagram for connecting a Piezoelectric disc with the ESP32
#define PIN_PIEZO 13

void setup() {
	pinMode(PIN_PIEZO, INPUT);
	Serial.begin(9600);
}

void loop() {
	int sensorValue = analogRead(PIN_PIEZO);
	Serial.println(sensorValue);
	delay(25);
}

Testing

After connecting the components and uploading the code to the microcontroller, you can gently tap the piezo disc. Upon opening the serial console or plotter, you should see that the input values change depending on the pressure you apply.

Output of the measured values with the serial plotter of the Arduino IDE.
Fig.: Output of the measured values with the serial plotter of the Arduino IDE.
Last edited by Christian Grieger on 2025-05-12
X
  1. [top]
  2. Applications
  3. Technical Specifications
  4. Functionality and safety precautions
  5. Used Components
  6. Connections
  7. Setup & Programming
  8. Testing