Go Down

Topic: Using a Piezeo Element to read analog values (Read 453 times) previous topic - next topic

iisfaq

Jul 20, 2013, 02:35 am Last Edit: Jul 20, 2013, 02:50 am by iisfaq Reason: 1
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: [Select]


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

LarryD

Have you seen this?
http://www.arduino.cc/en/Tutorial/KnockSensor
The way you have it in your schematic isn't the same as how you have it wired up!

iisfaq

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: [Select]

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy