nimishac
Published © GPL3+

Ultrasonic security system

This is a distance sensitive alarm made with ultrasonic sensor

BeginnerShowcase (no instructions)8,407
Ultrasonic security system

Things used in this project

Story

Read more

Schematics

Connections

Code

Ultrasonic Security Alarm

C/C++
//Security Alarm with Ultrasonic Sensor//

#define trigPin 6  
#define echoPin 5
#define buzzer 2
float new_delay; 


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


void loop() 
{
  long duration, distance;
  digitalWrite(trigPin, LOW);        
  delayMicroseconds(2);              
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);           
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  new_delay= (distance *3) +30;
  Serial.print(distance);
  Serial.println("  cm");
  if (distance < 50)
  {
   digitalWrite(buzzer,HIGH);
   delay(new_delay);
   digitalWrite(buzzer,LOW);
 
  }
  else
  {
    digitalWrite(buzzer,LOW);

  }
  
 delay(200);
}

Credits

nimishac

nimishac

3 projects • 2 followers

Comments