Piezo sensor doesn't print the values right?

Hi everyone!

I’ve been looking around on this forum for a while now and haven’t been able to find a post similar to this and I hope I posted it in the correct place.

I have a problem with readings on a Piezo with which I really hope you could help me!

First a bit of backstory:

I’ve been working with Arduino since today and i’ve done some projects to see how sensors are hooked up and how to write a script so that you can print the values a sensor measures.

At the moment i’m trying a step further towards my end goal which is to make a sound absorbing panel that rotates with the sun but closes when there is too much noise nearby. I have it working that a panel follows the sun with a servo and 2 photoresistors. This script is attached so you guys can get a clearer picture of this all.

Now to the point:

I’ve started on the sound measuring part of the script in a different file so I can see if it correctly measures the intensity of the sound nearby. I want the panel to close when the intensity gets above a certain treshold.

To begin I copied the first script for a knock sensor here:

This was to see whether it would actually work and every now and then I got a knock and then at other times I wouldn’t so I added the Serial.print part to the code to see what was actually going on.

However there is a constant measurement of 14 and in the beginning there is no noise and then after a few seconds it starts to non stop print “Noise”. If I increase the treshold to 250 it still works the same and then at 300 it just doesn’t print anymore.

I’ve attached the file, just in case I missed something in there, and a photo of the setup as well, in case I hooked it up all wrong (which is more likely I think).

I’d like to get a reading between 0 and 1023 like with a photoresistor if possible so I can get an idea which treshold would be needed to reset the servo to 0. Then delay the script for the light sensors so the panels would remain closed for 3 seconds then read the sound again. if the sound is still above the treshold, it would remain closed for another 15 seconds.

I’d love it if you could help me with at least the readings of the sound sensor so I can work on this project further.

Many thanks in advance!

Knock.ino (562 Bytes)

Sun_follower_-_Sketch.ino (1.3 KB)

A piezo can only be used as "contact microphone".

The "knock sensor" example is poorly written. Misses knocks and is not very sensitive.

Try the sketch in post#16 here.

Yes I see that it wouldn’t work with air vibrations however I’m stuck with the basic uno arduino set which doesn’t have a microphone included. That’s also why I wanted to try and work with the Piezo component and then later replace it with a microphone.

When I made the setup and tried to read what the values were it didn’t show any. Not even when I tapped on it it said that there was no knock. How can I make it more sensitive so it does read correctly?

I’ve looked at the post you included but it doesn’t have a photo/sketch of how to hook it all up. Can you include that? That way I can try it and see if it does what I need.

Thank you for replying so fast!

I've looked at the post you included but it doesn't have a photo/sketch of how to hook it all up. Can you include that? That way I can try it and see if it does what I need.

Already explained in the comments of the sketch.

Piezo connected to A0 and ground.
1Megohm resistor (brown,black,green) also connected to A0 and ground (= across the piezo).
The buzzer is optional.
You see the knock values on the monitor.
And an onboard LED flashes once when a knock is over the threshold.