Go Down

Topic: Piezo Sensor malfunctioning? (Read 973 times) previous topic - next topic

Swoosh88

Hi,
I've got this piezo sensor which isn't working properly... It keeps sending out a signal of 15... Which doesnt change when I tap it.
I'm not sure if this will influence the results, but I am using a ScrewShield to connect the raw wires from the Piezo to the Arduino. All the pins are intact and all that, so it should work.
What could I be doing wrong here?

This is my setup:


I used this script:
Code: [Select]
// these constants won't change:
const int ledPin = 13;      // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100;  // threshold value to decide when the detected sound is a knock or not


// these variables will change:
int sensorReading = 0;      // variable to store the value read from the sensor pin
int ledState = LOW;         // variable used to store the last LED status, to toggle the light

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600);       // use the serial port
}

void loop() {
  // read the sensor and store it in the variable sensorReading:
  sensorReading = analogRead(knockSensor);   

  // if the sensor reading is greater than the threshold:
  if (sensorReading >= threshold) {
    // toggle the status of the ledPin:
    ledState = !ledState; 
    // update the LED pin itself:       
    digitalWrite(ledPin, ledState);
    // send the string "Knock!" back to the computer, followed by newline
    Serial.println("Knock!");       
  }
  delay(100);  // delay to avoid overloading the serial port buffer
}

johnwasser

Could it be that what you have ie a piezo beeper with a built-in oscillator and not a raw piezo element?  Is the disk in a plastic case (as your diagram shows) or out in the open with two wires?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Swoosh88

Well, actually, I bought 3 types, to test them out:
1- The one with a plastic case
2- A flat piece
3- A flat piece with a thin edge around it

Number 1 and 2 both didn't work.
I tested them seperatly. (on the same Arduino board)

Swoosh88

Ok, so I made the whole setup again as shown on the picture, and added the line
Serial.println(sensorReading);
after the line
sensorReading = analogRead(knockSensor);

which keeps showing me:
0
0
0
0
etc.

Which isnt good, right?

Pofenas

Maybe the black wire should be connected to 5v instead of Gnd?

Swoosh88


Pofenas

Of course not!! In fact, It will feed the piezo and return the current to the analog input. Arduino's analog input is able to read any voltage between 0 and 5 volts (in general terms. There is some exceptions, but it's not the point now). Wiring the piezo to 5 volt, you ensure that analog input only may have less than 5 volts, which is absolutelly safe.

Swoosh88

So, I just tried, and it didn't work... still 0 signal...

Could it perhaps be the Arduino board itself? or perhaps the fact that I'm using a screwshield?

Swoosh88

So, today i removed the resistance from the setup, which showed the arduino is malfunctioning like hell:
It even shows a completely random stream of information when the sensor is unplugged
So ill change my arduino today, and hope the problem will be fixed

Swoosh88

As it turned out, I wasn't using the right resistor :P
I used 100kOhm instead of 1 MOhm :P
And that random signalling was just the analog noise ;)

Go Up