How to – Piezo as knock sensor

Hello everyone, in this post we are going to learn how to work with a piezo, that is a device that virbates when it receives electricity: when it moves, it displaces air around it, creating sound waves. However, it is even more interesting to learn how it is possibile to use the same device as a sensor to catch, for example, a knock. For this reason, it is also called knock sensor.


This device exploit the so-called piezoeletctric effect: it means that it is able to create a variable voltage when it is deformed.

Piezoelectric effect

Emitting sound waves

First of all, let me explain how it is possible to emit sound waves. Modifying the voltage on the piezo, we can control sound waves’s frequency.

The circuit is really simply: you have just to link the piezo to the ground and to a digital pin on the Arduino.

This is the sketch: it uses the function  tone() in order to emit sound waves of fixed frequency (in this particular case 1500) for a certain period (in this case 2 seconds). The piezo has been linked to the digital pin 8: if you want to change pin, you also have to modify the value of piezoPin constant with the correct value.

Knock sensor

But, as I said, the piezo can be used also as a sensor. The circuit is a bit different:

Knock sensor scheme

The only difference is the presence of a 1 MegaOhm resistence. Pay attention: now the sensor is connected to an analogic pin (A0).

This is the sketch: every time that the sensor catch a knock, the string “Knock!” is sent through the serial port. In order to avoid to take little movement as knocks, it only considers values greater than the treshold of 100. Just a tip: do not knock directly on the sensor: cover it with an other surface.

Stay tuned!



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )


Connessione a %s...