Sooo im trying to make a simple program that prints "touched!" when a piezoelectric sensor is touched.
Maybe I don't understand how they work or something, but I'm looking at the serial monitor that is printing the input value of the piezo, and the numbers don't make sense. It just climbs from 0 -1000 and goes back to zero whenever I touch it.
The piezo is connected to an analog pin on the arduino. The circut couldn't get more simpler, the piezo is simply connected to ground through the ground pin and the positive is connected to the A0 pin.
When the piezo isn't being touched, the analog pin is essentially seeing an open circuit. It's floating. So you need to provide a relatively low resistrance to ground so that the voltage on the pin is a known value. Try 10K and work your way down.
And when the piezo is being touched, do you think that maybe it could generate a voltage higher than 5V? If it does, what do you think that might do to your analog input pin?
Or higher... Higher impedance will "allow" higher voltage, but you need SOMETHING to pull the input down to zero when there is no signal. The output is unknown, especially since the force/movement/vibration is unknown.
For sound pick-up (through the air like a microphone), 1M or 10M is often used, but the signal still might be too low for the Arduino (without amplification).
Usually, the Piezo can't put-out enough current to damage the Arduino and the little built-in protection diodes will "clamp" the voltage between a little more than Vcc, and slightly negative.
The Piezo only puts-out a voltage ONLY WHILE it's moving or vibrating. Your program only reads for an instant, once every time through the loop. It's hard to "catch" the peak voltage, especially during the delay when the code isn't doing anything, and also during the print statement. Even without the delay & printing, it's still not continuously reading.
And, the Piezo puts-out positive voltage when flexed one way and negative voltage when flexed the other. If it's "vibrating", half of the time it will be negative and since the Arduino can't read negative voltages, half of the readings will be zero.
That is the expected result. When pressed, the piezo generates a short voltage pulse, which charges up the capacitance in the circuit. The charge then very slowly drains away through the extremely high resistance of the input pin.