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, https://www.arduino.cc . 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.
Attachments
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); 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 if(distance < 6) { digitalWrite(13,HIGH); } else { digitalWrite(13,LOW); } 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! https://howtomechatronics.com/tutorials/arduino/u... I also recommend this site a lot, not just for this project but also other projects.
HOW TO MAKE
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, http://blogmasterwalkershop.com.br/wp-content/uploads/2016/10/esquemá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.