brillianttechnoz
Published © GPL3+

Alarm system

Makes sound when an an object comes too close to it

BeginnerFull instructions provided5,946
Alarm system

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Buzzer
Buzzer
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

schematic for alarm system

Code

code for alarm system

C/C++
copy and paste it in the aurdino ide
int trigPin = 9;//first we should the pins
int echoPin = 10;
int buzzer  = 7;
void setup() {
  Serial.begin (9600);//to print on serial moniter we should start the serial baud
  pinMode(trigPin, OUTPUT);//we should declare trigpin as output and echo pin as input
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  //block of code used to find the distance of an object in cm 
  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;
  
  if (distance <= 10)// if the distance is less than 10 or = 10 
                    //than the buzzer will make sound
  {
    digitalWrite(buzzer,HIGH);
    Serial.print(distance);//to print the distance in serial moniter
    Serial.println("");
  }
  else {
   digitalWrite(buzzer,LOW);//else it will turn off
   Serial.print(distance);//to print the distance in serial moniter
   Serial.println("");
  }
  delay(10);
}

Credits

brillianttechnoz

brillianttechnoz

3 projects • 3 followers

Comments