Multiple knock sensors

I wish to attach 2 or more piezo elements that function as knock sensors to my Arduino Uno. Now I followed the tutorial for the knock sensor and made a few modifications such as that when a knock occurs it needs to light an LED for 3 seconds. My problem is in adding a second piezo to the analog inputs. I am quite sure I am bunging up the code.

Here goes...

int ledPin1 = 13; int ledPin2 = 8;

byte val = 0;

int THRESHOLD = 20;

void setup() {

pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); Serial.begin(9600);


void loop() {

int sensorValue = analogRead(A0);

if (val >= THRESHOLD) {

digitalWrite(ledPin1, HIGH); delay(3000); digitalWrite(ledPin1, LOW); }

int sensorValue2 = analogRead(A5);

if (val >= THRESHOLD) {

digitalWrite(ledPin2, HIGH); delay(3000); digitalWrite(ledPin2, LOW);




This just seems to get the Arduino stuck, neither sensor will light up either of the LED's. Of course I am very convinced that there needs to be a beautiful bit of code that ties the 2 inputs together although of course I am still quite new at it and it might just not be possible at all. In either case if anybody could lend a coding hand and a lesson in how to, I would greatly appreciate it.

Get rid of the delay()s. Read, play with and really, really understand the blink without delay example.

I agree with AWOL (as I usually do) that you should embrace the blink without delay example, and get rid of the delays...

...but also...

Why do your if statements compare to val, but the sensor readings go to sensorValue and sensor Value2 ? It is no wonder that the piezo sensors are ineffective!

Also, please learn to post your code using the code tags (the # button).

Thank you for your input, I did get it to work now, was staring blind at the problem. Thanks again.