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 hour205
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.