Smart Motion Detector With sound and Light

Function

The Motion Detector acts like a digital watchman. It sends out invisible sound waves to measure distance in real-time. We have programmed the logic to focus on a 50 cm radius.

  1. Scanning: The sensor constantly calculates the distance of objects in front of it.
  2. Decision Making: The code checks if the distance is less than 50 cm.
  3. Reaction:
    • If an object is closer than 50 cm, the Arduino activates the Intruder Alarm (Red Light + Sound).
    • If the area is clear (distance > 50 cm), it maintains the All-Clear signal (Green Light).

Components

To build this Smart Motion Detector With sound and Light, we used the following parts from the Plzpapa Basic Robotic Kit:

  • Arduino Uno
  • BreadBoard
  • Ultrasonic Sensor
  • Buzzer (For Sound)
  • 1 Green LED 
  • 1 Red LED 
  • 2 Resistor Blue (220 Ohm) (LED ke liye)
  • Jumper Wires 

Wiring (Taarein Jorna)

1. BreadBoard:

  • Connect with GND

2. Ultrasonic Sensor

  • VCC: Arduino 5V pin par.
  • GND: BreadBoard +.
  • Trig: Arduino Pin 9 par.
  • Echo: Arduino Pin 10 par.

3.Red LED Connections:

  • Bari Taang (+): Arduino Pin 2 par.
  • Choti Taang (-): Resistor laga kar BreadBoard +.

4.Green LED (Mehfooz/No Motion) Connections

  • Bari Taang (+): Arduino Pin 3 par.
  • Choti Taang (-): Resistor laga kar BreadBoard +.

5 .Buzzer Connections

  • Bari Taang (+): Arduino Pin 4 par.
  • Choti Taang (-): BreadBoard +.

Code

// --- PINS ---
const int trigPin = 9;   // Ultrasonic Sensor Trig
const int echoPin = 10;  // Ultrasonic Sensor Echo
const int redLed = 2;    // Laal Batti (Khatra)
const int greenLed = 3;  // Hari Batti (Safe)
const int buzzer = 4;    // Buzzer

// --- RANGE SETTING (Yahan se range control karein) ---
// Agar aap isay '20' kar dein ge to haath bohat qareeb lana paray ga.
// Agar '100' kar dein ge to door se pakar lay ga.
int rangeLimit = 50; // Abhi hum ne 50 CM set kiya hai.

long duration;
int distance;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(buzzer, OUTPUT);
 
  Serial.begin(9600);
}

void loop() {
  // 1. Faasla Naapna (Measure Distance)
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2; // CM mein faasla
 
  // Serial Monitor par distance check karein
  Serial.print("Faasla: ");
  Serial.print(distance);
  Serial.println(" cm");

  // 2. Faisla Karna (Decision)
  // Agar faasla 50 se KAM hai aur 0 se ZYADA hai
  if (distance < rangeLimit && distance > 0) {
   
    // MOTION DETECTED! (Red Light + Sound)
    digitalWrite(redLed, HIGH);
    digitalWrite(greenLed, LOW);
    digitalWrite(buzzer, HIGH);
   
  } else {
   
    // SAFE ZONE (Green Light Only)
    digitalWrite(redLed, LOW);
    digitalWrite(greenLed, HIGH);
    digitalWrite(buzzer, LOW);
  }
 
  delay(100); // Thora sa waqfa
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top