#include <Arduino.h>
// Define GPIO pins
const int relayPin = 23; // Relay pin
const int ledPin = 22; // LED pin
const int buzzerPin = 21; // Buzzer pin
const unsigned long firstPhaseDuration = 10000; // 10 seconds
const unsigned long secondPhaseDuration = 4000; // 4 seconds (10 to 14 seconds)
const unsigned long totalCountdownDuration = 24000; // Total 24 seconds
const unsigned long relayDuration = 5000; // Relay active for 5 seconds
void setup() {
// Initialize serial monitor
Serial.begin(115200);
// Set pin modes
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
// Make sure relay and buzzer are off initially
digitalWrite(relayPin, LOW);
digitalWrite(buzzerPin, LOW);
}
void loop() {
// Indicate start of the system
Serial.println("Starting system...");
// Loud double beep at the start
for (int i = 0; i < 2; i++) {
tone(buzzerPin, 1000, 200); // Beep for 200 ms
delay(300); // Wait between beeps
}
// Phase 1: First 10 seconds
digitalWrite(ledPin, HIGH); // LED ON
for (int i = 0; i < 2; i++) { // Double beep
tone(buzzerPin, 1000, 200); // Beep for 200 ms each
delay(300); // Wait between beeps
}
delay(firstPhaseDuration - 400); // Wait for remaining time (10 sec total)
// Phase 2: Next 4 seconds (10 to 14 seconds)
Serial.println("Starting countdown for next 4 seconds...");
// Fast blinking LED for the next 4 seconds
unsigned long startTime = millis();
while (millis() - startTime < secondPhaseDuration) {
digitalWrite(ledPin, HIGH); // LED ON
delay(200); // Short ON time
digitalWrite(ledPin, LOW); // LED OFF
delay(200); // Short OFF time
}
// Continuous beep during the blinking
tone(buzzerPin, 1000); // Start continuous beep
// Final countdown for 14 to 24 seconds
Serial.println("Starting final countdown...");
delay(totalCountdownDuration - firstPhaseDuration - secondPhaseDuration); // Wait for remaining time (24 sec total)
// LED fast blink from 14 to 24 seconds
startTime = millis();
while (millis() - startTime < relayDuration) {
digitalWrite(ledPin, HIGH); // LED ON
delay(200); // Short ON time
digitalWrite(ledPin, LOW); // LED OFF
delay(200); // Short OFF time
}
// Activate relay for 5 seconds
Serial.println("Ejecting parachute!");
digitalWrite(relayPin, HIGH); // Activate relay
delay(relayDuration); // Keep activated for 5 seconds
digitalWrite(relayPin, LOW); // Deactivate relay
Serial.println("Parachute ejection complete.");
// Reset and stop
digitalWrite(ledPin, LOW); // Ensure LED is OFF
noTone(buzzerPin); // Ensure buzzer is OFF
while (true); // Stop the loop
}