Hi guys,
Essentially I've connected a piezo and an LED to appropriate pins. My code works as the light flashes when a certain threshold is reached on the analog input
I have a few questions
-
Why do I use a resistor in parallel with the piezo wires
-
How can i get my sensitivity right - also its strange because the device doesnt really pick up sound - but just more when i tap it or something.
Ive been trying to use this to guide me, and while it works - it doesnt work very well.
Ive tried various resistors, but theres clearly a sweet spot i can't find
- how can i find it?
there is also a strange phenomenon to me where if i do tap it, it the analog input just seems to stay at a certain value for quite some time and just slowly go down by 1. I kind of want it to be responsive and quick
in case it is of any use to you: my code
/*
Microphone
*/
int ledPin = 2;
int knockSensor= 5;
byte val = 0 ;
int statePin = LOW;
int THRESHOLD = 100;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
val = analogRead(knockSensor);
Serial.println(val);
delay(100);
if(val >= THRESHOLD)
{
statePin = HIGH;
digitalWrite(ledPin, statePin);
//Serial.println("Knock!");
}
delay(100);
statePin = LOW;
digitalWrite(ledPin, statePin);
}
Thanks in advance