Using Ultrasonic Distance Sensor HC-SR04 with Buzzer, LED and Arduino

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ • 357

  • @maker101io
    @maker101io  3 роки тому +17

    Source Code: create.arduino.cc/editor/mertarduinotech/b7022e05-f709-4003-b2a7-5c487ee25007/preview
    Recommended Items:
    Use Your Muscles in Project - amzn.to/3wdL45C​
    37 Sensor & Module Packages - amzn.to/3m66WeQ​
    Try this Robot Arm - amzn.to/3fq8DCl​
    Best Resin 3D Printer - amzn.to/39tY8KB​
    Arduino Compatible Kits - bit.ly/2J2AFF7​
    Banggood Spring Sale - bit.ly/3slMbOn​

  • @Kona-bona
    @Kona-bona 5 років тому +11

    i had this project as an exam in my informatics class , and it worked and i got straight A. thank you.

  • @alvaronicolasgamarrapena5596
    @alvaronicolasgamarrapena5596 Рік тому +2

    really good video man, code is great and when i tried it worked the first time, keep the great work bro

  • @lecongquyen2189
    @lecongquyen2189 2 роки тому +3

    What a great detailed guideline! I followed step by step and it work. I will use it for my final electrical engineering project. Thanks a lot!

  • @mrbowlingalley
    @mrbowlingalley 5 років тому +6

    3 years later and we are still building this. I set safetyDistance to 25. With only LED and no buzzer. Detects my cat coming in the room. Pretty cool - I guess!

  • @AVolt
    @AVolt 7 років тому +11

    thank you so much it worked with me.
    your fan from middle east
    اخوك من الشرق الاوسط

    • @PachaHooper
      @PachaHooper 4 роки тому

      he man can u send the code if u got it please

    • @y.osa269
      @y.osa269 3 роки тому

      اخوي ممكن الكود ضروري الله يسعدك

    • @Epic_stickman90
      @Epic_stickman90 8 місяців тому

      @@PachaHooper the code is in pinned comment

  • @muhammadfirdauz5272
    @muhammadfirdauz5272 4 роки тому +5

    NICE!!! Saved me a thousand dlrs in school fees

  • @shlb3692
    @shlb3692 Рік тому

    OMG it works
    thank you so much, please keep sharing projects like this.

  • @Ganondalf_the_grey
    @Ganondalf_the_grey 3 роки тому +1

    got the uno and this is a great tutorial. thanks.

  • @theelectromaker6215
    @theelectromaker6215 4 роки тому

    Thank you very much, i saw many vids but any of them din't work but your worked thank you very much.

  • @quentinb9692
    @quentinb9692 5 років тому +2

    It came in a kit, first thing that I acutally got to work with my UNO. Thanks for thie vid.

  • @tomanprasad8859
    @tomanprasad8859 Місяць тому

    Such a beautiful project ❤

  • @marcelnalewajko3537
    @marcelnalewajko3537 4 роки тому +2

    Thank you! This tutorial was very good and helped me a lot

  • @HAYRISHEENVASUDEVANMoe
    @HAYRISHEENVASUDEVANMoe 11 місяців тому

    thank you bro you are king of arduino

  • @AdityaYadav-mk4ye
    @AdityaYadav-mk4ye 6 років тому +1

    Thank you very much i am starting to learn arduino and thanks to you i can learn the hardware and then i will work on software

  • @crinnovator9444
    @crinnovator9444 7 років тому +12

    East or west mert is the best...... Thanks

  • @djeastreofficial
    @djeastreofficial 3 роки тому +1

    Awesome 👌🏻

  • @LhorKhan214
    @LhorKhan214 Рік тому +3

    hi, can you explain where did you get this value 0.034?
    Edited:
    i did a google search, its the speed of sound (343 m / s)

  • @mohdnaqibhaiqal2974
    @mohdnaqibhaiqal2974 Рік тому +1

    I lke the video because is short and easy to understand

  • @purple_clouds3797
    @purple_clouds3797 2 роки тому

    This is just what i needed and it's very simple😆😇😇🤤

  • @thomasalexander1563
    @thomasalexander1563 8 років тому +1

    Nice tutorial,,
    Luckily find it in instructable..
    Thank you..
    Keep it

  • @hkiceman001
    @hkiceman001 7 років тому

    very interesting , I change the LED to a servo motor, it works .... good
    According to your code information , it means can do anything when change the led or buzzer, thank you !

    • @AhmedHassan-qe2hs
      @AhmedHassan-qe2hs 7 років тому

      what is the code if i attach vibrator instead to led ???

    • @srikanthch5858
      @srikanthch5858 7 років тому

      Can u send me the source code

  • @chaturbhujbiyani4633
    @chaturbhujbiyani4633 6 років тому +2

    wow...u did it ....u saved me....i used it in science project...

    • @eoz8985
      @eoz8985 5 років тому

      i also have a science fair can you explain and the coding

  • @MarkSmith-rb5mc
    @MarkSmith-rb5mc 7 років тому +3

    Thanks for a well laid out and easy to understand tutorial. Keep up the good work!

  • @AyushRaj-me8ly
    @AyushRaj-me8ly 4 роки тому

    I like your video, is very useful for our project. Keep making these videos :)

  • @rushabhvaidya7930
    @rushabhvaidya7930 3 роки тому

    Thanks a lot you did it man!!! Thank again

  • @iqratareen-mh4xw
    @iqratareen-mh4xw 7 місяців тому

    Thank u sir ❤❤its working

  • @AR-dy3fu
    @AR-dy3fu 6 років тому +33

    If anyone has any problems to get the code...just copy mine.
    // defines pins numbers const int trigPin = 9; const int echoPin = 10; const int buzzer = 11; const int ledPin = 13; // defines variables long duration; int distance; int safetyDistance; void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input pinMode(buzzer, OUTPUT); pinMode(ledPin, OUTPUT); 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; safetyDistance = distance; if (safetyDistance

  • @Sheik_ULEM
    @Sheik_ULEM 3 роки тому

    Thank you this was very clear and easy to understand

  • @STudyTime4UVikasMishraSir
    @STudyTime4UVikasMishraSir 2 роки тому

    Thank you for your nice and easy video editing
    Surely helpful for beginners

    • @cubebrix5801
      @cubebrix5801 2 роки тому

      hi. can you help me, im only using led and its only blinking

    • @InkByt3
      @InkByt3 6 місяців тому

      @@cubebrix5801 If you're only using the LED that is what it is supposed to do.

  • @williamkakooza4603
    @williamkakooza4603 6 місяців тому

    Well done Professor

  • @melihapa3884
    @melihapa3884 2 роки тому +5

    Hello. There are already a lot of these examples on youtube. In your circuit the lights are either on or off. The sound either squeaks or it doesn't. I wish you had made a circuit where the intensity of sound and light increases as you get closer. :(

    • @ArzenikDev
      @ArzenikDev Рік тому +2

      Bro just recode it to do that it's not that hard

  • @vishnutripathi2885
    @vishnutripathi2885 2 роки тому

    great work....very helpful

  • @jacoblewis8543
    @jacoblewis8543 4 роки тому

    Nice Job
    Ur Great with the tutorial which is very understandable and the code.
    One problem is that when I went to the source code to look it took me to ur website with no code

    • @y.osa269
      @y.osa269 3 роки тому

      Did you get the code? If yes please send it to me

    • @jacoblewis8543
      @jacoblewis8543 3 роки тому

      @@y.osa269 no
      i did not get it

  • @Si-uy8qg
    @Si-uy8qg Рік тому

    Nice video, by the way, i'm John Blas everyone.

  • @emersonrocha1097
    @emersonrocha1097 8 років тому +1

    ola,fiz esse projeto com seu codigo.
    mas ele ficou aprando com led vermelho sem nada na frente,como se houvesse um obstaculo sem ter.

  • @egorkorbasov3422
    @egorkorbasov3422 7 років тому +1

    Hi! I tried to do 2 things together, Like a bell ring (you push the button and hear the buzzer rings) and LDR+3colorLED. But when I press the button when there is no light it rings only when the loop of LED is over. Why is it so?

  • @dhirajmandal715
    @dhirajmandal715 3 роки тому

    thanks it help a lot ❤❤

  • @dylansworld54321
    @dylansworld54321 2 роки тому +1

    Great project! Why is my buzzer clicking instead of buzzing though?

    • @SG-gr3fl
      @SG-gr3fl 2 роки тому

      Did you ever figure it out?

  • @andreisantos5088
    @andreisantos5088 4 роки тому

    i'm brazilian and liked very good so much your video, congratulations!!!

  • @deadchords4919
    @deadchords4919 7 років тому +1

    digital pin 13 has a build in resistor
    so why to put another one?

  • @HotDoggyStand
    @HotDoggyStand 5 років тому

    any reason why mine is reading out distances in the 2ks. I used the code you provided us with.

  • @_Simon
    @_Simon 5 років тому

    do the trig and echo pins need to be on a PWM signal for them to work?
    I am doing a project on the Arduino mega and using 3 of these sensors, but all of the PWM pins are being used on motor drivers. Love your videos. Best Arduino channel. Keep up the good work!

    • @hrithikjain1806
      @hrithikjain1806 5 років тому

      Not really, you can use digital write/read

  • @jamesmay4547
    @jamesmay4547 2 роки тому

    Thank you for the great video and what is the name of the background music

  • @namithss7966
    @namithss7966 5 років тому +1

    thanks this was good work

  • @TusharSharma-is1mi
    @TusharSharma-is1mi 7 років тому

    Great job yaar
    I needed this help and....

  • @pizzulgaming6253
    @pizzulgaming6253 3 роки тому

    Hi .... Can explain to me about this project that use of what system ? Hopefully in full description

  • @giancarlosgza
    @giancarlosgza 7 років тому

    Amazing video!!!!

  • @belaaa522
    @belaaa522 3 місяці тому

    THNKYOUU ITS WORKS

  • @MohamedAzizYazidi
    @MohamedAzizYazidi 4 місяці тому

    why do when i check the monitor to see the distance every time it put the disance then a 0 again and again
    and that makes the buzzer make noise even when the is nothing infront of the sensor

  • @G.V.Ramnivedan
    @G.V.Ramnivedan 7 років тому

    While coding should we connect the arduino board to the bread board please tell me soon

  • @Sore_YT
    @Sore_YT Рік тому +1

    My Circuit Isn't working, can somebody help?

  • @phonepaseuthkhounthachack9459
    @phonepaseuthkhounthachack9459 3 роки тому

    It is work. Thanks bro

  • @williammichael3913
    @williammichael3913 6 років тому +3

    Hey! I love this project tysm. But I was wondering How would I increse/decrese the range so that it will turn buzzer on when someone is more farther away?
    Thanks!

    • @Kirtymonma
      @Kirtymonma 5 років тому

      William Michael did you ever figure out?

    • @alejandroacosta6495
      @alejandroacosta6495 4 роки тому

      Just look the code, he configured the "Safe Distance to 5", if you want to make it in different length just change the safe distance to a greater number

    • @cheshire793
      @cheshire793 Рік тому

      @@alejandroacosta6495yeah, my friend and i are trying that and it's not working. do you have any other suggestions?

  • @3bsily
    @3bsily 6 років тому

    how i can add vibration motor with this project > same a smart blind stick please any one help me to add vibration motor

  • @stemtube8006
    @stemtube8006 7 років тому +1

    My buzzer is sounding like a Geiger counter??? it’s working but not properly, is it the buzzer or count I fix that somehow

    • @Thajoeee
      @Thajoeee Рік тому +1

      to change the sound of the buzzer you need to replace the original piece of code with "if (safetyDistance

  • @chalsu
    @chalsu 2 роки тому

    Hey, can I add an LCD to this project? and How will the code be written when the LCD is added?

  • @emilusfiogbe3450
    @emilusfiogbe3450 6 років тому

    merci beaucoup c'est astronomiquement instructif!!

  • @ahmedomaar
    @ahmedomaar Рік тому

    Thanks for your helping, I make it

  • @ikramnazri6748
    @ikramnazri6748 10 місяців тому

    What type of resistor you use?

  • @sreekarbss5475
    @sreekarbss5475 5 років тому

    Thanks bro it helped in my project

  • @nurinqasrina7826
    @nurinqasrina7826 5 років тому +6

    Why my led keeps on and the sensor is not working 😣

  • @AvighnaDaruka
    @AvighnaDaruka 3 роки тому

    Hi bro, did you use passive or active buzzer?

  • @manufacturingengineering-bp8il
    @manufacturingengineering-bp8il 5 місяців тому

    دروستم کرد💘

  • @katianuriu7506
    @katianuriu7506 11 місяців тому

    What type of buzzer did you use?

  • @prempanchal7721
    @prempanchal7721 3 роки тому

    Hey Bro, I Have 3 Pin Buzzer Sensor GND, I/O, VCC... So which connection should I do...?

  • @charliebell7163
    @charliebell7163 3 роки тому

    How would i make it louder ? and also how would i make it longer range thanks you!!

  • @rafabalderas8948
    @rafabalderas8948 7 років тому

    Can I connect more than 1 LED? If i wish to disconnect the buzzer l, should I delete something in the code??

  • @applefinn3933
    @applefinn3933 5 років тому

    how do you change the distance of when the buzzer starts

  • @harshithraj6055
    @harshithraj6055 2 роки тому

    Only we have to do this code with computer only or we can use cellphone

  • @Dofusvidss
    @Dofusvidss 7 років тому

    Thank yoou very much for your tutorials ! I'm a beginner on arduino, why don't you connect the buzzer (+) on VCC ?

  • @MrBOBALON
    @MrBOBALON 7 років тому

    When I unplug it from my computer, and attempt to use a 9v battery, it doesn't work. I see the little yellow light on the arduino fade away with no buzzing from objects near the sensor. How can I get it to run on just the 9v?

  • @prashantpal8376
    @prashantpal8376 3 роки тому

    Arduino Uno R3 Development Board with USB Cable can we use this

  • @JaydiEntenia
    @JaydiEntenia 9 місяців тому

    yey it worked, but how do i make it so that it'll have longer distance?

  • @jwf677
    @jwf677 4 роки тому +8

    // defines pins numbers
    const int trigPin = 9;
    const int echoPin = 10;
    const int buzzer = 11;
    const int ledPin = 13;
    // defines variables
    long duration;
    int distance;
    int safetyDistance;
    void setup() {
    pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
    pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    pinMode(buzzer, OUTPUT);
    pinMode(ledPin, OUTPUT);
    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;
    safetyDistance = distance;
    if (safetyDistance

    • @hyperandaimbot
      @hyperandaimbot 2 роки тому

      Hi 2nd line from last do we have to write any number after serial.print(distance)

    • @איילהחלק
      @איילהחלק Рік тому

      Is this a code that causes a bulb to light up at a certain distance?

  • @osamazafar7350
    @osamazafar7350 7 років тому

    it worked
    thanks.

  • @ArzenikDev
    @ArzenikDev Рік тому

    I edited your script a bit so it goes beep stop beep stop within a set range thank you for the video

  • @aveekaumsingh5398
    @aveekaumsingh5398 6 років тому

    nice video........i want more ideas

  • @kevinpriadinata1184
    @kevinpriadinata1184 Рік тому

    can u make a vidio how to modify the distance

  • @shrutiverma9077
    @shrutiverma9077 4 роки тому

    Can we directly use the led on pin 13

  • @lacombegaetan
    @lacombegaetan 7 років тому

    Thanks for tis tutorial !
    Is there a way to change buzzer's volume ?

    • @charliebell7163
      @charliebell7163 3 роки тому

      YEAH i rlly need it to be as loud as possible

  • @gunjanchoudhary5310
    @gunjanchoudhary5310 2 роки тому

    Sir Mera coda upload nhi ho rha h uske liye mujhe library download Karna padega but Kon sa library download karu ye nhi samjh me aa rha

  • @emersonnascimento7468
    @emersonnascimento7468 7 років тому

    Por que quando a distância começa a marcar de 3 a 4 cm no monitor serial começa a ficar saltitada pra 3400 e o som tbm fica saltitando ?

  • @ibrahimEditzFootball
    @ibrahimEditzFootball Рік тому

    Can we make it without led

  • @SMARTS-mv4nh
    @SMARTS-mv4nh 7 років тому +7

    what the problem i can't able to run this either the buzzer continuously sounds or sometimes not sounds ,i removed the light section from it

  • @_vishnu2142_
    @_vishnu2142_ 2 роки тому

    Can we do this project without led and resistor ? Please reply sir

  • @rumaishafatima6053
    @rumaishafatima6053 2 роки тому

    Sir, how will it be if you connect this project with GSM modem?

  • @mohammadabas3890
    @mohammadabas3890 2 роки тому

    How can I connect two sensors in series in this case?

  • @afnanrahman6905
    @afnanrahman6905 Рік тому

    it is working only on time if i remove the obstacle then it is still alarming and blinking led

  • @shrimpbean
    @shrimpbean 3 роки тому

    how to display sierial monitor on to oled

  • @cassandraservo
    @cassandraservo 5 років тому +1

    Where do u write the code?

  • @salmanijaz8326
    @salmanijaz8326 4 роки тому

    thanks it works

  • @UmmmIlovemath
    @UmmmIlovemath 3 роки тому

    how to get the app for distance

  • @chandanjha3379
    @chandanjha3379 6 років тому

    Awesome I love it

  • @Umutt1316
    @Umutt1316 4 роки тому

    Teşekkürler işime yaradı ve bir beğeni de benden

  • @alphagamingff2011
    @alphagamingff2011 3 роки тому

    Can ve use another board uno small

  • @dhomepanda22
    @dhomepanda22 4 роки тому

    what type of Resistor

  • @africantech5
    @africantech5 4 роки тому

    Well done sir can you pls Guide me on using pic16f877A for this project

    • @africantech5
      @africantech5 4 роки тому

      I will sincerely be grateful for quick response

  • @nagalaharivavilala4186
    @nagalaharivavilala4186 7 років тому

    what is the software used?? Is it keil or ardunio??

  • @Randomx760
    @Randomx760 5 років тому

    Can iake it with Arduino nano with same code