Devices & Components
Arduino Uno Rev3
Breadboard (generic)
HC-SR04 Ultrasonic Sensor
Jumper wires (generic)
Speaker 0.5 w
LED (generic)
Software & Tools
Arduino IDE
Project description
Code
proximitydetectoralarm
arduino
1#define trigPin 13 2#define echoPin 12 3#define speaker 11 4#define led2 10 5 6void setup() { 7 Serial.begin (9600); 8 pinMode(trigPin, OUTPUT); 9 pinMode(echoPin, INPUT); 10 pinMode(speaker, OUTPUT); 11 pinMode(led2, OUTPUT); 12} 13 14void loop() { 15 long duration, distance; 16 digitalWrite(trigPin, LOW); 17 delayMicroseconds(2); 18 digitalWrite(trigPin, HIGH); 19 delayMicroseconds(10); 20 digitalWrite(trigPin, LOW); 21 duration = pulseIn(echoPin, HIGH); 22 distance = (duration/2) / 29.1; 23 if (distance < 192) { // set your distance 24 tone(speaker,7); 25 digitalWrite(led2,HIGH); 26} 27 28 delay(50); //change the rate at which the speaker pings 29} 30
proximitydetectoralarm
arduino
1#define trigPin 13 2#define echoPin 12 3#define speaker 11 4#define led2 10 5 6void setup() { 7 Serial.begin (9600); 8 pinMode(trigPin, OUTPUT); 9 pinMode(echoPin, INPUT); 10 pinMode(speaker, OUTPUT); 11 pinMode(led2, OUTPUT); 12} 13 14void loop() { 15 long duration, distance; 16 digitalWrite(trigPin, LOW); 17 delayMicroseconds(2); 18 digitalWrite(trigPin, HIGH); 19 delayMicroseconds(10); 20 digitalWrite(trigPin, LOW); 21 duration = pulseIn(echoPin, HIGH); 22 distance = (duration/2) / 29.1; 23 if (distance < 192) { // set your distance 24 tone(speaker,7); 25 digitalWrite(led2,HIGH); 26} 27 28 delay(50); //change the rate at which the speaker pings 29} 30
Downloadable files
untitled
https://github.com/saaketporay/Proximity-Detector-Alarm
Diagram
Diagram

untitled
https://github.com/saaketporay/Proximity-Detector-Alarm
Diagram
Diagram

Schematic
Schematic

Comments
Only logged in users can leave comments