Ultrasonic Motion Detection Alarm Using Arduino

Step 1: Components

Step 2: Uploading the code

CODE :

#define trigPin 12
#define echoPin 13
int Buzzer = 8;

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

void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 80 || distance Serial.println("no object detected");
digitalWrite(Buzzer, LOW);

}
else {
Serial.println("object detected");
tone(Buzzer, 400); // play 400 Hz tone for 500 ms
delay(500);
tone(Buzzer, 800); // play 800Hz tone for 500ms
delay(500);
tone(Buzzer, 400); // play 400 Hz tone for 500 ms
delay(500);
tone(Buzzer, 800); // play 800Hz tone for 500ms
delay(500);
tone(Buzzer, 400); // play 400 Hz tone for 500 ms
delay(500);
tone(Buzzer, 800); // play 800Hz tone for 500ms
delay(500);
noTone(Buzzer);
}
delay(300);
}

Step 3: Ultrasonic Sensor Connections

Connections :

Connect Vcc to Vin pin
Connect GND to GND 
connect ECHO to Pin 13
connect TRİG to Pin 12

Step 4: Connecting The Buzzer


Connect Positive Terminal To Pin 8

Connect Negative Terminal To GND pin on POWER

Previous
Next Post »
3IG