I am running two piezos off an Arduino UNO and trying to get 10 LED lights to trigger when the piezo voltage exceeds a certain threshold. Problem is, the LEDs wont fire when the Piezo voltage exceeds that threshold and I'm not sure if it is a coding or wiring problem.
Below are pictures of the wiring (Top and bottom) and code. Any help is much appreciated!!
/*
Dual Piezo Bond Auger Sensor; Blinking LED Light Stack Sketch
-----------------------------------------------------*/
//Piezo 1 Pin (PiezoPin1)
//Piezo 1 connected to A0
int PP1 = 0;
//Piezo 1 Pin (PiezoPin1)
//Piezo 2 connected to A1
int PP2 = 1;
//Sets the threshold for the detected sound to trigger the LED
const int threshold = 0.01;
void setup () {
Serial.begin(9600);
for (int i = 4; i < 12; i++) {
pinMode(i, OUTPUT);
//sets the led pins 2-11 to output
}
}
void loop() {
//Ensure to turn off ALL LEDs before continuing
for (int i = 4; i < 12; i++) {
digitalWrite(i, LOW);
}
/* Read the Piezos
Reads both piezos and outputs the values. Triggers LED lights
to fire when a peak voltage is exceeded
Adjust the value based on the peak signal voltage you
want to trigger the LED lights*/
int Piezo1ADC = analogRead(PP1); // Read Piezo 1 ADC value
float Piezo1V = Piezo1ADC / 1023.0 * 5.0; // Convert to voltage
int Piezo2ADC = analogRead(PP2); // Read Piezo 2 ADC value
float Piezo2V = Piezo2ADC / 1023.0 * 5.0; // Convert to voltage
Serial.println(Piezo1V); //Print the voltage from Piezo 1
Serial.println(Piezo2V); //Print the voltage from Piezo 2
}
// The blink function - used to turn the LEDs on and off
void blink(int LEDPin11, int LEDPin2, int LEDPin3, int LEDPin4, int LEDPin5, int LEDPin6, int LEDPin7, int LEDPin8, int LEDPin9, int LEDPin10, int Piezo1V, int Piezo2V, int threshold) {
if (Piezo1V >= threshold || Piezo2V >= threshold) { //toggle status of LED pins linked to PP1
// Blink the LEDs on for both Piezos
{ digitalWrite(LEDPin2, HIGH);
// Delay so that you can see the LEDs go On.
delay(10);
// Turn the LEDs Off
digitalWrite(LEDPin2, LOW);
// Increase this Delay if you want to see an actual blinking effect.
delay(10);
}
{ digitalWrite(LEDPin3, HIGH);
delay(10);
digitalWrite(LEDPin3, LOW);
delay(10);
}
{ digitalWrite(LEDPin4, HIGH);
delay(10);
digitalWrite(LEDPin4, LOW);
delay(10);
}
{ digitalWrite(LEDPin5, HIGH);
delay(10);
digitalWrite(LEDPin5, LOW);
delay(10);
}
{ digitalWrite(LEDPin6, HIGH);
delay(10);
digitalWrite(LEDPin6, LOW);
delay(10);
}
{ digitalWrite(LEDPin7, HIGH);
delay(10);
digitalWrite(LEDPin7, LOW);
delay(10);
}
{ digitalWrite(LEDPin8, HIGH);
delay(10);
digitalWrite(LEDPin8, LOW);
delay(10);
}
{ digitalWrite(LEDPin9, HIGH);
delay(10);
digitalWrite(LEDPin9, LOW);
delay(10);
}
{ digitalWrite(LEDPin10, HIGH);
delay(10);
digitalWrite(LEDPin10, LOW);
delay(10);
}
{ digitalWrite(LEDPin11, HIGH);
delay(10);
digitalWrite(LEDPin11, LOW);
delay(10);
}
{ digitalWrite(LEDPin10, HIGH);
delay(10);
digitalWrite(LEDPin10, LOW);
delay(10);
}
}
}