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:
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.