Pages: [1]   Go Down
Author Topic: Using a Piezeo Element to read analog values  (Read 278 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 126
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I am using an UNO and a piezeo element connected directly between ground and A0



The additional wires (red + orange) are only being used to hold the very small Piezeo wires in place - nothing else.

My code is

Code:

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);  
  
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = 1023-analogRead(sensorPin);    
  // turn the ledPin on
  
  Serial.println(sensorValue);

delay(100);
}

This runs full speed and generally returns 0 if nothing is going on. But if I touch/tap the piezeo element it changes values say jumps to 600 and then slowly reduces back to 0.

This reduction to 0 can take 30 seconds.

I would have expected a much quicker drop to 0

If I was using this to record audio (such as a rain drop or hail) I would need much quicker reduction to 0 since one strong hail stone would be only a few ms not 30 seconds.

Any ideas on what I need to ensure a quicker drop and why it is doing this?

Could there really be that much energy being released over 30 seconds?

Chris
« Last Edit: July 19, 2013, 07:50:24 pm by iisfaq » Logged

Offline Offline
Edison Member
*
Karma: 56
Posts: 2160
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you seen this?
http://www.arduino.cc/en/Tutorial/KnockSensor
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 126
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK I have found that if I put a 1M resister between the Red + Black legs of the Piezieo element then I get good data.

Thanks for the info on the knock sensor - it helped but I found it on a youtube video and not on here.

cheers


I have also changed the loop to

Code:
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  
if (sensorValue >= 5)  
  Serial.println(sensorValue);
  // turn the ledPin on
  delay(100);                  
  
}

So I now have

A0 connected to 1 Leg of 1M resister and then connected to RED leg of Piezo
GND connected to other leg of 1M and then connected to BLACK leg of Piezo



chris
Logged

Pages: [1]   Go Up
Jump to: