Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Vidhi Padhiar
Published

Distance-Based Alarm System:Alert When Objects Are Too Close

Alerts when objects come too close using an HC-SR04 sensor and buzzer. Simple, customizable safety solution! 🚨🔧

BeginnerFull instructions provided1 hour244
Distance-Based Alarm System:Alert When Objects Are Too Close

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
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 220 ohm
Resistor 220 ohm
×1

Story

Read more

Custom parts and enclosures

Buzzer alarm system working model

Schematics

Buzzer alarm system wiring

Code

Buzzer Alarm System

Arduino
🚀 Just completed this Distance-Based Alarm System project and it’s working perfectly! The HC-SR04 sensor and buzzer are a great combo for creating an effective proximity alert. If you’re looking to add a bit of safety or just want to explore how ultrasonic sensors work, this is a fantastic starting point. Looking forward to seeing how others use this concept in their projects! Feel free to ask any questions or share your own variations. 😊🔧 #Arduino #DIY #Electronics
const int trigger = 9;
const int echo = 10;
const int buzzer = 11;
const int dist = 15; // 15 cm
void setup() {
 pinMode(trigger, OUTPUT);
 pinMode(echo, INPUT);
 pinMode(buzzer, OUTPUT);
 Serial.begin(9600);
}

void loop() {
  digitalWrite(trigger, LOW);
  delayMicroseconds(2);

  digitalWrite(trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger, LOW);

  long duration = pulseIn(echo, HIGH);
  float distance = (duration/2.0)*0.0344;
  
  if(distance<dist)
  {
    digitalWrite(buzzer, HIGH);
  }
  else{
    digitalWrite(buzzer, LOW);
  }

  delay(500);
}

Credits

Vidhi Padhiar
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.