I took the knock code..and edited it to my needs..
what I am trying to do is:
1.) have a piezo sensor hoked up to Ananlog pin 0
2.) read this 'output' from the piezo sensors with the Arduino
3.) take the results from Piezo and have a led mirror the output on PWM (so tiny/low flicker..or bright flickering)
/* Vibration detection using piezo sensor with matching PWM led output
This sketch reads a piezo element to detect a vibration.
It reads an analog pin and parses the value into a PWM value represented by the LED.
The circuit:
* + connection of the piezo attached to analog in 0
* - connection of the piezo attached to ground
* 1-megohm resistor attached from analog in 0 to ground
edited from:
http://www.arduino.cc/en/Tutorial/Knock.pde
*/
// led connected to digital pin 13
const int powerLed = 13;
//declare pin 9 to be an pwmLed (pin 9 is PWM enabled pin)
const int pwmLED = 9;
// the piezo is connected to analog pin 0
const int piezoSensor = A0;
// threshold value to decide when to 'detect' above/over a cetain vibration level
const int threshold = 100;
// variable to store the read value
int pwmVal = 0;
// variable to store the value read from the sensor pin
int sensorReading = 0;
void setup() {
// declare the powerLed as as OUTPUT
pinMode(powerLed, OUTPUT);
//turn ON powerLED
digitalWrite(powerLed, HIGH);
// declare analog pin 0 as input
pinMode(A0, INPUT);
// turn on serial port
//Serial.begin(9600);
}
void loop() {
//read the piezo sensor
sensorReading = analogRead(piezoSensor);
//Serial.println(sensorReading);
// analogRead values go from 0 to 1023, analogWrite values from 0 to 255
pwmVal = sensorReading / 4;
analogWrite(pwmLED, pwmVal);
//Serial.println("PWM: ");
//Serial.println(pwmVal);
delay(25); // delay to avoid overloading the serial port buffer
}
I have my 1 megaOhm resistor arcross GND and analog pin0
piezo V++ goes to analog pin 0 (after resistor lead)
piezo GND goes to GND ( after resistor lead)
I have reada few mentions..but 'where' do I put a cap to keep/hold this peek signal for a better circuit?
(I am new to this and still learning when I have time) =)
I mean the code 'works' (sorta).. but I have to bang on the piezo sensor I got from RadioShack..
is there a way to make it more sensitive?
for exampel with sensor on my desk.. laying flat..
if I tap my fingers on desktop..it should react..
but I have to bang pretty hard..or even hit the sensor physically itself..??
suggestions?
thanks