intermediateChapter 36 of 4530 min

36. Piezo Sensor

Use analog input to read the piezo sensor; outcome: serial shows the vibration value (0–1023); a tap makes it jump.

This lesson uses: Arduino UNO R3 board, TinkerBlock TK59 Piezo-Ceramic Sensor module, jumper wires (or breadboard). Use analog input to read the piezo sensor; outcome: serial shows the vibration value (0–1023); a tap makes it jump.

1. Wiring

Connect TK59 Piezo-Ceramic Sensor to Arduino:

  • GND → Arduino GND
  • SIGNAL → Arduino A0
  • The two NC pins stay unconnected. The block has no VCC pin: the disc makes its own voltage, and the pad printed VCC beside the disc is its red lead, not a supply.

TK59 wiring diagram

2. New sketch

  1. Arduino IDE: File → New (or Ctrl/Cmd + N) to create a blank sketch
  2. Confirm board and port are selected (same as Lesson 01)
  3. Type the code below into the default setup() and loop() yourself

3. Program structure

Same as last lesson: two fixed blocks setup() and loop().

  • setup(): Start serial; runs once.
  • loop(): Keep repeating “read analog value → print to serial → wait → repeat”.

Tap the piezo and the serial value will jump—upload and try.

4. Code to write

Type the code below into setup() and loop() (do not copy-paste; typing it yourself helps you remember):

lesson36.ino
// Piezo sensor on A0; pressure/vibration changes output voltage, ADC 0-1023
#define PIEZO_PIN A0

void setup() {
  Serial.begin(9600);
  Serial.println("Piezo sensor program started");
}

void loop() {
  int val = analogRead(PIEZO_PIN);   // Read A0; more pressure/vibration = higher value
  Serial.print("Pressure: ");
  Serial.println(val);
  delay(100);   // Poll every 100 ms
}
View on GitHub · workshop/36-piezo-sensor/arduino/lesson36/lesson36.ino @ v1.13

Program notes

Overall idea: The disc makes a voltage when it is bent, and only while it is changing: a 1 MΩ resistor drains it, so a steady press reads close to 0. A0 reads it; a harder tap gives a higher value. This lesson only prints the raw value; you can use it for thresholds or simple strength comparison.

CodeIn this lesson
analogRead(PIEZO_PIN)Read A0, 0–1023; a harder tap reads higher

5. Hands-on

  1. After entering the code, click Verify (✓) to compile
  2. Click Upload (→) to upload to the board
  3. Open Serial Monitor (Tools → Serial Monitor, baud 9600)
  4. Watch serial: close to 0 at rest
  5. Tap the sensor and see the value jump

Expected result:

Serial monitor:

Piezo sensor program started
Pressure: 0
Pressure: 0
Pressure: 368
...

A tap makes the value jump, then it falls back. A reading every 100 ms catches only part of a tap, so the same tap can read high one time and low the next; the TK59 handbook samples fast enough to catch the peak.

Piezo sensor effect

Note: TK96 Mechanical Key LED is different (key + LED); you can try it.

Proceed to Lesson 37.

Edit this page — content/guides/tinkerblock-workshop/36-piezo-sensor.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Piezo-Ceramic Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Projects and guides on the forum →