@Mikolaj Kraszewski You may well have several sensors, you just have the first sensor finished before you start the next sensor maybe there should be a delay between the two sensor code
i m little confused you sent a 10 microseconds long pulse, doesn't matter where it goes it will be 10 sec long and " pulsein" is calculating the time from high(when the pulse enters) to low (when pulse ends) and it is 10 micro seconds. but it is calculating the time from transmitting the pulse to receiving the pulse
The code works, but is not the best to combine with other stuff. It is really advisable to connect the TRIG to pin 3 and let an interrupt do the measuring in the background, so you don't have puseIn halting your code completely while sensing.
Maybe just one thing to add up, the moment you set trig pin to HIGH, echo pin will be switched to HIGH as well, until it detects the back wave. That's why the period of echo pin input on HIGH mode equals to the time ultrasonic wave travels.
The code works fine, however the circuitry you have provided in the video is connected wrong.Other than that thank you for the explanation, greatly appreciated!
Thank you for the video! Worked perfectly from the first time. I've just bought my uno 3 and unpacked it 5 minutes ago and this was firs project i did. Pozdrav iz uk :) Ivan
I came up with this project idea. I was like I finally invent something to be proud of hahah. when I started working on this project, I found out that this project is already done by this gentleman. anyway good job boss
at 4:07, if the bounced sound waves cause the echo pin to go high that means the echo pin will trigger after the sound waves already bounced off the surface.. Don't you need the echo pin start the timing at the same time the trig pin sets off the pulse???????
Hello. I built the regular circuit and it is working great! I tried to watch your LCD tutorial and use the code give, but the LCD is just turning on and not displaying anything. I would really appreciate it if you or someone else could paste a diagram of the circuit used to build the circuit with the LCD display. Thanks alot for the help and the great video!
hello can ultrasonic sensor work two task instances i.e to sense an object and an send information to servo motors to be used to turn when it sense an object
what about angled distances can i mount two of them on my car's rear bumper bellow both tail lights and see the distance of a object lying exactly between the sensors ?
+Dejan Nedelkovski I've been trying to to this for a few days, but I keep getting 0 distance on all codes I've used. I've tried the NewPing library but I can't seem to get it to work. Can you please help me?
just don't connect echo to power, instead connect vcc to power (don't connect vcc to gnd) and connect gnd to gnd on the arduino. echo and trig should be connected to 10 and 9. other than that good video!
I looked up that this version of sensor is vulernable to interference from other ultrsonic sensors, if that is the case could I use this sensor to create a Local positioning system using a tri-lateration? What are your thoughts? Thanks
I like your technique of highlighting code as you step through it. You have a good "classroom" approach; I wish everyone did this; it would allow absorbing info easier on us students. Tkx My problem: I'd like to use the HC-SR04 Ultrasonic sensor to shoot through a 7 cm opening (mason jar) and sense the liquid (alcohol) level in it from 3 cm (top of jar) to 20 cm (bottom of jar). Will the sides of the jar interfere with the sound pulse? Thanks
Thanks for the quick reply - so, if I understand you, the sides of the jar would obscure any reflexion from the liquid; the technology would not work inside a jar. Can you suggest any alternative that does not involve contact with the liquid (phytosanitary) or modification of the liquid container (using plain old mason jar)?
I have something more or less similar to this. It works in terms of reading cms but when the results are really inconsistent for me. If i have an object 20 cm awaay it will sometimes print out 20cm but mostly it will print out 1cm or 2 as if theres something messing with it. What could be the cause? Awesome video thank you
Hi Can you help me please? I want some distance sensor for (20cm) with adjustment option if there is, and with dry contact open/close. so, when it detects Obstacle it will open the dry contact and automatically close it when it will stop detect the Obstacle can you help me to find the item that I need on AliExpress? Thanks Yossi
Is there something like an expansion of this code on the timetravel? duration=pulsIn(echoPin, HIGH); Because i’m planning to use other radio frequency module but still same concept of getting distance as ultrasonic
Hi! Excellent video! How could I run a video on my computer using only the ultrasonic sensor? That when I stand in front of the sensor, a certain video is executed. it's possible? Thank you!
With your idea, I'm trying to make a speed-meter. I'm trying to put it into m/s but I only get rounded numbers for the distance. For the range of the sencor it's not very usefull. Do you know why this happend? (I used the code from your website that connects with the LCD)
hi I wanted to know if we can measure the distance in mms.. eg 3.3 cm or 10.5 cm as everyone on TH-cam is showing only 0 significant digit after decimal I.e. 3 cm or 10 cm... also are there more accurate sensors for measuring distance and displacement. please reply asap.. thank you. D Prakash
Hi Dejan, could you please show us a tutorial how to connect multiple sensors to an UNO, MEGA, or Edison board through Wifi (integrated/ through shield ) or through XBee ZigBee, something like 3 ultrasonic sensors with two infrared sensors and one face tracked camera(All in one) with the LCD display for all the information shown, does this set up need like different switches to make everything work? I am trying to build a Obstacle Avoiding Robot Car and I don't quite get the point how to connect everything which hasn't include the Motor side(4X4 with individual Encoders, I may possibly go for a 6 wheels as well), still trying to figure out the wifi part with an Android phone control through Wifi(so I could switch manual control and autonomous back and forth if I need to) which I also have to consider wifi connection of the Face Cam(WebCam or Pixy CMUcam5). I really enjoy learning your tutorial and it's been very clear and helpful, as a newbie step by step teaching process just make me understand more! Please show us more~
good day man, i have three ultrasonic sensors hc-sr04, i wanna make an evader obstacles with arduino one so i have decided to make a structure and to put the sensors like this: (IOOI-IOOI-IOOI) to get the best coverage, so i wanna make is the following: the sensor of the middle will be emitting and receiver but the other two sensors will be receiver only, i made all ok, the connections, the trigg signal, the echo signal too, the vcc, i know that after trigg, it needs a delay. the middle sensor work exelent but the problem is the other two sensors, what do i must do with the trigg pin of the that two sensors?, already i connected it to gnd and dont work like this.
i m little confused you sent a 10 microseconds long pulse, doesn't matter where it goes it will be 10 sec long and " pulsein" is calculating the time from high(when the pulse enters) to low (when pulse ends) and it is 10 micro seconds. but it is calculating the time from transmitting the pulse to receiving the pulse
Is there a way I can make the sensor produce higher frequency ultrasound ? If not, where can I find a sensor capable of producing around 96 KHz or even 161 KHz ?
i have a question. i tried the ultrasonic buzzer but the distance kept on showing 0 for me... i looked at all my steps and also verified the code and the code works... im not actually sure what i did wrong, but if anyone knows how to help me pls tell me.
Please note, circuit diagram at 0:56 should be: 5v to VCC, GND to GND, D10 to Trig, D9 to Echo.
@Mikolaj Kraszewski You may well have several sensors, you just have the first sensor finished before you start the next sensor maybe there should be a delay between the two sensor code
Could you please send full circuit diagram by connecting with LCD display
i m little confused you sent a 10 microseconds long pulse, doesn't matter where it goes it will be 10 sec long and " pulsein" is calculating the time from high(when the pulse enters) to low (when pulse ends) and it is 10 micro seconds.
but it is calculating the time from transmitting the pulse to receiving the pulse
How To Mechatronics hablas español verdad
my ultrasonic sensor got fried, i think. lol
This video is incredible, code is so much easier to understand with the calculations. What a guy!!
Glad it helped!
No Words for the appreciation dear. Hats Off. Keep making these type of tutorials.
very helpful
thank you my bro
keep it real
love from india and battir
3rasi
Great explanation ❤
Thank you and good luck 🌻🇱🇰😇
You have echo and vcc in series. The red wire should be I the right most pin of your diagram.
Even that is swapped, right? Red is vcc, so leftmost pin, and black is gnd, so the rightmost pin
The code
```
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration*0.034/2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.print("
");
}
```
toi alors toi merci
thank you very mush brother.I struggled with a wrong code for a week.error was I used ' ' instead of " "
The code works, but is not the best to combine with other stuff. It is really advisable to connect the TRIG to pin 3 and let an interrupt do the measuring in the background, so you don't have puseIn halting your code completely while sensing.
Maybe just one thing to add up, the moment you set trig pin to HIGH, echo pin will be switched to HIGH as well, until it detects the back wave. That's why the period of echo pin input on HIGH mode equals to the time ultrasonic wave travels.
Why echo pin switches to high the moment we set trig pin to high?
Wonderful. Thank you so much. Very easy to follow and the maths was explained very simply.
Cool project!. Besides arduino, I have also tried to use 2 esp8266, you can get sensors and displays without cables
Thx dude. I never knew this channel was so helpful. Subbed.
Great job SIR, for those who ask about LCD connection please see the code (2.3.4.5.6.7 on arduino pins = 4.6.11.12.13.14 on LCD) thanks.
The code works fine, however the circuitry you have provided in the video is connected wrong.Other than that thank you for the explanation, greatly appreciated!
Thank you for the video! Worked perfectly from the first time. I've just bought my uno 3 and unpacked it 5 minutes ago and this was firs project i did.
Pozdrav iz uk :)
Ivan
Great tutorial dude!
Good and simple... ! Nice video, keep on man!
Yes follow the instructions on the site, not here. There you can copy and paste the code too.
I came up with this project idea. I was like I finally invent something to be proud of hahah. when I started working on this project, I found out that this project is already done by this gentleman. anyway good job boss
I love the video, much easier to understand than the technical sheet
Мужик, красавчик, мудро поступил и делаешь контент на английском. Респект!
you can fit the sensor on the arduino without a breadboard: just use pin 11 as vcc
Best code ever! Thank you :)
Thanks man 👍
Where's the diagram if u connect a lcd
You save my life thank you🥰
The new library is very helpful
Clear and concise! Thank you!!
This is awesome very detailed explaination
I broke my ultrasonic sensor cause of your diagram 🙃
Nah bro, worked fine for me
Thanks for sharing the code, but I was hopping to learn the physical setup of the US sensor as well
Excellent tutorial! Thank you very much for your explanation!
I am a fan of your channel.please send a video of coding Bluetooth module for joystick module
at 4:07, if the bounced sound waves cause the echo pin to go high that means the echo pin will trigger after the sound waves already bounced off the surface.. Don't you need the echo pin start the timing at the same time the trig pin sets off the pulse???????
Great videos. Subscribed. Keep up!
thanks for video I also bought it and it work I got inspired by you thanks
Nice video !! I liked it, it was usefull.
Btw, where are you from ?
nice tutorial, easy to understand
Thank you! I'll be referencing this in my next video. Please be aware that your fritzing diagram is incorrect.
Hello. I built the regular circuit and it is working great! I tried to watch your LCD tutorial and use the code give, but the LCD is just turning on and not displaying anything. I would really appreciate it if you or someone else could paste a diagram of the circuit used to build the circuit with the LCD display. Thanks alot for the help and the great video!
The problem with the LCD might be the contrast. You need to apply an appropriate voltage to the contrast pin.
Very to the point. Thanks!
So cool! Thanks homeboy !!!!
hello can ultrasonic sensor work two task instances i.e to sense an object and an send information to servo motors to be used to turn when it sense an object
Thank you for frying my sensor.
Thank you soooooo much! This really was useful.
My serial monitor only shows this: 0000000000000000000
How can I fix it or where is my false?
Mine to
Mine to
@@paulrosenzweig1180 hast du es geschafft, weil ich habe das gleiche Problem( did you fix it and when yes how did you do it?)
Lukas Lachmayr no
@@lukaslachmayr7093 der Fehler ist in den ersten zwei Zeilen => trigPin = 10; echoPin = 9
Very cool, thank you for sharing!
which connection pins for LCD with IC2 module for SDA and SCL???? what to connect in arduino?
what about angled distances
can i mount two of them on my car's rear bumper bellow both tail lights and see the distance of a object lying exactly between the sensors ?
+Dejan Nedelkovski I've been trying to to this for a few days, but I keep getting 0 distance on all codes I've used. I've tried the NewPing library but I can't seem to get it to work. Can you please help me?
that happened to me too
Contact me 8530799642
Any solution? It's showing 0 distance :/
Abdullah Al Farabe contact me 9975844642
Put the trig pin on 9 and echo pin on 10 and then try.
This is quite helpful . . thank you
awesome work dude. can you please explain why did you set the trigger pin to LOW initially for 2 microseconds ??
thank you
why you don't tell the connection with LCD pin
yess
@@fikrifathoni_te6574 same
Loads of shite on TH-cam for this!
Fucking search for it u pleb
Scares me that you have 45 likes... hes talking about the Sensor u bellends
@@phillbon3457 bruh he was just asking you prig
i want your kids
please can i ask how did you display the distance on the lcd screen
Hi. The schematic at around 1min appears to be wrong. (Vcc to ground, Ground not connected, power connected to echo)
Where can I get that same LDC display he uses in the video?
Wouldn't the duration be equal to the delay time that you set the trig pin to high?
I thought it was vcc, echo, trigger, gnd. I think your wiring diagram is wrong.
can you provide a link to the correct one?
just don't connect echo to power, instead connect vcc to power (don't connect vcc to gnd) and connect gnd to gnd on the arduino. echo and trig should be connected to 10 and 9. other than that good video!
You're incorrect. It's VCC, Trig, Echo, Gnd.
@@elissitdesign Nah my sensor is VCC, Echo, Trigger, then GND
Perfect as always ty!
Would this work to read the level of water in a tank?
So for 'mm' instead of 'cm' you can just change it to " s = t * 0.34 / 2 " ?
Op-Onion42 That’ll do it
can you also set the distance fixed while the system is doing other things ?
thank you.
I looked up that this version of sensor is vulernable to interference from other ultrsonic sensors, if that is the case could I use this sensor to create a Local positioning system using a tri-lateration? What are your thoughts? Thanks
Excuse me and hello. I tried doing this but found it saying the distance as 0 in all cases
I like your technique of highlighting code as you step through it. You have a good "classroom" approach; I wish everyone did this; it would allow absorbing info easier on us students. Tkx My problem: I'd like to use the HC-SR04 Ultrasonic sensor to shoot through a 7 cm opening (mason jar) and sense the liquid (alcohol) level in it from 3 cm (top of jar) to 20 cm (bottom of jar). Will the sides of the jar interfere with the sound pulse? Thanks
Thanks for the quick reply - so, if I understand you, the sides of the jar would obscure any reflexion from the liquid; the technology would not work inside a jar. Can you suggest any alternative that does not involve contact with the liquid (phytosanitary) or modification of the liquid container (using plain old mason jar)?
Does this work with liquids, like water, for example?
How max distance it will measure can we use in drones to measure height?
Can the trig pins for 2 or more sensors can be in same digital pin?
I have something more or less similar to this. It works in terms of reading cms but when the results are really inconsistent for me. If i have an object 20 cm awaay it will sometimes print out 20cm but mostly it will print out 1cm or 2 as if theres something messing with it. What could be the cause?
Awesome video thank you
i have an arduino nano 33 iot, that works at 3.3V, is there a way to use this sensor with it?
excelente tutorial!
loved it...Thank you sir
Hi
Can you help me please?
I want some distance sensor
for (20cm) with adjustment option if there is, and with dry contact open/close.
so, when it detects Obstacle it will open the
dry contact and automatically close it when it will stop detect the Obstacle
can you help me to find the item that I need
on AliExpress?
Thanks
Yossi
whether the wave exits the trig leg and enters the echo leg
Can I use a temperature module in it to get a highly accurate distance?
Is there something like an expansion of this code on the timetravel?
duration=pulsIn(echoPin, HIGH);
Because i’m planning to use other radio frequency module but still same concept of getting distance as ultrasonic
FANTASTIC! I got it to work. I wish the code was a little more intuitive.
Hotttt
Hi! Excellent video! How could I run a video on my computer using only the ultrasonic sensor? That when I stand in front of the sensor, a certain video is executed. it's possible? Thank you!
You can do it by clicking Ctrl+Shift+M
do you know any sensor for 2d pattern digitizing .
With your idea, I'm trying to make a speed-meter. I'm trying to put it into m/s but I only get rounded numbers for the distance. For the range of the sencor it's not very usefull. Do you know why this happend? (I used the code from your website that connects with the LCD)
+Dejan Nedelkovski Thank you very much!
hi I wanted to know if we can measure the distance in mms.. eg 3.3 cm or 10.5 cm as everyone on TH-cam is showing only 0 significant digit after decimal I.e. 3 cm or 10 cm... also are there more accurate sensors for measuring distance and displacement. please reply asap.. thank you.
D Prakash
Hey, nice tutorial! Do you think this sensor could be used to measure wind speed?
+pezzioliveira6 No, I dont' think so.
very very helpful .... thanks a lot
how do you make the com23 tab tell you what number ou want, i know how to pull it up, but dont know how to use it
Hi Dejan, could you please show us a tutorial how to connect multiple sensors to an UNO, MEGA, or Edison board through Wifi (integrated/ through shield ) or through XBee ZigBee, something like 3 ultrasonic sensors with two infrared sensors and one face tracked camera(All in one) with the LCD display for all the information shown, does this set up need like different switches to make everything work? I am trying to build a Obstacle Avoiding Robot Car and I don't quite get the point how to connect everything which hasn't include the Motor side(4X4 with individual Encoders, I may possibly go for a 6 wheels as well), still trying to figure out the wifi part with an Android phone control through Wifi(so I could switch manual control and autonomous back and forth if I need to) which I also have to consider wifi connection of the Face Cam(WebCam or Pixy CMUcam5). I really enjoy learning your tutorial and it's been very clear and helpful, as a newbie step by step teaching process just make me understand more! Please show us more~
+Dejan Nedelkovski Great to hear from you Dejan, thank you and I will follow up!
good day man, i have three ultrasonic sensors hc-sr04, i wanna make an evader obstacles with arduino one so i have decided to make a structure and to put the sensors like this:
(IOOI-IOOI-IOOI) to get the best coverage, so i wanna make is the following: the sensor of the middle will be emitting and receiver but the other two sensors will be receiver only, i made all ok, the connections, the trigg signal, the echo signal too, the vcc, i know that after trigg, it needs a delay. the middle sensor work exelent but the problem is the other two sensors, what do i must do with the trigg pin of the that two sensors?, already i connected it to gnd and dont work like this.
Does it have to constantly be connected to the computer to get info from the serial monitor?
can you make an utrasonic water tank lavel indicator?
maybe even control a pump with it
Is their an actual practical application for using this or is this more for fun?
have a pseudocode for this project?
i m little confused you sent a 10 microseconds long pulse, doesn't matter where it goes it will be 10 sec long and " pulsein" is calculating the time from high(when the pulse enters) to low (when pulse ends) and it is 10 micro seconds.
but it is calculating the time from transmitting the pulse to receiving the pulse
thanks... very useful
Hi, if I want to use 7 segment display, how I have to make it? Thanks
I wonder if it's possible to use HC-SR04 for "Flow Meters". Would the flow of the water speed up the ultrasound?
V good explanation
how can i code the arduino using one ultrasonic sensor to take two readings that will produce the area.
in arduino uno i m out of pins what to do now ? should i purchase arduino mega?
Is there a way I can make the sensor produce higher frequency ultrasound ?
If not, where can I find a sensor capable of producing around 96 KHz or even 161 KHz ?
Hi, im thinking about build this for my car. do i need more then one sensor for front and back or is the angle of this sensor to small?
why my serial monitor show the wrong value of distance? even I put the barrier in front of the sensor but it shows 120++
i have a question. i tried the ultrasonic buzzer but the distance kept on showing 0 for me... i looked at all my steps and also verified the code and the code works... im not actually sure what i did wrong, but if anyone knows how to help me pls tell me.
I am experiencing this problem too. did u find a solution?