Arduino UNO Ultrasonic Motion Alarm
by AnasArkawi in Circuits > Arduino
1420 Views, 19 Favorites, 0 Comments
Arduino UNO Ultrasonic Motion Alarm
How to make arduino powered motion alarm!
I Hope You Enjoy
I Hope You Enjoy
Components
Components:
Arduino UNO
Buzzer
Ultrasonic Sensor
Jumper Wire
Arduino UNO
Buzzer
Ultrasonic Sensor
Jumper Wire
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);
}
#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);
}
Ultrasonic Sensor Connections
Connections :
Connect Vcc to Vin pin
Connect GND to GND
connect ECHO to Pin 13
connect TRİG to Pin 12
Connect Vcc to Vin pin
Connect GND to GND
connect ECHO to Pin 13
connect TRİG to Pin 12
Connecting the Buzzer
Connect Positive Terminal To Pin 8
Connect Negative Terminal To GND pin on POWER
Connect Negative Terminal To GND pin on POWER
Finish!!
Now Power Up Arduino And Test It, Don't Forget To Vote, I Hope You Enjoy Thanks For Supporting Goodbye ?