// Define the buzzer and LED pins
const int buzzerPin = 5; // Change this to match your setup
const int ledPin = 6; // Change this to match your setup
// Define the countdown time (in seconds)
const int countdownTime = 60; // Change this to your desired countdown time
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(115200); // Initialize serial communication
}
void loop() {
// Start the countdown
for (int i = countdownTime; i >= 0; i--) {
// Display the countdown on the Serial Monitor
Serial.print("Countdown: ");
Serial.println(i);
// Calculate the duration based on how close we are to zero
int duration = map(i, 0, countdownTime, 100, 500); // Adjust as needed for sound range
// Play a beep sound, turn on the LED
playSoundAndLight(1000, duration);
delay(1000); // Delay for 1 second
}
// You can add additional actions or code to execute after the countdown finishes here
// For example, turn off the buzzer, LED, or trigger another event.
}
// Function to play a sound on the buzzer, turn on the LED
void playSoundAndLight(int frequency, int duration) {
tone(buzzerPin, frequency, duration);
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(duration);
noTone(buzzerPin);
digitalWrite(ledPin, LOW); // Turn off the LED
}