Hassan Shettima Lawan
Published © GPL3+

Proximity Alarm Distance Meter

This project can perform a number of tasks simultaneously while being monitored through serial port on your computer or on your mobile.

IntermediateProtip7 hours5,733
Proximity Alarm Distance Meter

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
passive buzzer module
U can find it on ali express, it costs less than a dollar.
×1
HC-06 Bluetooth Module
×1
LED (generic)
LED (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE
arduino bluetooth controller apk
U can find it on playstore
microsoft visio professional

Story

Read more

Schematics

proximity_alarm_distance_sensor_1SkASpI1Lh.pdf

Code

ultrasonic_sensor___buzzer.ino

Arduino
// proximity sensor
// Tgst hassan shettima lawan contact me on;
// hassanshettima705@gmail.com +2347062769748 +2348183555452



const int buzzerPin = 8;               // buzzzer signal pin attached to digital pin 8
const int trigPin = 11;               // ultrasonic triggerPin connected to digital pin 11
const int echoPin = 10;               // ultrasonic echoPin connected to digital pin 10
int ledPin = 13;                      // LED positive connecteed to digital pin 13 (no need for resistor)
long duration;
float distanceMeters, distanceCm, distanceInch;

void setup() {                        // define all digital and analog pins
  pinMode(13, OUTPUT);                // LED pin as output
  pinMode(trigPin, OUTPUT);           // trigger pin as output because it sends signal
  pinMode(8, OUTPUT);                 // buzzer pin as output
  pinMode(echoPin, INPUT);             // echo pin as input becaue it recievs signals
  Serial.begin(9600);                  // initiate serial communication
}

void loop() {
  digitalWrite(trigPin, HIGH);                // initiate the ultrasonic sensor for sending and receiving
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distanceMeters = duration * 0.00034 / 2;      // speed of sound per second; divide by 2 due to then sound coming back to the echo part of the sensor
  distanceCm = duration * 0.034 / 2;
  distanceInch = duration * 0.0133 / 2;

  Serial.print("Distance: ");                     // print distance (meters) in serial monitor
  Serial.print(distanceMeters);
  Serial.println("  Meters");
  delay(300);

  Serial.print("Distance: ");                      // print distance (centi meters) in serial monitor
  Serial.print(distanceCm);
  Serial.println("  cm");
  delay(300);

  Serial.print("Distance: ");                        // print distance (inches) in serial monitor
  Serial.print(distanceInch);
  Serial.println("  inch");
  delay(300);
  Serial.println("----------------------------");     // seoeration


  if (distanceCm <= 30 )    {                           // if distance is greater than or equal to 30 cm on LED and on buzzer ON and OFF
    digitalWrite(13, HIGH);                                 // ...... with delay as interval
    tone(buzzerPin, 1200);
    delay(500);                                                 //   u can tweak the code to suit yourn needs
    noTone(buzzerPin);
    digitalWrite(13, LOW);
    delay(5);
  }
  else if (distanceCm > 100 )    {
    digitalWrite(13, LOW);
    noTone(buzzerPin);
  }
}

Credits

Hassan Shettima Lawan

Hassan Shettima Lawan

2 projects • 12 followers
Electrical electronics engineering technologist. Learning is a hobby.

Comments