Close

Piezo sensor considerations

A project log for Nixie Tap

Minimal USB powered Nixie display and IoT button

mladenmladen 10/15/2017 at 20:560 Comments

Piezoelectric transducers are curious little devices. You can use them both ways, as a vibration source and as a vibration sensor.

In this project, piezo crystal is used as a sort of a "knock" sensor, or a microphone. It’s glued to device walls from the inside.

ESP8266 is continually polling (yeah, not too optimized) the A0 input. When device is tapped with a finger, piezo picks up the vibration, and generates a voltage spike. ESP8266 samples the voltage, and if it's over detection threshold, it considers that a tap event has occurred.

I whipped up a demo code for this feature:

    adc_reading = analogRead(A0);
    if (adc_reading > threshold)
    {
        delay(5);
        adc_reading = analogRead(A0);
        if (adc_reading > threshold)
        {
            display.write(state,state,state,state,1);
        }
    }

 The result of this quick'n'dirty code is:

As it can be observed from the video, this interface should be further optimized (skipped detection at 0 and 8). Maybe I need a transistor preamp, since handling this in code is tricky.

Discussions