Pages: [1]   Go Down
Author Topic: Piezo Sensor malfunctioning?  (Read 802 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8084
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Albacete
Offline Offline
Full Member
***
Karma: 0
Posts: 140
Arduino mola que te pasas
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That won't harm the Arduino?
Logged

Albacete
Offline Offline
Full Member
***
Karma: 0
Posts: 140
Arduino mola que te pasas
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As it turned out, I wasn't using the right resistor smiley-razz
I used 100kOhm instead of 1 MOhm smiley-razz
And that random signalling was just the analog noise smiley-wink
Logged

Pages: [1]   Go Up
Jump to: