Hello there everyone,
I have been working on my final uni project which involves triggering LEDs from Piezo elements connected to a drum set (so each time I hit a drum an LED strip gets activated and deactivated).
I have been doing this on an Arduino Uno and have been using this code on LED testers at the moment, however, the lights don’t seem to be responding well to the code.
I am a complete beginner in coding and was recommended this arduino Knock! (https://www.arduino.cc/en/Tutorial/Knock) code by Stephen from core electronics. It seems to be triggering the LEDs however once triggered once, the lights do not turn off for a couple of seconds and the serial print is printing hundreds of hits when I only tapped it once.
I basically just need a simple on/off reaction to the piezo’s being hit as it needs to respond dynamically to each drum hit. Any help or guidance would be wonderful to someone who has very little arduino knowledge!!! below is the code I have been working on so far.
Thanks in advance! (At the moment the Piezo is connected to a breadboard and a 1 megohm resistor).
int knockSensor = 0;
byte val = 0;
int statePin = LOW;
int THRESHOLD = 200;
void setup() {
pinMode(8, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(knockSensor);
if (val >= THRESHOLD) {
statePin = !statePin;
digitalWrite(8, statePin);
Serial.println("Knock!");
}
delay(100); // we have to make a delay to avoid overloading the serial port
}











