Hi everyone! I am trying to create a project using 6 piezo vibration sensors and 6 LEDs. The goal is for piezo1 to turn on LED1 for 1 second when a vibration is sensed, piezo2 blinks LED2, etc. I borrowed the wiring diagram from another project and adapted it for this.
The piezos all work great and I can see in the serial monitor the various levels of input. But no LEDs light up. Code and fritzing diagram below. I am using a Mega2560, though the diagram is with an Uno. Same pin numbers, though. Please help! TIA
// Define the pin numbers
const int piezoPins[6] = {A0, A1, A2, A3, A4, A5}; // Analog pins for piezo sensors
const int ledPins[6] = {2, 3, 4, 5, 6, 7}; // Digital pins for LEDs
void setup() {
// Initialize LED pins as outputs
for (int i = 0; i < 6; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW); // Ensure LEDs are off initially
}
// Initialize piezo sensor pins as inputs
for (int i = 0; i < 6; i++) {
pinMode(piezoPins[i], INPUT);
}
// Start serial communication
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < 6; i++) {
int sensorValue = analogRead(piezoPins[i]); // Read the sensor value
// Print sensor value to Serial Monitor
Serial.print("Sensor ");
Serial.print(i);
Serial.print(": ");
Serial.println(sensorValue);
if (sensorValue > 10) { // Threshold value to determine vibration (Adjust as needed)
digitalWrite(ledPins[i], HIGH); // Turn on the corresponding LED
delay(500);
digitalWrite(ledPins[i], LOW); // Turn on the corresponding LED
} else {
digitalWrite(ledPins[i], LOW); // Turn off the LED
}
}
delay(100); // Small delay to avoid rapid toggling
}