How to make Bluetooth Accident Alert Calling System



 




Click here and download App 

               CODE 

const int PirSensor = 2;     // PIR sensor input pin

const int Buzzer = 13;        // Buzzer output pin

const int Button = 4;        // Push button input pin


int motionState = 0;

bool motionHandled = false;


void setup() {

  Serial.begin(9600);

  pinMode(PirSensor, INPUT);

  pinMode(Buzzer, OUTPUT);

  pinMode(Button, INPUT_PULLUP);  // Use internal pull-up resistor

}


void loop() {

  motionState = digitalRead(PirSensor);


  if (motionState == HIGH && !motionHandled) {

    motionHandled = true;   // Avoid repeated triggers


    unsigned long startTime = millis();

    bool buttonPressed = false;


    // Beep for up to 5 seconds or until button is pressed

    while (millis() - startTime < 5000) {

      if (digitalRead(Button) == LOW) {  // Button pressed (active LOW)

        buttonPressed = true;

        break;

      }

      digitalWrite(Buzzer, HIGH);  // Turn on buzzer

      delay(100);

      digitalWrite(Buzzer, LOW);   // Turn off buzzer

      delay(100);

    }


    digitalWrite(Buzzer, LOW);  // Make sure buzzer is off


    if (!buttonPressed) {

      Serial.println("1");

    }


    delay(1000);                // Small delay to avoid retriggering immediately

  }


  // Reset motionHandled if no motion

  if (motionState == LOW) {

    motionHandled = false;

  }

}

Post a Comment

Previous Post Next Post

Contact Form