0

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!!

Breadboard

Arduino

/*
 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);
 }
 }
}
per1234
4,2782 gold badges24 silver badges43 bronze badges
asked Aug 3, 2017 at 20:16
1
  • Edit your question to format the code. Select all the code and hit Ctrl-K. Commented Aug 3, 2017 at 20:31

1 Answer 1

1

Well, you never call blink, so leds never get a chance to light up.

Also, you are turning down the led at the begining of each loop. That will cause flickring.

And you don't need so many parameters for blink. In fact, what you need is a little function for blinking just one led.

I think this sketch is what your are looking for (but I can't assure it's correct)

/*
 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()
{
 /* 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
 if(Piezo1V >= threshold||Piezo2V >= threshold) //toggle status of LED pins linked to PP1
 // Blink the LEDs on for both Piezos
 {
 {
 littleBlink(2);
 littleBlink(3);
 littleBlink(4);
 littleBlink(5);
 littleBlink(6);
 littleBlink(7);
 littleBlink(8);
 littleBlink(9);
 littleBlink(10);
 littleBlink(11);
 }
 }
}
void littleBlink(int pin)
{
 digitalWrite(pin, HIGH);
 delay(10);
 digitalWrite(pin, LOW);
 delay(10);
}
answered Aug 3, 2017 at 21:11
3
  • Use a for loop for the littleBlink calls, e.g. for (int n = 2; n < 12; n++) { littleBlink(n); } Commented Aug 3, 2017 at 22:20
  • 1
    @Michel. I know, but I'm not sure about what pins he is using and a for will confuse him. Keep things simple, one small step at time. Commented Aug 3, 2017 at 22:24
  • yes, that's also true Commented Aug 3, 2017 at 22:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.