Intruder Alarm System

📡 Skill: Sensor Interfacing
🌐 Skill: Iot
⚙️ Hardware: Arduino Uno
⚙️ Hardware: Ultrasonic Sensor
⚙️ Hardware: Buzzer
🏠 Home Automation
📦 Young Innovators Kit
Difficulty: Entry Level
⏱️ 30 mins
🔒

Wiring Diagram Locked

Create a free profile to unlock detailed component schematics and structural configurations for this kit.

Unlock Instantly
#define TRIG_PIN 9
#define ECHO_PIN 10
#define BUZZER_PIN 12

long duration;
float distance;

float threshold = 13.0; // cm

unsigned long triggerTime = 0;
bool alarmActive = false;

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // Trigger ultrasonic pulse
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  // Read echo
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = duration * 0.034 / 2;

  Serial.print("Distance: ");
  Serial.println(distance);

  // Check threshold crossing
  if (distance > threshold) {
    if (!alarmActive) {
      alarmActive = true;
      triggerTime = millis(); // start timer
    }
  } else {
    // Reset when condition no longer true
    alarmActive = false;
    digitalWrite(BUZZER_PIN, LOW);
  }

  // Alarm behavior
  if (alarmActive) {
    unsigned long elapsed = millis() - triggerTime;

    if (elapsed <= 3000) {
      // First 3 seconds: beeping every 200ms
      if ((elapsed / 200) % 2 == 0) {
        digitalWrite(BUZZER_PIN, HIGH);
      } else {
        digitalWrite(BUZZER_PIN, LOW);
      }
    } else {
      // After 3 seconds: continuous ON
      digitalWrite(BUZZER_PIN, HIGH);
    }
  }

  delay(50);
}
💻

Source Code Locked

Sign in to view, edit, and copy the full verification setup source code and config parameters.

Get Code Access