PIYUSH_K_SINGH
Published © GPL3+

PROXIMITY_ALARM

Proximity Alarm with increasingly faster beeping like 'SONAR Radar'.

BeginnerFull instructions provided1,269
PROXIMITY_ALARM

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
9V DC Battery Connector
×1
9V DC Battery
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

PROXIMTY_ALARM_CIRCUIT

Code

PROXIMTY_ALARM_CODE

C/C++
The code is used for proximity alarm which acts like a 'SONAR'. It starts with a tune from buzzer, which acts like a loading music ! The beeping of buzzer changes every time, depending upon the distance observed by ultra-sonic sensor!
#define trigPin 13
#define echoPin 12
int buzz=8;
int b;
int led=7;
int a=2;
int count =15;
//int j;
//#define led 11
//#define led2 10

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

void loop() {

  for(int i=0;i<2;i++)
  { while(count>0)
     {tone(buzz,500*count,300);
      // j=(rand()%10);
       delay(count*10);
       count--;
     }
  }
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 // if (distance < 4) {  // This is where the LED On/Off happens
 //   digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
//  digitalWrite(led2,LOW);
//}
 // else {
   // digitalWrite(led,LOW);
    //digitalWrite(led2,HIGH);
 // }
  if (distance >= 300 || distance <= 0){
   // Serial.println("Out of range");
 }
  else {
    //Serial.write(distance);
    //Serial.println(" cm");
    b=distance/10;
 tone(buzz,10000,50);
 digitalWrite(led, HIGH);
 digitalWrite(led, LOW);

 delay(b*70);
  }
 // delay(500);
}

Credits

PIYUSH_K_SINGH

PIYUSH_K_SINGH

3 projects • 1 follower

Comments