#define POT_PIN 34 // Potentiometer simulating accelerometer (Tilt)
#define BUTTON_PIN 18 // Push button simulating impact detection
#define BUZZER_PIN 23 // Buzzer for accident alert
#define LED_PIN 19 // LED Indicator for accident
bool accidentDetected = false;
void setup() {
Serial.begin(115200);
pinMode(BUTTON_PIN, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(BUZZER_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.println("Smart Helmet System Initialized");
}
void loop() {
int tiltValue = analogRead(POT_PIN);
bool impactDetected = digitalRead(BUTTON_PIN) == LOW;
// Detect tilt beyond threshold (simulated)
bool tiltDetected = tiltValue > 3000;
if (tiltDetected || impactDetected) {
accidentDetected = true;
digitalWrite(BUZZER_PIN, HIGH);
digitalWrite(LED_PIN, HIGH);
Serial.println("🚨 Accident Detected! 🚨");
} else {
accidentDetected = false;
digitalWrite(BUZZER_PIN, LOW);
digitalWrite(LED_PIN, LOW);
}
Serial.print("Tilt Value: ");
Serial.print(tiltValue);
Serial.print(" | Impact: ");
Serial.println(impactDetected ? "YES" : "NO");
delay(500);
}