Piezo wrong default value

I'm trying to use Piezo following the project book.
If I connect only my Piezo to Analog Read throug a 1M resistor (like book says) and other to the ground my Piezo work correctly and i have in output (Serial.printiln(analogRead(A0)) 0/1/2 if there isn't noise.
But if I also connect another component for example a Led default value of Piezo without noise is 30/40.
What is the cause of this?
Thanks :slight_smile:

What project book. I'm sure there are many.

You don't usually connect a piezo THROUGH (in series with) a 1meg resistor.
The resistor goes ACROSS the piezo.

A circuit with 1Megohm impedance picks up hash very easilly.
The wiring has to be short or shielded.

How do you supply the Arduino.
With e.g. a 9volt battery, the supply could dip under the load of a LED.
That will influence piezo readings.

Are you building a "knock sensor".
Try entering that in the search box on top of this page.

If you want detailed help, post your circuit and your code (inside code tags).
Leo..

My code is very easy i just print out the value.

const int piezo=A0;

void setup() {
  Serial.begin(9600);

}

void loop() {
  Serial.println(analogRead(piezo));
  delay(100);

}

Also the circuit is very easy.

http://postimg.org/image/g1hzfld03/

Seems strange that the piezo is connected between A0 and 5volt.
And the load resistor between A0 and ground.
Are you sure that's in the project book.

I would expect the piezo also connected between A0 and ground.
Connected to the supply makes it dependent of supply variations.

Try connecting the piezo between A0 and ground, and report back.
Leo..

Hi, i'm sure that the project book say to connect the cuircuit like I have done.
I've tried as you sayid connecting the piezo between A0 and the gournd with 1M resistor but it doesn't work.
Now I have without noise values like 700, and with a lot variation.
Thanks.

You must be doing something wrong.
I wired it up as explained in post#3.
Resistor from A0 to ground, and piezo from A0 to ground.
It gives me a constant stream of zeroes, untill I tap the bench where the piezo is lying on.

It misses some taps, because of the 100msec delay in the code.
Try this.

const int piezo = A0; // piezo pin
int rawValue = 0; // holds A/D reading

void setup() {
  Serial.begin(9600);
}

void loop() {
  rawValue = analogRead(piezo); // read pin
  if (rawValue > 0) { // if a knock is detected
    Serial.println(rawValue); // print the value
    delay(10); // not toooo many values
  }
}

Leo..

Can you upload the picture of your circuit?
Thanks!

isky:
Can you upload the picture of your circuit?
Thanks!

:slight_smile: No "circuit".
I just soldered a 1Meg resistor to a bare piezo disk.
And soldered two wires to the "circuit".
Poked the other end of the wires into A0 and ground of an UNO.
The picture you uploaded.
Just change the orange link from + to ground.
Check if the piezo is making contact, and is plugged into the right strips.
Upload another picture if you're not sure.
Leo..

Yeah, now it seems to work right. But i don't understand why.
Why we don't connect piezo to + ?
And specially why the project book sayid to connect to +?
Thank you so much!