Safety Sensor

27

The main idea: The main idea of this project is to avoid invasions in your house, so you can enjoy life safer. You can install this anywhere you want like a garage, a room, a locker etc.

How does it work? Basically, when you open the door the buzzer will start, it works because there is a sensor and when there is nothing blocking the sensor up until 35cm it is programmed to start buzzing. But, when you close the door the buzzer will stop.

Step 1: What Will You Need:

A sensor, A breadboard, Jumper wires, Buzzer, Arduino board, Button, Resister 10K, A computer with Arduino install and a USB cable

Step 1- First of all, you need to get all your materials to start this project.

Step 2: Building

Then, you get the breadboard and the Arduino board and places the jumper wires, the button, sensor, resister 10k and the button. It should look like the photo

Observation- If you press the button it will stop buzzing for 10 seconds

Step 3: Plugging

Step 3- Plug the one side of the USB cable to the Arduino board and the other side to your computer

Step 4: Code

Open Arduino in your computer and put this code in it: Step 4- Open Arduino in your computer and put this code in it:

/*
* Ultrasonic Sensor HC-SR04 and Arduino Tutorial
*
* by Dejan Nedelkovski,
* www.HowToMechatronic.com
*
*/
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int buzzPin = 2;
const int button1 = 3;
int making =0;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzPin, OUTPUT);
pinMode (button1, INPUT); 
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
making = digitalRead(button1);
Serial.println(making);
if(distance>35){
  digitalWrite(buzzPin, HIGH);
  if (making == HIGH) {
   digitalWrite(buzzPin, LOW);
   delay(10000);
  }
} else {
  digitalWrite(buzzPin, LOW);
}
}

Share

    Recommendations

    • First Time Author

      First Time Author
    • Big and Small Contest

      Big and Small Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018

    Discussions