Intro: Distance Sensor

Introduction: Intro: Distance Sensor

My project is a safe box. It is made in the laser cutter and can support until the Iphone 8 plus. Inside the box, I put Arduino with a bradboard and with some wire connections and a buzzer, I was able to make a distance sensor. Here is the code I got from a website and just changed the distance when it was supposed to buzz.

/I got this code from the Arduino site, . In the images you will be able to see were the wires, the distance sensor and the buzzer are supposed to be.

With this distance sensor you will not be stolen anymore! Because, if the thief opens the box, it's going to start beeping and he is going to be caught.

Step 1: Step 1- Materials Used

To make this code, you will need: A bradboard

1 Arduino piece

A computer to write the code

Exactly 7 wires

USB cable for Arduino

a buzzer

a distance sensor

Also, you will need this code

<p>/*<br> * PIR sensor tester
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int buzzPin = 13; 
// 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
Serial.begin(9600); // Starts the serial communication
pinMode(buzzPin, OUTPUT); 
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
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
if(distance < 6) {
} else {
Serial.print("Distance: ");
Serial.println(distance); </p><p>}                                                                    </p>

Step 2: Step 2- How to Make It

It is an easy thing to do, but to simplify everything, this video is very useful and I used it to make the distance sensor! I also recommend this site a lot, not just for this project but also other projects.


Step 1: Make sure you have all the needed materials

Step 2: Connect the USB cable to a source of energy and to the Arduino piece. PS: make sure you have the code uploaded in your Arduino piece.

Step 3: Connect the wires between the Arduino and the Bradboard, as It's shown in the link,ático.png and in the code also.

Step 4: Test your project and see if it works probably and if you want to change the distance when it is supposed to buzz, you just change the number and instead of writing "distance < 6", you can put distance<10, for example.

1 Person Made This Project!


  • Pets Challenge

    Pets Challenge
  • Remote Control Contest

    Remote Control Contest
  • Stone Concrete Cement Contest

    Stone Concrete Cement Contest



3 years ago on Introduction

True that this would work. I stared to go down the same road for a garage door sensor. I think that using a magnetic door switch (what I ended up doing) would also be a nice approach. Using a magnetic reed switch setup on an interrupt controlled subroutine would be a bit more efficient. Thanks for posting your project.