hi guys, so this project is gonna be about how i make my ultrasonic sensor with buzzer using the arduino. This is a very simple porject to prove the basics. 

 

This project can be installed in places that you guys think it suits this project here. This ultrasonic sensor here will detect objects that are close to another object. For example, normally cars has parking sensors to detect object that you are getting near with it...Similarly goes with the ultrasonic sensor, if there is any object that is getting near to your belongings maybe, it will trigger you by the buzzer with a loud beep from the buzzer for a long relay. So this project is very usefull to use places you think you need. i will move on with my project.

 

ill show you guys step by step on which connections you should connect with:

 

BUZZER: a) postive terminal(+) - pin 2

                b) negative terminal(-) -pin GND

ULTRASONIC: a)pin GND - pin GND to the                                      arduino board

                        b) pin ECHO - pin 9

                        c) pin TRIG - pin 10

                        d) pin VCC - 5V supply

 

I'll move on with the code

(you guys must copy down the code below)

 

int trigPin = 9;

int echoPin = 10;

int led = 7;

 

 

void setup() {

Serial.begin(9600);

pinMode(led, OUTPUT);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

// put your setup code here, to run once:

 

}

 

void loop() {

long duration, distance;

digitalWrite(trigPin,HIGH);

delayMicroseconds(1000);

digitalWrite(trigPin, LOW);

duration=pulseIn(echoPin, HIGH);

distance =(duration/2)/29.1;

Serial.print(distance);

Serial.println("CM");

delay(10);

 

if((distance<=10))

{

digitalWrite(led, HIGH);

}

else if(distance>10)

{

digitalWrite(led, LOW);

}

}

 

I am very sure that this code is 100% works. But if you guys have any problem with the code,please ask me question and i will definitely reply. Goodluck guys. bye